当前位置: 首页>>代码示例>>Java>>正文


Java Alert.dismiss方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:26,代码来源:AlertAcceptDismissAction.java

示例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();
		}
	}
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:23,代码来源:WebPage.java

示例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;
}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:22,代码来源:AlertTag.java

示例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;
    }
}
 
开发者ID:hiroshitoda,项目名称:Selenium-sample-with-Jenkins,代码行数:22,代码来源:SimpleTest.java

示例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");
	}
}
 
开发者ID:Hi-Fi,项目名称:robotframework-seleniumlibrary-java,代码行数:27,代码来源:JavaScript.java

示例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);
        }
    }
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:33,代码来源:Screenshoter.java

示例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;
	}
}
 
开发者ID:chr-krenn,项目名称:chr-krenn-fhj-ws2017-sd17-pse,代码行数:15,代码来源:PageObject.java

示例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");	
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:8,代码来源:SeleniumUtils.java

示例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();
	}
}
 
开发者ID:AnujDasari,项目名称:Actitime-Framework,代码行数:12,代码来源:HelperManager.java

示例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;
	}
}
 
开发者ID:zhengshuheng,项目名称:PatatiumWebUi,代码行数:17,代码来源:ElementAction.java

示例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);
    }
}
 
开发者ID:automate-website,项目名称:jwebrobot,代码行数:34,代码来源:AlertActionExecutor.java

示例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();
	}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:33,代码来源:DocSearchToAnotherViewAft.java

示例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();
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:11,代码来源:WebDriverITBase.java

示例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;
	}
 
开发者ID:toolsqa,项目名称:OptimusPrime,代码行数:35,代码来源:HtmlAlertHandlers.java

示例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]);
	}
}
 
开发者ID:gautamsabba,项目名称:UIFramework,代码行数:9,代码来源:PopupHandler.java


注:本文中的org.openqa.selenium.Alert.dismiss方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。