本文整理汇总了Java中org.openqa.selenium.Alert.getText方法的典型用法代码示例。如果您正苦于以下问题:Java Alert.getText方法的具体用法?Java Alert.getText怎么用?Java Alert.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.Alert
的用法示例。
在下文中一共展示了Alert.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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;
}
}
示例4: 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;
}
示例5: 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;
}
示例6: 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();
}
示例7: 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));
}
示例8: 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;
}
}
示例9: 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);
}
}
示例10: confirmation
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
public String confirmation() {
Alert alert = this.switchTo().alert();
String alertText = alert.getText();
alert.accept();
return alertText;
}
示例11: isElementPresent
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
public boolean isElementPresent() {
try {
if ( (element.getUiDriver() instanceof HiddenBrowserDriver)
&& (element instanceof UiAlert || element instanceof UiPrompt || element instanceof UiConfirm)) {
return false;
}
if (element instanceof UiAlert || element instanceof UiConfirm) {
Alert dialog = webDriver.switchTo().alert();
return dialog != null;
} else if (element instanceof UiPrompt) {
Alert prompt = webDriver.switchTo().alert();
return prompt.getText() != null && !prompt.getText().equals("false");
// return seleniumBrowser.isPromptPresent(); // Not implemented yet
}
HiddenHtmlElementLocator.findElement(this.element, null, false);
return true;
} catch (NotFoundException nfe) {
return false;
} catch (ElementNotFoundException enfe) {
return false;
}
}
示例12: 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;
}
}
示例13: alertGetMessage
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Nullable
public String alertGetMessage() {
try {
Alert alert = driver().switchTo().alert();
String msg = alert.getText();
alert.accept();
return msg;
} catch(Exception ex) {
return null;
}
}
示例14: alertPresent
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
public static ExpectedCondition<QAFExtendedWebDriver, Alert> alertPresent() {
return new ExpectedCondition<QAFExtendedWebDriver, Alert>() {
@Override
public Alert apply(QAFExtendedWebDriver driver) {
try {
Alert alert = driver.switchTo().alert();
alert.getText();
return alert;
} catch (NullPointerException e) {
}
return null;
}
};
}
示例15: 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);
}
}