use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class SuvianTest method test13_1.
// This test appears to find the button even though it is inside iframe
// without frame switch
@Test(enabled = true)
public void test13_1() {
// Arrange
driver.get("http://suvian.in/selenium/2.3frame.html");
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".container .row .intro-message iframe")));
// Act
WebElement buttonElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("h3 button"))));
assertThat(buttonElement, notNullValue());
// Assert
WebElement currentElement = buttonElement;
for (int cnt = 0; cnt != 4; cnt++) {
try {
WebElement containerElement = currentElement.findElement(By.xpath(".."));
String elementHTML = containerElement.getAttribute("outerHTML");
System.err.println("Parent element: " + (elementHTML.length() > 120 ? elementHTML.substring(0, 120) + "..." : elementHTML));
currentElement = containerElement;
} catch (InvalidSelectorException e) {
// ignore - reached top level
break;
}
}
buttonElement.click();
// Assert
try {
alert = driver.switchTo().alert();
String alertText = alert.getText();
assertTrue(alertText.contains("You clicked a button within a frame"));
// confirm alert
alert.accept();
} catch (NoAlertPresentException e) {
// Alert not present - ignore
} catch (WebDriverException e) {
System.err.println("Alert was not handled : " + e.getStackTrace().toString());
return;
}
}
use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class GmailTest method loginTest.
// the gmail of showing the identity confirmation page the test is not ready to handle
@Test(priority = 4, enabled = false)
public void loginTest() throws InterruptedException, IOException {
// Click on Sign in Link
driver.findElement(signInLink).click();
// origin:
// https://github.com/TsvetomirSlavov/JavaScriptForSeleniumMyCollection
// Wait for page url to change
ExpectedCondition<Boolean> urlChange = driver -> driver.getCurrentUrl().matches("^https://accounts.google.com/signin.*");
wait.until(urlChange);
// TODO: examine it landed on https://accounts.google.com/AccountChooser
// Enter the email id
enterData(identifier, "automationnewuser24@gmail.com");
/*
File screenshotFile = screenshot.getScreenshotAs(OutputType.FILE);
// Move image file to new destination
FileUtils.copyFile(screenshotFile, new File("c:\\temp\\UserID.jpg"));
*/
// Click on next button
clickNextButton(identifierNextButton);
// Enter the password
enterData(passwordInput, "automationnewuser2410");
// Click on next button
clickNextButton(passwordNextButton);
// Wait for page url to change
/*
urlChange = driver -> {
String url = driver.getCurrentUrl();
System.err.println("The url is: " + url);
return (Boolean) url.matches("^https://mail.google.com/mail.*");
};
wait.until(urlChange);
*/
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
System.out.println("Checking if mail page is loaded...");
// https://github.com/pawnu/SeleniumQA/blob/master/EcommerceProject/RunTest.java
return checkPage();
}
});
// Wait until form is redndered, old semantics
wait.until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
System.err.println("Wait for form to finish rendering");
JavascriptExecutor js = ((JavascriptExecutor) driver);
Boolean active = (Boolean) js.executeScript("return document.readyState == 'complete'");
if (active) {
System.err.println("Done");
}
return active;
}
});
System.err.println("Click on profile image");
// Click on profile image
wait.until((WebDriver driver) -> {
WebElement element = null;
try {
element = driver.findElement(profileImage);
} catch (Exception e) {
return null;
}
return (element.isDisplayed()) ? element : null;
}).click();
// Wait until form is redndered, lambda semantics
wait.until((WebDriver driver) -> {
System.err.println("Wait for form to finish rendering");
JavascriptExecutor js = ((JavascriptExecutor) driver);
Boolean active = (Boolean) js.executeScript("return document.readyState == 'complete'");
if (active) {
System.err.println("Done");
}
return active;
});
// Sign out
System.err.println("Sign out");
highlight(driver.findElement(signOutButton), 100);
driver.findElement(signOutButton).click();
try {
alert = driver.switchTo().alert();
alert.accept();
} catch (NoAlertPresentException ex) {
// Alert not present
System.err.println("NoAlertPresentException (ignored): " + ex.getStackTrace());
return;
} catch (WebDriverException ex) {
System.err.println("Alert was not handled by PhantomJS: " + ex.getStackTrace().toString());
return;
}
}
use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class AppTest method test13_1.
// NOTE: this test is hanging the jbrowserdriver
// after the test is run orphaned java processess require a taskkill
@Ignore
@Test
public void test13_1() {
// Arrange
driver.get("http://suvian.in/selenium/2.3frame.html");
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".container .row .intro-message iframe")));
// Act
WebElement buttonElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("h3 button"))));
assertThat(buttonElement, notNullValue());
buttonElement.click();
// Assert
try {
// confirm alert
Alert alert = driver.switchTo().alert();
String alert_text = alert.getText();
assertThat(alert_text, containsString("You clicked on Green"));
} catch (NoAlertPresentException e) {
// Alert not present - ignore
} catch (WebDriverException e) {
System.err.println("Alert was not handled : " + e.getStackTrace().toString());
return;
}
}
Aggregations