本文整理汇总了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;
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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();
}
}
示例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.");
}
示例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;
}
示例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();
}
示例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));
}
示例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;
}
示例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;
}