From 525e102ac6942a032546559ae14ecf20bfb20da9 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 11 Nov 2017 12:04:33 +0100 Subject: Add category measure to integration tests --- .../src/main/java/org/sonarqube/qa/util/Tester.java | 11 ++++++++++- .../main/java/org/sonarqube/qa/util/UserTester.java | 20 ++++++++++++++++++-- .../qa/util/pageobjects/measures/MeasuresPage.java | 13 ++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) (limited to 'server/sonar-qa-util/src') diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java index 50412d8bc50..f5077ad3266 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java @@ -39,12 +39,21 @@ import static java.util.Objects.requireNonNull; *
  • clean-up of users between tests
  • *
  • clean-up of session when opening a browser (cookies, local storage)
  • *
  • quick access to {@link WsClient} instances
  • + *
  • clean-up of defined settings. Properties that are not defined by a plugin are not reset.
  • *
  • helpers to generate organizations and users
  • * - *

    + * * Recommendation is to define a {@code @Rule} instance. If not possible, then * {@code @ClassRule} must be used through a {@link org.junit.rules.RuleChain} * around {@link Orchestrator}. + * + * Not supported: + *

    */ public class Tester extends ExternalResource implements TesterSession { diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java index 5f4f4a943d0..6c57c8a81aa 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/UserTester.java @@ -67,6 +67,9 @@ public class UserTester { return service().create(request.build()).getUser(); } + /** + * For standalone mode only + */ @SafeVarargs public final User generateAdministrator(Consumer... populators) { User user = generate(populators); @@ -77,16 +80,29 @@ public class UserTester { @SafeVarargs public final User generateAdministrator(Organizations.Organization organization, Consumer... populators) { + String organizationKey = organization.getKey(); User user = generate(populators); - session.wsClient().organizations().addMember(organization.getKey(), user.getLogin()); + session.wsClient().organizations().addMember(organizationKey, user.getLogin()); session.wsClient().userGroups().addUser(AddUserWsRequest.builder() - .setOrganization(organization.getKey()) + .setOrganization(organizationKey) .setLogin(user.getLogin()) .setName("Owners") .build()); return user; } + @SafeVarargs + public final User generateAdministratorOnDefaultOrganization(Consumer... populators) { + User user = generate(populators); + session.wsClient().organizations().addMember("default-organization", user.getLogin()); + session.wsClient().userGroups().addUser(AddUserWsRequest.builder() + .setOrganization("default-organization") + .setLogin(user.getLogin()) + .setName("sonar-administrators") + .build()); + return user; + } + @SafeVarargs public final User generateMember(Organizations.Organization organization, Consumer... populators) { User user = generate(populators); diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/measures/MeasuresPage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/measures/MeasuresPage.java index f3cd21aac1b..4e39003c048 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/measures/MeasuresPage.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/measures/MeasuresPage.java @@ -23,7 +23,9 @@ import com.codeborne.selenide.CollectionCondition; import com.codeborne.selenide.Condition; import com.codeborne.selenide.Selenide; import com.codeborne.selenide.SelenideElement; +import com.codeborne.selenide.WebDriverRunner; import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; public class MeasuresPage { public MeasuresPage() { @@ -61,7 +63,16 @@ public class MeasuresPage { } public MeasuresPage backShortcut() { - Selenide.$(".layout-page-header-panel").sendKeys(Keys.LEFT); + SelenideElement panel = Selenide.$(".layout-page-header-panel"); + + // panel.sendKeys(Keys.LEFT) does not work correctly on Chrome + // The workaround is to use Actions + // https://bugs.chromium.org/p/chromedriver/issues/detail?id=35 + Actions actions = new Actions(WebDriverRunner.getWebDriver()); + actions.moveToElement(panel); + actions.click(); + actions.sendKeys(Keys.LEFT); + actions.build().perform(); return this; } -- cgit v1.2.3