use of org.openqa.selenium.NoAlertPresentException in project selenium_java by sergueik.
the class SuvianTest method test13_3.
@Test(enabled = true)
public void test13_3() {
// Arrange
driver.get("http://suvian.in/selenium/2.3frame.html");
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".container .row .intro-message iframe")));
// Act
WebElement buttonElement = driver.findElement(By.xpath("//button[@onclick = 'myFunction()']"));
assertThat(buttonElement, notNullValue());
// Assert
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 SuvianTest method test19_1.
@Test(enabled = true)
public void test19_1() {
// Arrange
driver.get("http://suvian.in/selenium/2.9greenColorBlock.html");
WebElement greenBoxElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message table div.greenbox"))));
// Act
// Assert
assertThat(greenBoxElement, notNullValue());
// TODO: computed style of that element
actions.moveToElement(greenBoxElement).build().perform();
greenBoxElement.click();
try {
// confirm alert
alert = driver.switchTo().alert();
String alert_text = alert.getText();
assertThat(alert_text, containsString("You clicked on Green"));
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 loginAfterTest.
@Test(priority = 3, enabled = false)
public void loginAfterTest() throws InterruptedException, IOException {
// Click on Sign in Link
System.err.println("Click on Sign in Link");
driver.findElement(signInLink).click();
// Wait for page url to change
System.err.println("Wait for page url to change");
ExpectedCondition<Boolean> urlChange = driver -> driver.getCurrentUrl().matches("^https://accounts.google.com/signin.*");
wait.until(urlChange);
// Enter the email id
System.err.println("Enter the email id");
enterData(identifier, "automationnewuser24@gmail.com");
// Click on next button
System.err.println("Click on next button");
clickNextButton(identifierNextButton);
// Enter the password
System.err.println("Enter the password");
enterData(passwordInput, "automationnewuser2410");
// Click on next button
System.err.println("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);
// Click on profile image
System.err.println("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();
// 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: " + ex.getStackTrace());
} catch (WebDriverException ex) {
System.err.println("Alert was not handled by PhantomJS: " + ex.getStackTrace().toString());
}
// Wait for page url to change
System.err.println("Wait for page url to change");
urlChange = driver -> driver.getCurrentUrl().matches("^https://accounts.google.com/signin.*");
wait.until(urlChange);
// Click on Choose user Link
sleep(100);
/*
List<WebElement> x = driver.findElements(By.cssSelector("svg"));
for (WebElement y : x) {
System.err.println(y.getAttribute("outerHTML"));
}
*/
System.err.println("Click on users list link");
WebElement svgSelector = // svg")).findElement(By.xpath(".."));
driver.findElements(By.cssSelector("div[role='button'] svg[width='24px']")).get(0).findElement(By.xpath(".."));
// System.err.println(svgSelector.findElement(By.xpath("..")).findElement(By.xpath("..")).findElement(By.xpath("..")).findElement(By.xpath("..")).findElement(By.xpath("..")).findElement(By.xpath("..")).getAttribute("outerHTML"));
/*
<?xml version="1.0"?>
<div>
<h1 class="sfYUmb" data-a11y-title-piece="" id="headingText" jsname="z6sL2b">Hi auto</h1>
<div class="FgbZLd r5i3od">
<img jsname="XpilHb" alt="" src="https://lh3.googleusercontent.com/-wFVXorRrucg/AAAAAAAAAAI/AAAAAAAAAAA/AMp5VUqt1um4XARGfeTINdbjBR3yAa_CpQ/mo/photo.jpg?sz=64" class="iarmfc"/>
<div id="profileIdentifier" class="RRP0oc ilEhd" data-a11y-title-piece="">automationnewuser24@gmail.com</div>
<div jscontroller="hgUmTc" jsaction="JIbuQc:BV9TTc(af8ijd)">
<div role="button" class="mUbCce fKz7Od YYBxpf KEavsb" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" jsshadow="" jsname="af8ijd" aria-label="Switch account" aria-disabled="false" tabindex="0">
<div class="VTBa7b MbhUzd" jsname="ksKsZd"/>
<content class="xjKiLb">
<span style="top: -12px">
<span>
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="24px" height="24px" viewBox="0 0 24 24" fill="#000000">
<path d="M7.41 7.84L12 12.42l4.59-4.58L18 9.25l-6 6-6-6z"/>
<path d="M0-.75h24v24H0z" fill="none"/>
</svg>
</span>
</span>
</content>
</div>
</div>
</div>
</div>
*/
highlight(svgSelector, 100);
svgSelector.click();
// Wait for page url to change
System.err.println("Wait for page url to change");
urlChange = driver -> driver.getCurrentUrl().matches("^https://accounts.google.com/ServiceLogin/signinchooser.*");
wait.until(urlChange);
// TODO: examine cookies
sleep(1000);
}
use of org.openqa.selenium.NoAlertPresentException in project devonfw-testing by devonfw.
the class WindowUtils method closeAlertIfPresent.
/**
* Checks if Alert Pop Up was displayed and dismiss it if shown.
*
* @return true if alert was dismissed, false otherwise
* @author
*/
public static boolean closeAlertIfPresent() {
try {
Alert alert = BasePage.getDriver().switchTo().alert();
alert.dismiss();
BFLogger.logDebug("Alert dismissed.");
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
use of org.openqa.selenium.NoAlertPresentException in project teammates by TEAMMATES.
the class AdminActivityLogPageUiTest method testSanitization.
private void testSanitization() {
______TS("safe against injection from admin search page");
AdminSearchPage searchPageForInjection = logPage.navigateTo(createUrl(Const.ActionURIs.ADMIN_SEARCH_PAGE)).changePageType(AdminSearchPage.class);
String injectedScript = "Test Injected Script<script>alert('This is not good.');</script>";
searchPageForInjection.inputSearchContent(injectedScript);
searchPageForInjection.clickSearchButton();
searchPageForInjection.waitForPageToLoad();
logPage.navigateTo(createUrl(Const.ActionURIs.ADMIN_ACTIVITY_LOG_PAGE));
logPage.waitForPageToLoad();
try {
browser.driver.switchTo().alert();
signalFailureToDetectException("Script managed to get injected");
} catch (NoAlertPresentException e) {
// this is what we expect, since we expect the script injection to fail
}
}
Aggregations