/** * 获取对话框文本 * @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; } }
@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(); } }
@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(); } }
@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(); } }
private void waitForIncomingCallDialog(WebDriver driver) throws InterruptedException { int i = 0; for (; i < TEST_TIMEOUT; i++) { try { driver.switchTo().alert(); break; } catch (NoAlertPresentException e) { Thread.sleep(1000); } } if (i == TEST_TIMEOUT) { throw new RuntimeException("Timeout (" + TEST_TIMEOUT + " seconds) waiting for incoming call"); } }
private void testSanitization() { ______TS("safe against injection from admin search page"); AdminSearchPage searchPageForInjection = logPage .navigateTo(createUrl(Const.ActionURIs.ADMIN_SEARCH_PAGE)) .changePageType(AdminSearchPage.class); String injectedScript = "Test Injected Script<script>alert('This is not good.');</script>"; searchPageForInjection.inputSearchContent(injectedScript); searchPageForInjection.clickSearchButton(); searchPageForInjection.waitForPageToLoad(); logPage.navigateTo(createUrl(Const.ActionURIs.ADMIN_ACTIVITY_LOG_PAGE)); logPage.waitForPageToLoad(); try { browser.driver.switchTo().alert(); signalFailureToDetectException("Script managed to get injected"); } catch (NoAlertPresentException e) { // this is what we expect, since we expect the script injection to fail } }
@Before public void setUp() { try { // Close alerts if present driver.switchTo().alert().accept(); } catch (NoAlertPresentException ex) { // Nothing to do... } // Restart cookies and browser driver.manage().deleteAllCookies(); driver.get("about:blank"); startMockServer(); }
/** * Close window. * * @param winHandle * the win handle * @throws BrowserUnexpectedException */ public void closeWindow(String winHandle) throws BrowserUnexpectedException { BrowserWindow closingWindow = getWindowByHandle(winHandle); if (null == closingWindow) { // if (winHandle.equals(getWindowOnFocusHandle())) { // getDriver().close(); // } else { // getDriver().switchTo().window(winHandle); // getDriver().close(); // } throw GlobalUtils.createNotInitializedException("windows"); } else { closingWindow.close(); try { // test if there is alert. if no, refresh windows list checkCloseWindowAlert(closingWindow.getWindowHandle()); closingWindow.setClosed(false); } catch (NoAlertPresentException noAlert) { if (getNumberOfOpenWindows() > 0) refreshWindowsList(getDriver(), false); } } }
private void checkCloseWindowAlert(String winh) throws NoAlertPresentException { try { Alert alt = getDriver().switchTo().alert(); if (alt == null) throw GlobalUtils.createInternalError("web driver"); PopupPromptDialog aDialog = new PopupPromptDialog(getDriver(), alt, alerts.size()); aDialog.setClosingWindowHandle(winh); alerts.add(aDialog); } catch (UnreachableBrowserException error) { if (getNumberOfOpenWindows() > 0) throw GlobalUtils .createInternalError("ATE multi windows handler", error); } catch (UnsupportedOperationException e) { throw GlobalUtils .createInternalError("Driver doesn't support alert handling yet", e); } catch (NoSuchWindowException windClosedAlready) { //do nothing if window closed without alert dialog intervention. for example in Chrome. throw new NoAlertPresentException(windClosedAlready); } }
@Test(groups = "wso2.es.common", description = "Test XSS in Gadgets Page") public void testListGadgetsXSSTestCase() throws Exception { String alertMessage = "XSS"; String url = baseUrl + "/store/assets/gadget/list?" + "sortBy=overview_name&sort=}</script><script>alert('" + alertMessage + "')</script>"; driver.get(url); boolean scriptInjected = false; try { String actualAlertMessage = closeAlertAndGetItsText(driver, false); if (actualAlertMessage.equals(alertMessage)) scriptInjected = true; } catch (NoAlertPresentException ex) { } assertFalse(scriptInjected, "Script injected via the query string"); }
/** * * @return {@link Alert} object representing HTML alert, prompt or confirmation modal dialog */ private Alert getAlert() { try { return this.webDriver.switchTo().alert(); } catch (NoAlertPresentException e) { throw new ElementNotFoundException(e); } }
/** * * @return {@link Alert} object representing HTML alert, prompt or confirmation modal dialog */ private Alert getAlert() { try { return this.webDriver.switchTo().alert(); } catch (NoAlertPresentException e) { return null; } }
/** * Opens the APPRTC_URL and clicks 'confirm-join-button'. */ private void takeAction() { Random rand = new Random(System.currentTimeMillis()); long channel = Math.abs(rand.nextLong()); for (WebDriver webDriver : this.getWebDriverList()) { webDriver.get(APPRTC_URL + channel); try { webDriver.switchTo().alert().accept(); } catch (NoAlertPresentException e) { logger.warn(e.getLocalizedMessage()); } webDriver.findElement(By.id("confirm-join-button")).click(); } }
boolean isAlertPresent() { try { getDriver().switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } }
private boolean isAlertPresent(WebDriver Driver) { try { Driver.switchTo().alert(); return true; } catch (NoAlertPresentException e) { Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, e); return false; } }
private boolean isAlertPresent(WebDriver Driver) { try { Driver.switchTo().alert(); return true; } catch (NoAlertPresentException e) { Logger.getLogger(this.getClass().getName()).log(Level.OFF, e.getMessage(), e); return false; } }
public boolean isAlertPresent() { try { Driver.switchTo().alert(); return true; } catch (NoAlertPresentException e) { Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, e); return false; } }
@Override protected void onError(Description description, Throwable testFailure) throws Throwable { super.onError(description, testFailure); WebDriver webDriver = seleniumProvider.getWebDriver(); try { Alert alert = webDriver.switchTo().alert(); testFailure.addSuppressed(new RuntimeException("Unexpected alert with text: '" + alert.getText() + "'!")); } catch (NoAlertPresentException ignored) { } finally { webDriver.switchTo().defaultContent(); } }
public boolean isAlertPresent() { try { wd.switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } }
private void cleanDriver() { manage().deleteAllCookies(); get(BLANK_PAGE); if (!mobile) { try { switchTo().alert().accept(); } catch (NoAlertPresentException e) { LOG.debug("No alert was present when returnDriver was executed: {}", e); } } if (maximize) { manage().window().maximize(); } }
private void setUp(boolean maximize, boolean reusable, boolean mobile) { testedObject = spy( new ClosingAwareWebDriverWrapper(webDriver, frameSwitcher, maximize, reusable, mobile)); when(webDriver.manage()).thenReturn(options); when(webDriver.manage().window()).thenReturn(window); when(webDriver.switchTo()).thenReturn(bobcatTargetLocator); when(webDriver.switchTo().alert()).thenReturn(alert); doThrow(new NoAlertPresentException()).when(alert).accept(); }
/** * Accept any displayed alert message. If no alert is displayed, an exception will be thrown. * <p> * Fires {@link AcceptedAlertEvent} in case a alert was successfully accepted. * * @throws NoAlertPresentException in case no alert is present * @see Alert#accept() * @since 2.0 */ public void accept() throws NoAlertPresentException { StringBuilder builder = new StringBuilder(); ActionTemplate.browser(browser()).execute(browser -> { Alert alert = webDriver().switchTo().alert(); builder.append(alert.getText()); alert.accept(); }).fireEvent(browser -> new AcceptedAlertEvent(builder.toString())); log.debug("alert was accepted"); }
/** * Declines any displayed alert message. If no alert is displayed, an exception will be thrown. * <p> * Fires {@link DeclinedAlertEvent} in case a alert was successfully accepted. * * @throws NoAlertPresentException in case no alert is present * @see Alert#dismiss() * @since 2.0 */ public void decline() throws NoAlertPresentException { StringBuilder builder = new StringBuilder(); ActionTemplate.browser(browser()).execute(browser -> { Alert alert = webDriver().switchTo().alert(); builder.append(alert.getText()); alert.dismiss(); }).fireEvent(browser -> new DeclinedAlertEvent(builder.toString())); log.debug("alert was declined"); }
/** * 点击确认按钮 */ public void alertConfirm() { Alert alert=driver.switchTo().alert(); try { alert.accept(); log.info("点击确认按钮"); } catch (NoAlertPresentException notFindAlert) { // TODO: handle exception //throw notFindAlert; log.error("找不到确认按钮"); throw notFindAlert; } }
/** * 点击取消按钮 */ public void alertDismiss() { Alert alert= driver.switchTo().alert(); try { alert.dismiss(); log.info("点击取消按钮"); } catch (NoAlertPresentException notFindAlert) { // TODO: handle exception //throw notFindAlert; log.error("找不到取消按钮"); throw notFindAlert; } }
public boolean isAlertPresent() { try { driver.switchTo().alert(); oLog.info("true"); return true; } catch (NoAlertPresentException e) { // Ignore oLog.info("false"); return false; } }
@Override public boolean occurred() { try { webDriver.seleniumWebDriver().switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } }
public void handlePushNotificationAlert() { try { String alertText = getAppiumDriver().switchTo().alert().getText(); logger.info(alertText); if (alertText.contains("Would Like to Send You Notifications Notifications may include alerts, sounds, and icon badges. These can be configured in Settings.")) { logger.info("Push Notification alert raised : " + getAppiumDriver().switchTo().alert().getText()); okBtn.click(); } } catch (NoAlertPresentException ex) { logger.info("Push Notification alert did not pop up"); } }
public void addOrganisation(int accountType, String accountName, String url, OAuthCredentials oAuthCredentials, boolean autoSync) { linkRepositoryButton.click(); waitFormBecomeVisible(); dvcsTypeSelect.select(dvcsTypeSelect.getAllOptions().get(accountType)); organization.clear().type(accountName); switch (accountType) { case 0: oauthBbClientId.clear().type(oAuthCredentials.key); oauthBbSecret.clear().type(oAuthCredentials.secret); break; case 1: oauthClientId.clear().type(oAuthCredentials.key); oauthSecret.clear().type(oAuthCredentials.secret); break; case 2: urlGhe.clear().type(url); oauthClientIdGhe.clear().type(oAuthCredentials.key); oauthSecretGhe.clear().type(oAuthCredentials.secret); break; default: break; } autoLinkNewRepos.click(); addOrgButton.click(); // dismiss any information alert try { webDriver.switchTo().alert().accept(); } catch (NoAlertPresentException e) { // nothing to do } }
@Override public String get(TestRun ctx) { try { ctx.driver().switchTo().alert(); return "" + true; } catch (NoAlertPresentException e) { return "" + false; } }
@Override public boolean test(final WebDriver driver) { JavascriptExecutor executor = (JavascriptExecutor)driver; try { driver.switchTo().alert(); return true; } catch (NoAlertPresentException nape) { return false; } }