Timeout error with windowMaximize using Selenium RC - java

I am trying to navigate to a page and maximize and focus the page..My code is as below -.
public class DynamicTableHandling
{
public static void main(String[] args) throws InterruptedException
{
Selenium selenium = new DefaultSelenium("localhost",4444,"*firefox","http://scores.sify.com");
selenium.start();
selenium.open("/match/scorecard/ENG_IND_JUL27_JUL31_2014.shtml");
selenium.waitForPageToLoad("180000");
selenium.windowMaximize();
selenium.windowFocus();
}
}
It opens up the URL but doesn maximize or focus the window. I have been working on gmail and other websites and there both the windowMAximize() and windowFocus were working perfectly. Moreover I am getting error as below:
Exception in thread "main" com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:369)
at DynamicTableHandling.main(DynamicTableHandling.java:13)

Related

I've got a problem with error: org.openqa.selenium.NoSuchWindowException: no such window: window was already closed

When i clicked on loginBtn, then first site is closing and another opening. Then if I try to find something by any selector->org.openqa.selenium.NoSuchWindowException: no such window: window was already closed:/
I've no idea what's going on.I was trying to find iFRame, switch to another window and still getting error.
That's the flow of test:
#Test
public void LogIn() throws AWTException, InterruptedException {
MainPage mainPage= new MainPage();
mainPage.logIn()
.loginToProfile()
.writeNameAndPassword()
.clickLoginBtn()
.clickWizyty();<--here is the problem
}}
this is method which goes to another page:
public OnMySite clickLoginBtn() {
loginBtn.click();
return new OnMySite();
}
and here is the problem, on everything i getting exception
public void clickWizyty() throws InterruptedException {
Thread.sleep(3000);
//WebElement iFrame= DriverManager.getWebDriver().findElement(By.tagName("iframe"));
//DriverManager.getWebDriver().switchTo().frame(iFrame);
String currentTabHandle = DriverManager.getWebDriver().**getWindowHandle()**;
String newTabHandle = DriverManager.getWebDriver().getWindowHandles()
.stream()
.filter(handle -> !handle.equals(currentTabHandle))
.findFirst()
.get();
WaitForElement.waitUntilElemembtIsVisible(wizyty);
wizyty.click();
}}'''
even here: getWindowHandle(); its showing "no such window... "

How Appium Page factory will pick correct xpath when both Android & IOS Xpaths are defined

I am new to Appium and planned to use Appium page factory to execute my test with same script in both android and IOS, Currently i am working on Android device so i am keeping IOS xpath as null, When i execute my script its throwing the error "userNameTextBox=null" . I have two questions here
1. Based on what criteria Appium page factory will know which xpath to select android or IOS
2. Why in my code its throwing "userNameTextBox as Null" although i am using Android driver.
private AndroidDriver<AndroidElement> driver;
#AndroidFindBy(className = "android.widget.EditText")
#iOSBy(className = "")
private AndroidElement userNameTextBox;
public void login(String userName, String password) throws InterruptedException {
userNameTextBox.sendKeys(userName);
}
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException {
LaunchApplication.launchApp("samsungtablet");--This code will launch the app based on device passed
LoginPage lp= new LoginPage();
lp.login("test", "test");---Failing here
}
Previously the application was not setting the driver instance correctly as a result i was getting xpath value as null, I added below function to call driver from the launchapplication class and it worked with that.
public void login(String userName, String password) throws InterruptedException {
this.driver = LaunchApplication.driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
userNameTextBox.sendKeys(userName);
}

How to launch both native app and chrome browser on android to switch between them

I am facing a problem, I want to test Browser links on a native app, when I clicked on links from the native app then the browser is opened but from the browser, I want to check whether this link is matched with my expected result below is my code can anyone to figure out the problem
1) this is my case in this test case I have opened the desired screen and click on the facebook link when I clicked on facebook link facebook is opened in the browser, from the browser I want to get the actual URL
Below is my code
#Test(priority = 10)//Validate that FaceBook Link is working Fine
public void ValidateFacebookLink() throws MalformedURLException, InterruptedException {
WebElement FaceBookLinkID = driver
.findElement(By.id("com.fittingnzidd.cherripik.development:id/tv_share_biz_fb"));
FaceBookLinkID.click();
// CherryPikLaunchInBrowser();
chromeBrowser();
}
public void chromeBrowser() throws InterruptedException {
Thread.sleep(5000);
Set <String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println("WebView:"+contextName);
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
System.out.println("WebView:"+contextName);
String ActualURL=driver.getCurrentUrl();
}
//driver.context("NATIVE");
}
}

Able to locate frame with selenium, but doesn't work with Junit Cucumber

I am able to locate a frame using a selenium java program. The following code runs successfully:
public static void TestCase() throws IOException, InterruptedException{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("website");
driver.findElement(By.xpath("//*[#id='username']")).sendKeys(userName);
driver.findElement(By.xpath("//*[#id='password']")).sendKeys("password");
driver.findElement(By.xpath("//*[#id='session_link']")).click();
driver.findElement(By.xpath("//*[#id='app_236']/a")).click(); //Click a link on the page
driver.switchTo().frame("iframe100-100"); //Switch to a frame within the new page
driver.findElement(By.xpath("//*[#id='yui-gen0']/li[2]/div")).click(); //Click element within the frame
}
But if I run the same code using a Cucumber Junit maven project, the program is not able to locate the frame.
#Given("^I log into website$")
public void log_in()
{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("website");
driver.findElement(By.xpath("//*[#id='username']")).sendKeys(userName);
driver.findElement(By.xpath("//*[#id='password']")).sendKeys("password");
driver.findElement(By.xpath("//*[#id='session_link']")).click();
}
#When("^I select the link from homepage$")
public void select_link() throws InterruptedException
{
driver.findElement(By.xpath("//*[#id='app_236']/a")).click();
}
#Then("^I should see something$")
public void click_element_within_frame()
{
driver.switchTo().frame("iframe100-100"); //Switch to a frame within the new page
driver.findElement(By.xpath("//*[#id='yui-gen0']/li[2]/div")).click(); //Click element within the frame
}
Error message :
31morg.openqa.selenium.NoSuchFrameException: Unable to locate frame: iframe100-100
Any suggestions ?

Test Upload File In Selenium

Currently i wish to run selenium for test excel upload. And my coding didn't working as expected. Just wondering how to resolve it. Every time i run the automated testing my code will be stop at this step:sendKeys("C:\Users\user\Desktop\JSPL Style Excel Upload.csv") without any error message show. Any suggestion?
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:7101/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public void testJava() throws Exception {
driver.get(baseUrl + "SCM_Telephone_Accounting_2-ViewController-context-root/faces/Main_Menu");
driver.findElement(By.id("np2:cni10")).click();
driver.findElement(By.id("r1:1:if1::content")).click();
driver.findElement(By.id("r1:1:if1::content")).clear();
driver.findElement(By.id("r1:1:if1::content")).sendKeys("C:\\Users\\user\\Desktop\\JSPL Style Excel Upload.csv");
driver.findElement(By.id("r1:1:cb1")).click();
}

Categories