當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。