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


Java Alert类代码示例

本文整理汇总了Java中org.openqa.selenium.Alert的典型用法代码示例。如果您正苦于以下问题:Java Alert类的具体用法?Java Alert怎么用?Java Alert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Alert类属于org.openqa.selenium包,在下文中一共展示了Alert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAlertText

import org.openqa.selenium.Alert; //导入依赖的package包/类
/**
 * 获取对话框文本
 * @return 返回String
 */
public String getAlertText()
{
	Alert alert=driver.switchTo().alert();
	try {
		String text=alert.getText().toString();
		log.info("获取对话框文本:"+text);
		return text;
	} catch (NoAlertPresentException notFindAlert) {
		// TODO: handle exception
		log.error("找不到对话框");
		//return "找不到对话框";
		throw notFindAlert;

	}
}
 
开发者ID:zhengshuheng,项目名称:PatatiumWebUi,代码行数:20,代码来源:ElementAction.java

示例2: 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

示例3: execute

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Override
public ExecuteResult execute(final ConnectorManager connector) {
    final VariableStoreConnector variableStore = connector.getConnector(VariableStoreConnector.class);
    final WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class);

    try {
        final Alert alert = webSiteConnector.getDriver().switchTo().alert();
        final String text = alert.getText();
        variableStore.set(variableName, text);

        LOGGER.info(LEARNER_MARKER, "Save text '{}' from alert to variable '{}' (ignoreFailure: {}, negated: {}).",
                    text, variableName, ignoreFailure, negated);

        return getSuccessOutput();
    } catch (NoAlertPresentException e) {
        LOGGER.info(LEARNER_MARKER, "Failed to get text from alert (ignoreFailure: {}, negated: {}).",
                    ignoreFailure, negated);

        return getFailedOutput();
    }
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:22,代码来源:AlertGetTextAction.java

示例4: 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

示例5: clickAlert

import org.openqa.selenium.Alert; //导入依赖的package包/类
/**
 * 切换到alter,并点击确认框
 */
public void clickAlert(String msg) {
	WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
	Alert alert;
	baseOpt.wait(20);
	// Alert alert = driver.switchTo().alert();

	try { // 不稳定,原因待查。还是用上面的吧
	// wait and switchTo, Otherwise, throws a TimeoutException
		alert = webDriverWait.until(ExpectedConditions.alertIsPresent());
	} catch (Exception e) {
		this.screenShot();
		LogUtil.info(driver.manage().logs() + "==>alert等待超时!");
		alert = driver.switchTo().alert(); // 与waituntil功能重复,但until经常失败,为了增强健壮性才如此写
	}

	if (msg != null) {
		AssertUtil.assertEquals(alert.getText(), msg, "提示语错误");
	}

	alert.accept();
	baseOpt.wait(30);
}
 
开发者ID:quanqinle,项目名称:WebAndAppUITesting,代码行数:26,代码来源:WebBaseOpt.java

示例6: isElementPresent

