本文整理匯總了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);
}
}