本文整理汇总了Java中org.openqa.selenium.Alert.dismiss方法的典型用法代码示例。如果您正苦于以下问题:Java Alert.dismiss方法的具体用法?Java Alert.dismiss怎么用?Java Alert.dismiss使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.Alert
的用法示例。
在下文中一共展示了Alert.dismiss方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
protected ExecuteResult execute(final WebSiteConnector connector) {
try {
final Alert alert = connector.getDriver().switchTo().alert();
if (this.action == Action.ACCEPT) {
alert.accept();
LOGGER.info(LEARNER_MARKER, "Accept alert window (ignoreFailure: {}, negated: {}).",
ignoreFailure, negated);
} else {
alert.dismiss();
LOGGER.info(LEARNER_MARKER, "Dismiss alert window (ignoreFailure: {}, negated: {}).",
ignoreFailure, negated);
}
return getSuccessOutput();
} catch (NoAlertPresentException e) {
LOGGER.info(LEARNER_MARKER, "Failed accept or dismiss alert window (ignoreFailure: {}, negated: {}).",
ignoreFailure, negated);
return getFailedOutput();
}
}
示例2: open
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
public void open()
{
String paramUrl = paramTranslate(getUrl());
engine.openUrl(paramUrl);
try
{
engine.computeToolbarHeight();
}
catch(UnhandledAlertException e)
{
Alert alert = engine.getDriver().switchTo().alert();
if(alert != null)
{
alert.dismiss();
engine.computeToolbarHeight();
}
}
}
示例3: onCommand
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Object onCommand(Context context) {
Alert alert = getSession().switchTo().alert();
String text = alert.getText();
Object value = getValue();
if (value != null) {
alert.sendKeys(value.toString());
}
if ("ok".equalsIgnoreCase(click)) {
alert.accept();
} else if ("close".equalsIgnoreCase(click)) {
alert.dismiss();
}
return text;
}
示例4: closeAlertAndGetItsText
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
private String closeAlertAndGetItsText()
{
try
{
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert)
{
alert.accept();
}
else
{
alert.dismiss();
}
return alertText;
}
finally
{
acceptNextAlert = true;
}
}
示例5: confirmAction
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@RobotKeyword("Dismisses currently shown confirmation dialog and returns its message.\r\n" +
"\r\n" +
"By default, this keyword chooses 'OK' option from the dialog. If 'Cancel' needs to be chosen, keyword `Choose Cancel On Next Confirmation` must be called before the action that causes the confirmation dialog to be shown.\r\n" +
"\r\n" +
"Example:\r\n" +
" | Click Button | Send | | # Shows a confirmation dialog | \r\n" +
" | ${message}= | Confirm Action | | # Chooses Ok | \r\n" +
" | Should Be Equal | ${message} | Are your sure? | # Check dialog message | \r\n" +
" | Choose Cancel On Next Confirmation | | | # Choose cancel on next Confirm Action | \r\n" +
" | Click Button | Send | | # Shows a confirmation dialog | \r\n" +
" | Confirm Action | | | # Chooses Cancel |")
public String confirmAction() {
try {
Alert alert = browserManagement.getCurrentWebDriver().switchTo().alert();
String text = alert.getText().replace("\n", "");
if (acceptOnNextConfirmation) {
alert.accept();
} else {
alert.dismiss();
}
acceptOnNextConfirmation = acceptOnNextConfirmationDefault;
return text;
} catch (WebDriverException wde) {
throw new SeleniumLibraryNonFatalException("There were no alerts");
}
}
示例6: takeScreenshot
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
public synchronized void takeScreenshot(final String errorMessage, final String testName) {
try {
//This probably could be used someday (do not delete)
// int jsErrorNumber = JavaScriptError.readErrors(getWebDriver()).size();
// printStrings(image, removeNL(testName, errorMessage, "The following number of JS errors appeared during the test: " + jsErrorNumber));
BufferedImage image = new OurScreenshot().fullPage().getImage();
printStrings(image, removeNL(testName, errorMessage));
final String pathName = getFilenameFor(testName);
final File screenShotWithProjectPath = new File(pathName);
ImageIO.write(image, "png", screenShotWithProjectPath);
addScreenShotPathForTest(getOriginalTestName(testName), screenShotWithProjectPath.getPath(), errorMessage);
attachScreenShotToAllure(errorMessage, testName, screenShotWithProjectPath);
//VE path below works for TestNG (do not delete)
// String pathToImage = "../../ws/test-reports/test-classes/" + screenShotWithProjectPath.getName();
//VE path below works for ReportNG
String pathToImage = "../../test-reports/test-classes/" + screenShotWithProjectPath.getName();
Reporter.log("<br/><a href='" + pathToImage + "' target='_blank'> <img src='" + pathToImage + "' height='100' width='100'/> </a><br/>");
} catch (IOException e) {
LOGGER.error("IOException occurs", e);
} catch (UnhandledAlertException alertException) {
Alert alert = getWebDriver().switchTo().alert();
String alertText = alert.getText();
LOGGER.error("*****ERROR***** Unexpected Alert appeared. Alert text " + alertText);
alert.dismiss();
takeScreenshot(errorMessage, testName);
}
}
示例7: closeAlertAndGetItsText
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
String closeAlertAndGetItsText() {
try {
Alert alert = getDriver().switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
示例8: dismissAlert
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
public static final void dismissAlert(){
SeleniumWaitUtils.waitForAlert();
Alert alert = Config.driver().switchTo().alert();
log.info("Alert: " + alert.getText());
alert.dismiss();
log.info("Dismiss Alter");
}
示例9: handleAlert
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
/**
* This method handles alert windows
**/
public static void handleAlert(String status, WebDriver driver) {
Alert alert = driver.switchTo().alert();
if (status.equalsIgnoreCase("Y")) {
alert.accept();
} else if (status.equalsIgnoreCase("N")) {
alert.dismiss();
}
}
示例10: alertDismiss
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
/**
* 点击取消按钮
*/
public void alertDismiss()
{
Alert alert= driver.switchTo().alert();
try {
alert.dismiss();
log.info("点击取消按钮");
} catch (NoAlertPresentException notFindAlert) {
// TODO: handle exception
//throw notFindAlert;
log.error("找不到取消按钮");
throw notFindAlert;
}
}
示例11: perform
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
public void perform(final AlertAction action, final ScenarioExecutionContext context) {
WebDriver driver = context.getDriver();
// Wait for the alert
WebDriverWait wait = new WebDriverWait(driver, getActionTimeout(action, context));
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
// Validate text
String expectedAlertText = action.getText();
String alertText = alert.getText();
if (expectedAlertText != null && !expectedAlertText.equals(alertText)) {
throw new AlertTextMismatchException(action.getClass(), expectedAlertText, alertText);
}
// Enter text (in the prompt)
String promptInput = action.getInput();
if (promptInput != null ) {
alert.sendKeys(promptInput);
}
String confirmValue = action.getConfirm();
try {
if (BooleanMapper.isTrue(confirmValue)) {
alert.accept();
} else {
alert.dismiss();
}
} catch (BooleanExpectedException e) {
throw new BooleanExpectedException(action.getClass(), confirmValue);
}
}
示例12: testDocSearchToAnotherViewBookmark
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Test
/**
* test that after doc search, navigating to people flow maintenance view does not cause Javascript errors
* and therefore interfere with JS functionality like validation
*/
public void testDocSearchToAnotherViewBookmark() throws Exception {
waitAndClick("img[alt=\"doc search\"]");
waitForPageToLoad();
selectFrame("iframeportlet");
waitAndClick("td.infoline > input[name=\"methodToCall.search\"]");
// selectFrame("relative=top");
driver.switchTo().defaultContent();
waitAndClickByLinkText("Main Menu");
waitAndClickByLinkText("People Flow");
waitForPageToLoad();
selectFrame("iframeportlet");
waitAndClickByLinkText("Create New");
waitForPageToLoad();
fireEvent("document.documentHeader.documentDescription", "focus");
waitAndTypeByName("document.documentHeader.documentDescription", "sample description");
fireEvent("document.documentHeader.explanation", "focus");
waitAndTypeByName("document.documentHeader.explanation", "sample explanation");
// ((JavascriptExecutor)driver).executeScript("document.getElementById(\"uif-cancel\").focus();");
jGrowl("Click Cancel");
waitAndClickByXpath("//div[@class='uif-footer clearfix']/button[contains(text(), 'Cancel')]");
Thread.sleep(5000);
final String text = "Form has unsaved data. Do you want to leave anyway?";
Alert a=driver.switchTo().alert();
assertTrue(a.getText().equals(text));
a.dismiss();
passed();
}
示例13: dismissAlert
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
/**
* Dismiss the javascript alert (clicking Cancel)
*
*/
protected void dismissAlert()
{
Alert alert = driver.switchTo().alert();
//update is executed
alert.dismiss();
}
示例14: handleAlert
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
public boolean handleAlert(Alert alert) {
System.out.println("Handling alert with text " + alert.getText());
if(alert.getText().toLowerCase().contains("hello"))
{
System.out.println("Trying to accept the alert");
alert.accept();
System.out.println("Accepted the aert successfully");
}
else if(alert.getText().toLowerCase().contains("toolsqa"))
{
System.out.println("Trying to type something and accept the alert");
alert.sendKeys("Sample Yes");
alert.dismiss();
System.out.println("Alert dismissed successfully");
}
else if(alert.getText().toLowerCase().contains("pop up"))
{
System.out.println("Trying to dismiss this alert");
alert.dismiss();
System.out.println("Alert dismissed successfully");
}
else if(alert.getText().toLowerCase().contains("simple"))
{
System.out.println("This seems to be a same alert scenario, accepting the alert");
alert.accept();
System.out.println("Accepted the alert successfully");
}
System.out.println("Handled alert by accepting the alert");
return true;
}
示例15: dismissAlert
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
public void dismissAlert(String... waitFor) {
driver.switchTo().defaultContent();
Alert alert = driver.switchTo().alert();
alert.dismiss();
if (waitFor != null && waitFor.length > 0) {
setDriverWait(waitFor[0]);
}
}