Skip to content

Commit

Permalink
Merge pull request #643 from Vlatombe/flaky-logins
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe authored Feb 22, 2021
2 parents d6ad8e4 + 59e0baa commit 67237e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
28 changes: 13 additions & 15 deletions src/main/java/org/jenkinsci/test/acceptance/po/Login.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.jenkinsci.test.acceptance.po;

import java.time.Duration;
import org.openqa.selenium.support.ui.ExpectedConditions;

import org.junit.Assert;
import org.openqa.selenium.WebElement;
import java.util.concurrent.TimeUnit;

import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.jenkinsci.test.acceptance.Matchers.hasInvalidLoginInformation;
import static org.jenkinsci.test.acceptance.Matchers.loggedInAs;

Expand Down Expand Up @@ -37,18 +38,11 @@ public Login doLogin(String user, String password){
}

/**
* Login assuming "path" form element unavailability.<br>
* Paths are usually unavailable when using the "existing" Jenkins controller.<br>
* (Unavailable despite pre-installed form-element-path plugin.)
* @deprecated use {@link #doLogin(String, String)} instead. It doesn't require form-element-path.
*/
@Deprecated
public Login doLoginDespiteNoPaths(String user, String password){
driver.findElement(by.name("j_username")).sendKeys(user);
driver.findElement(by.name("j_password")).sendKeys(password);
WebElement we = driver.findElement(by.name("Submit"));
// for some reason submit() is bogus
we.click();
cUser.waitFor(we).withTimeout(Duration.ofSeconds(30)).until(CapybaraPortingLayerImpl::isStale);
return this;
return doLogin(user, password);
}

/**
Expand All @@ -64,7 +58,11 @@ public Login doLogin(User user) {

public Login doSuccessfulLogin(String user, String password) {
this.doLogin(user, password);
Assert.assertThat(this, loggedInAs(user));
waitFor().withTimeout(30, TimeUnit.SECONDS).until(() -> {
assertThat(this, not(hasInvalidLoginInformation())); // login hasn't failed
return ExpectedConditions.visibilityOfElementLocated(by.id("jenkins")); // redirect has happened
});
assertThat(this, loggedInAs(user));
return this;
}

Expand All @@ -78,7 +76,7 @@ public Login doSuccessfulLogin(User user) {

public Login doFailedLogin(String user, String password) {
this.doLogin(user, password);
Assert.assertThat(this, hasInvalidLoginInformation());
assertThat(this, hasInvalidLoginInformation());
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/plugins/ActiveDirectoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public void wannabe_cannot_login_to_Jenkins_after_AD_security_configured() {
String userWannabe = ENV.getUser() + "-wannabe";
GlobalSecurityConfig security = saveSecurityConfig(userWannabe);
jenkins.logout();
jenkins.login().doLoginDespiteNoPaths(userWannabe,
jenkins.login().doLogin(userWannabe,
ENV.getPassword());
security.configure();
assertThat(getElement(by.name("_.domain")), is(nullValue()));
jenkins.login().doLoginDespiteNoPaths(ENV.getUser(),
jenkins.login().doLogin(ENV.getUser(),
ENV.getPassword());
}

Expand All @@ -103,7 +103,7 @@ public void tearDown() {

private void userCanLoginToJenkinsAsAdmin(String userOrGroupToAddAsAdmin) {
GlobalSecurityConfig security = saveSecurityConfig(userOrGroupToAddAsAdmin);
jenkins.login().doLoginDespiteNoPaths(ENV.getUser(),
jenkins.login().doLogin(ENV.getUser(),
ENV.getPassword());
security.configure();
WebElement domain = getElement(by.name("_.domain"));
Expand Down

0 comments on commit 67237e8

Please sign in to comment.