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


Java Alert.getText方法代码示例

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

示例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;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:23,代码来源:RealHtmlElementState.java

示例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;
	}

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

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

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

示例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();
}
 
开发者ID:Simon-Kaz,项目名称:AppiumSauce,代码行数:19,代码来源:ParallelNativeIOSTest.java

示例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));
}
 
开发者ID:Simon-Kaz,项目名称:AppiumSauce,代码行数:20,代码来源:ParallelNativeIOSTest.java

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

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

示例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;
}
 
开发者ID:Nonorc,项目名称:saladium,代码行数:8,代码来源:SaladiumDriver.java

示例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;
    }

}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:30,代码来源:HiddenHtmlElementState.java

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

示例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;
	}
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:12,代码来源:WebDriverConnector.java

示例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;
		}
	};
}
 
开发者ID:qmetry,项目名称:qaf,代码行数:15,代码来源:QAFWebDriverExpectedConditions.java

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


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