List of usage examples for org.openqa.selenium NoAlertPresentException NoAlertPresentException
public NoAlertPresentException()
From source file:com.cognifide.qa.bb.provider.selenium.webdriver.close.ClosingAwareWebDriverWrapperTest.java
License:Apache License
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(); }
From source file:de.learnlib.alex.data.entities.actions.web.AlertAcceptDismissActionTest.java
License:Apache License
@Test public void shouldFailIfNoAlertIsPresent() { Mockito.when(targetLocator.alert()).thenThrow(new NoAlertPresentException()); final ExecuteResult result = action.execute(connectors); Assert.assertFalse(result.isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.AlertGetTextActionTest.java
License:Apache License
@Test(expected = IllegalStateException.class) public void shouldFailWhenNoAlertIsPresent() { Mockito.when(targetLocator.alert()).thenThrow(new NoAlertPresentException()); final ExecuteResult result = action.executeAction(connectors); Assert.assertFalse(result.isSuccess()); variableStore.get(VARIABLE_NAME);/*from w w w . ja v a 2 s.c o m*/ }
From source file:org.fluentlenium.assertj.unit.AlertAssertTest.java
License:Apache License
@Test(expected = AssertionError.class) public void testHasTextKoNoAlert() throws Exception { doThrow(new NoAlertPresentException()).when(alert).getText(); alertAssert.hasText("some text"); }
From source file:org.fluentlenium.assertj.unit.AlertAssertTest.java
License:Apache License
@Test(expected = AssertionError.class) public void testIsPresentKo() { doThrow(new NoAlertPresentException()).when(alert).switchTo(); alertAssert.isPresent();//from www . ja v a 2 s .c om }
From source file:org.sugarcrm.voodoodriver.EventLoop.java
License:Apache License
private boolean alertEvent(VDDHash event) { boolean result = false; boolean alert_var = false; boolean exists = true; boolean user_exists_true = false; boolean required = true; String msg = ""; String alert_text = ""; int timeout = 2; this.report.Log("Alert event starting."); if (!event.containsKey("alert") && !event.containsKey("exists")) { result = false;//from w w w. jav a2 s . com this.report.ReportError("Alert event missing alert attribute!"); return result; } if (event.containsKey("alert")) { String tmp = event.get("alert").toString(); tmp = this.replaceString(tmp); alert_var = this.clickToBool(tmp); } if (event.containsKey("exists")) { String tmp = event.get("exists").toString(); tmp = this.replaceString(tmp); exists = this.clickToBool(tmp); if (exists) { user_exists_true = true; } } if (event.containsKey("timeout")) { try { timeout = Integer.valueOf(replaceString((String) event.get("timeout"))); } catch (NullPointerException e) { this.report.ReportError("No value specified for timeout."); } catch (NumberFormatException e) { this.report.ReportError("Invalid integer value for timeout."); } } if (event.containsKey("required")) { String s = (String) event.get("required"); required = this.clickToBool(this.replaceString(s)); } try { Alert alert = null; while (timeout > 0) { try { alert = this.Browser.getDriver().switchTo().alert(); break; } catch (NoAlertPresentException e) { try { Thread.sleep(1000); } catch (InterruptedException i) { } timeout -= 1; } } if (alert == null) { throw new NoAlertPresentException(); } alert_text = alert.getText(); msg = String.format("Found Alert dialog: '%s'.", alert_text); this.report.Log(msg); handleVars(alert_text, event); if (event.containsKey("assert")) { String ass = event.get("assert").toString(); ass = this.replaceString(ass); this.report.Assert(ass, alert_text); } if (event.containsKey("assertnot")) { String ass = event.get("assertnot").toString(); ass = this.replaceString(ass); this.report.AssertNot(ass, alert_text); } if (alert_var) { this.report.Log("Alert is being Accepted."); alert.accept(); } else { this.report.Log("Alert is being Dismissed."); alert.dismiss(); } try { this.Browser.getDriver().switchTo().defaultContent(); } catch (Exception e) { /* * Bug 53577: if this alert is put up in response to a * window.close, switching back to the default content * will throw an exception. Curiously, it's a javascript * exception rather than NoSuchFrameException or * NoSuchWindowException that would be expected. Catch * generic "Exception" in case the Selenium folks fix the * Javascript error. */ this.report.Log("Unable to switch back to window. Is it closed?"); } Thread.currentThread(); Thread.sleep(1000); if (user_exists_true) { this.report.Assert("Alert dialog does exist.", true, true); } this.firePlugin(null, Elements.ALERT, PluginEvent.AFTERDIALOGCLOSED); result = true; } catch (NoAlertPresentException exp) { if (!exists) { msg = String.format("Expected alert dialog does not exist.", exists); this.report.Assert(msg, false, false); result = true; } else if (required) { this.report.ReportError("Error: No alert dialog found!"); result = false; } } catch (Exception exp) { this.report.ReportException(exp); result = false; } this.report.Log("Alert event finished."); return result; }