import org.openqa.selenium.Alert; //导入依赖的package包/类
@PublicAtsApi
public boolean isElementPresent() {

    // with the current Selenium implementation we do not know whether the opened modal dialog
    // is alert, prompt or confirmation
    if (element instanceof UiAlert) {

        return getAlert() != null;
    } else if (element instanceof UiPrompt) {

        Alert prompt = getAlert();
        return prompt != null && prompt.getText() != null;
    } else if (element instanceof UiConfirm) {

        Alert confirm = getAlert();
        return confirm != null && confirm.getText() != null;
    }

    HtmlNavigator.getInstance().navigateToFrame(webDriver, element);

    return RealHtmlElementLocator.findElements(element).size() > 0;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:23,代码来源:RealHtmlElementState.java

示例7: VerityAlertText

import org.openqa.selenium.Alert; //导入依赖的package包/类
/**
 * 验证alert对话框提示信息是否与预期值一致
 * @param expectAlertText alert 提示框预期信息
 * @author Administrator 郑树恒
 */
public static void VerityAlertText(String expectAlertText)
{
	Alert alert=driver.switchTo().alert();
	String  alertText=alert.getText();
	String verityStr="【Assert验证】:弹出的对话框的文本内容是否一致{"+alertText+","+expectAlertText+"}";
	log.info("【Assert验证】:弹出的对话框的文本内容是否一致{"+"实际值:"+alertText+","+"预期值"+expectAlertText+"}");
	try {
		Assert.assertEquals(alertText, expectAlertText);
		AssertPassLog();
		assertInfolList.add(verityStr+":pass");
	} catch (Error e) {
		// TODO: handle exception
		AssertFailedLog();
		errors.add(e);
		errorIndex++;
		assertInfolList.add(verityStr+":failed");
		Assertion.snapshotInfo();
		//throw e;
	}

}
 
开发者ID:zhengshuheng,项目名称:PatatiumWebUi,代码行数:27,代码来源:Assertion.java

示例8: 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

示例9: execute

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Override
protected ExecuteResult execute(final WebSiteConnector connector) {
    try {
        final Alert alert = connector.getDriver().switchTo().alert();
        alert.sendKeys(insertVariableValues(text));

        LOGGER.info(LEARNER_MARKER, "Send text '{}' to prompt window (ignoreFailure: {}, negated: {}).",
                    text, ignoreFailure, negated);

        return getSuccessOutput();
    } catch (NoAlertPresentException | ElementNotSelectableException e) {
        LOGGER.info(LEARNER_MARKER, "Failed to send text '{}' to prompt window (ignoreFailure: {}, negated: {}).",
                    text, ignoreFailure, negated);

        return getFailedOutput();
    }
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:18,代码来源:AlertSendKeysAction.java

示例10: testAlertOnDuplicationOfModelName

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Test(description = "Test to validate the duplication of model name is not allowed on model config page.")
public void testAlertOnDuplicationOfModelName() {
    modelPage.get();

    String familyName = Family.NEW_TEST_FAMILY2.name();
    String capabilityName = Capability.NEW_TEST_CAP2.name();

    // Trying to add a duplicate model.
    modelPage.addModel(existingModelName, familyName,
            capabilityName);

    // Fail the test if no alert message displayed on attempt of duplication of model name.
    Assert.assertTrue(isAlertPresent(),
            "No alert message displayed on attempting to duplicate the model name : " +
            existingModelName);

    Alert alert = driver.switchTo().alert();

    // Validates the alert message.
    Assert.assertEquals(alert.getText(),
            existingModelName + TestConstants.MODEL_EXIST_ALERT_MSG_SUFFIX,
            "The alert message on attempting duplication of model is different from what expected.");
}
 
开发者ID:Comcast,项目名称:dawg,代码行数:24,代码来源:StbModelUIIT.java

示例11: isAlertPresent

import org.openqa.selenium.Alert; //导入依赖的package包/类
/** Checks if an Alert is Present returns Boolean Value  **/
public static Boolean isAlertPresent(String controlType)
{
	try {			
		if (!controlType.equalsIgnoreCase("Alert"))
		{
			Alert alert = Automation.driver.switchTo().alert();	
			if(alert != null)
			{	
				TransactionMapping.report.strMessage=alert.getText();					
				alert.accept();							
				TransactionMapping.report.strStatus = "FAIL";
				TransactionMapping.pauseFun(TransactionMapping.report.strMessage);
				return true;
			}
		}
	} catch (Exception e) {				
		return false;
	}
	return false;		
}
 
开发者ID:MastekLtd,项目名称:SwiftLite,代码行数:22,代码来源:WebHelper.java

示例12: handlingSimpleAlertTest

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Test
public void handlingSimpleAlertTest() {
    final String expected_alert_text = "A Short Title Is Best A message should be a short, complete sentence.";

    driver.findElement(MobileBy.AccessibilityId("alert_views_button"))
            .click();
    //wait for alert view to load by waiting for "simple" alert button
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(MobileBy.AccessibilityId("simple_alert_button"))))
            //and click on it
            .click();
    wait.until(ExpectedConditions.alertIsPresent());

    Alert alert = driver.switchTo().alert();
    String titleAndMessage = alert.getText();

    assertThat(titleAndMessage, is(expected_alert_text));
    alert.accept();
}
 
开发者ID:Simon-Kaz,项目名称:AppiumSauce,代码行数:19,代码来源:ParallelNativeIOSTest.java

示例13: textInputAlertTest

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Test
public void textInputAlertTest() {
    driver.findElement(MobileBy.AccessibilityId("alert_views_button"))
            .click();
    driver.findElement(MobileBy.AccessibilityId("text_entry_alert_button"))
            .click();
    wait.until(ExpectedConditions.alertIsPresent());

    Alert alert = driver.switchTo().alert();
    String titleAndMessage = alert.getText();
    assertThat(titleAndMessage, is("A Short Title Is Best A message should be a short, complete sentence."));

    //input text
    String text_alert_message = "testing alert text input field";

    alert.sendKeys(text_alert_message);
    String alertTextInputField_value = driver.findElement(MobileBy.xpath("//UIAAlert//UIATextField")).getText();
    assertThat(alertTextInputField_value, is(text_alert_message));
}
 
开发者ID:Simon-Kaz,项目名称:AppiumSauce,代码行数:20,代码来源:ParallelNativeIOSTest.java

示例14: acceptAlertIfVisible

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Override
public WebDriverBrowser acceptAlertIfVisible() {
    executeAction(new BrowserCallback() {

        @Override
        public void execute(Browser browser) {
            if (isAlertVisible()) {
                Alert alert = getWebDriver().switchTo().alert();
                String text = alert.getText();
                alert.accept();
                fireEvent(new AcceptedAlertEvent(browser, text));
            }
        }

    });
    return this;
}
 
开发者ID:testIT-WebTester,项目名称:webtester-core,代码行数:18,代码来源:WebDriverBrowser.java

示例15: declineAlertIfVisible

import org.openqa.selenium.Alert; //导入依赖的package包/类
@Override
public WebDriverBrowser declineAlertIfVisible() {
    executeAction(new BrowserCallback() {

        @Override
        public void execute(Browser browser) {
            if (isAlertVisible()) {
                Alert alert = getWebDriver().switchTo().alert();
                String text = alert.getText();
                alert.dismiss();
                fireEvent(new DeclinedAlertEvent(browser, text));
            }
        }

    });
    return this;
}
 
开发者ID:testIT-WebTester,项目名称:webtester-core,代码行数:18,代码来源:WebDriverBrowser.java


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