@Before(EXECUTION_ALERT_AUTHENTICATION) public void beforeAlertAuthentication(JoinPoint joinPoint) throws Throwable { try { listener.beforeAuthentication(driver, (Alert) castTarget(joinPoint), (Credentials) castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } }
@After(EXECUTION_ALERT_AUTHENTICATION) public void afterAlertAuthentication(JoinPoint joinPoint) throws Throwable { try { listener.afterAuthentication(driver, (Alert) castTarget(joinPoint), (Credentials) castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } }
@Test public void canAuthenticateWithUsernameAndPassword() { Alert alert = alertIsPresent("please sign in"); cut.authenticateWith("foo", "bar"); verify(alert).authenticateUsing(credentialsCaptor.capture()); Credentials credentials = credentialsCaptor.getValue(); assertThat(credentials).isInstanceOf(UserAndPassword.class); assertThat((( UserAndPassword ) credentials).getUsername()).isEqualTo("foo"); assertThat((( UserAndPassword ) credentials).getPassword()).isEqualTo("bar"); }
@Override public void beforeAuthentication(WebDriver driver, Alert alert, Credentials credentials) { ((AlertEventListener) dispatcher).beforeAuthentication(driver, alert, credentials); }
@Override public void afterAuthentication(WebDriver driver, Alert alert, Credentials credentials) { ((AlertEventListener) dispatcher).afterAuthentication(driver, alert, credentials); }
@Override public void setCredentials(Credentials credentials) { alert.setCredentials(credentials); }
@Override public void authenticateUsing(Credentials credentials) { alert.authenticateUsing(credentials); waitUntilAlertIsNotPresent(); }
@Override public void setCredentials(Credentials credentials) { alert().setCredentials(credentials); }
@Override public void authenticateUsing(Credentials credentials) { alert().authenticateUsing(credentials); }
@Test public void canAuthenticateWithCredentials() { Alert alert = alertIsPresent("please sign in"); Credentials credentials = new UserAndPassword("foo", "bar"); cut.authenticateWith(credentials); verify(alert).authenticateUsing(credentials); }
/** * Authenticates the user using the given username and password. This will * work only if the credentials are requested through an alert window. * * @param username * the user name * @param password * the password */ public void authenticateOnNextAlert(String username, String password) { Credentials credentials = new UserAndPassword(username, password); Alert alert = driver.switchTo().alert(); alert.authenticateUsing(credentials); }
/** * This action will be performed each time before * {@link org.openqa.selenium.Alert#setCredentials(Credentials)} and * {@link org.openqa.selenium.Alert#authenticateUsing(Credentials)} * * @param driver WebDriver * @param alert {@link org.openqa.selenium.Alert} which is receiving user credentials * @param credentials which are being sent */ void beforeAuthentication(WebDriver driver, Alert alert, Credentials credentials);
/** * This action will be performed each time after * {@link org.openqa.selenium.Alert#setCredentials(Credentials)} and * {@link org.openqa.selenium.Alert#authenticateUsing(Credentials)} * * @param driver WebDriver * @param alert {@link org.openqa.selenium.Alert} which has received user credentials * @param credentials which have been sent */ void afterAuthentication(WebDriver driver, Alert alert, Credentials credentials);
/** * Authenticate a Basic-Auth popup using the given {@link Credentials credendials}. * <p> * This operation is decalred as "BETA" by the Selenium developers and might break in the future in case it changes. * * @param credentials the credentials to use * @see Alert#authenticateUsing(Credentials) * @since 2.0 */ @Beta public void authenticateWith(Credentials credentials) { ActionTemplate.browser(browser()).execute(browser -> webDriver().switchTo().alert().authenticateUsing(credentials)); log.debug("authenticated using credentials: {}", credentials); }