From ea220db926b379040128da5683e5a2223c7bdab1 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 20 Jul 2016 22:17:16 +0200 Subject: [PATCH] Ability to use selenide and phantomjs in ITs * selenide should replace Selenese HTML tests * phantomjs should replace Firefox in environments that require XVFB --- .travis.yml | 1 + it/it-tests/pom.xml | 10 +- .../src/test/java/it/Category4Suite.java | 2 + .../src/test/java/it/lite/LiteTest.java | 23 ++++ .../java/it/measure/ProjectOverviewTest.java | 11 +- .../QualityProfilesPageTest.java | 17 ++- it/it-tests/src/test/java/it/ui/UiTest.java | 32 +++-- .../it/updateCenter/UpdateCenterTest.java | 1 - .../test/java/it/user/AuthenticationTest.java | 61 ++++++++++ .../src/test/java/pageobjects/LoginPage.java | 53 +++++++++ .../src/test/java/pageobjects/Navigation.java | 112 ++++++++++++++++++ .../src/test/java/pageobjects/RuleItem.java | 41 +++++++ .../src/test/java/pageobjects/RulesPage.java | 52 ++++++++ .../test/java/pageobjects/SelenideConfig.java | 49 ++++++++ it/it-tests/src/test/java/util/ItUtils.java | 34 ++++-- ...display-nice-error-on-unknown-project.html | 24 ---- .../QualityProfilesPageTest/not_found.html | 24 ---- .../src/test/resources/ui/UiTest/footer.html | 28 ----- travis.sh | 26 +++- 19 files changed, 492 insertions(+), 109 deletions(-) create mode 100644 it/it-tests/src/test/java/it/user/AuthenticationTest.java create mode 100644 it/it-tests/src/test/java/pageobjects/LoginPage.java create mode 100644 it/it-tests/src/test/java/pageobjects/Navigation.java create mode 100644 it/it-tests/src/test/java/pageobjects/RuleItem.java create mode 100644 it/it-tests/src/test/java/pageobjects/RulesPage.java create mode 100644 it/it-tests/src/test/java/pageobjects/SelenideConfig.java delete mode 100644 it/it-tests/src/test/resources/measure/ProjectOverviewTest/should-display-nice-error-on-unknown-project.html delete mode 100644 it/it-tests/src/test/resources/qualityProfile/QualityProfilesPageTest/not_found.html delete mode 100644 it/it-tests/src/test/resources/ui/UiTest/footer.html diff --git a/.travis.yml b/.travis.yml index 25114af6581..063a3632829 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ cache: - server/sonar-web/node - server/sonar-web/node_modules - $HOME/jvm + - $HOME/phantomjs before_cache: # remove all the artifacts (JAR, ZIP) that are installed in local repo because of mvn deploy diff --git a/it/it-tests/pom.xml b/it/it-tests/pom.xml index c70e2d7d1b8..f13d10e223c 100644 --- a/it/it-tests/pom.xml +++ b/it/it-tests/pom.xml @@ -44,6 +44,12 @@ pom provided + + com.codeborne + selenide + 3.7 + test + com.google.guava guava @@ -116,7 +122,9 @@ org.apache.maven.plugins maven-surefire-plugin - -Xmx128m -Dsonar.runtimeVersion=${project.version} -Dmaven.localRepository=${settings.localRepository} + -Xmx128m -Dsonar.runtimeVersion=${project.version} + -Dmaven.localRepository=${settings.localRepository} + ${skipIts} */${category}Suite.java diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java index 3596a72be42..15474220cbd 100644 --- a/it/it-tests/src/test/java/it/Category4Suite.java +++ b/it/it-tests/src/test/java/it/Category4Suite.java @@ -37,6 +37,7 @@ import it.qualityProfile.QualityProfilesPageTest; import it.serverSystem.ServerSystemTest; import it.ui.UiTest; import it.uiExtension.UiExtensionsTest; +import it.user.AuthenticationTest; import it.user.BaseIdentityProviderTest; import it.user.FavouriteTest; import it.user.ForceAuthenticationTest; @@ -60,6 +61,7 @@ import static util.ItUtils.xooPlugin; MyAccountPageTest.class, FavouriteTest.class, // authentication + AuthenticationTest.class, ForceAuthenticationTest.class, LocalAuthenticationTest.class, BaseIdentityProviderTest.class, diff --git a/it/it-tests/src/test/java/it/lite/LiteTest.java b/it/it-tests/src/test/java/it/lite/LiteTest.java index f013e3a5c95..02c423e6d05 100644 --- a/it/it-tests/src/test/java/it/lite/LiteTest.java +++ b/it/it-tests/src/test/java/it/lite/LiteTest.java @@ -19,6 +19,8 @@ */ package it.lite; +import com.codeborne.selenide.CollectionCondition; +import com.codeborne.selenide.Condition; import com.sonar.orchestrator.Orchestrator; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -31,8 +33,13 @@ import org.sonarqube.ws.client.component.TreeWsRequest; import org.sonarqube.ws.client.issue.SearchWsRequest; import org.sonarqube.ws.client.measure.ComponentTreeWsRequest; import org.sonarqube.ws.client.measure.ComponentWsRequest; +import pageobjects.Navigation; +import pageobjects.RuleItem; +import pageobjects.RulesPage; import util.ItUtils; +import static com.codeborne.selenide.Condition.hasText; +import static com.codeborne.selenide.Condition.or; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; @@ -98,4 +105,20 @@ public class LiteTest { assertThat(c.getMeasuresList()).extracting(m -> m.getMetric()).containsOnly("lines", "ncloc"); }); } + + @Test + public void open_page_rules() { + RulesPage rulesPage = Navigation.get(ORCHESTRATOR) + .openHomepage() + .clickOnRules(); + + // wait for rules to be displayed + rulesPage.getRules().shouldHave(CollectionCondition.sizeGreaterThan(0)); + + assertThat(rulesPage.getTotal()).isGreaterThan(0); + for (RuleItem ruleItem : rulesPage.getRulesAsItems()) { + ruleItem.getTitle().should(Condition.visible); + ruleItem.getMetadata().should(or("have type", hasText("Bug"), hasText("Code Smell"), hasText("Vulnerability"))); + } + } } diff --git a/it/it-tests/src/test/java/it/measure/ProjectOverviewTest.java b/it/it-tests/src/test/java/it/measure/ProjectOverviewTest.java index cdcf92f1e1c..96f27688ea1 100644 --- a/it/it-tests/src/test/java/it/measure/ProjectOverviewTest.java +++ b/it/it-tests/src/test/java/it/measure/ProjectOverviewTest.java @@ -26,8 +26,10 @@ import it.Category1Suite; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import pageobjects.Navigation; import util.selenium.SeleneseTest; +import static com.codeborne.selenide.Condition.text; import static util.ItUtils.projectDir; public class ProjectOverviewTest { @@ -51,10 +53,11 @@ public class ProjectOverviewTest { } @Test - public void should_display_a_nice_error_when_requesting_unknown_project() { - Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("should_display_a_nice_error_when_requesting_unknown_project", - "/measure/ProjectOverviewTest/should-display-nice-error-on-unknown-project.html").build(); - orchestrator.executeSelenese(selenese); + public void display_a_nice_error_when_requesting_unknown_project() { + Navigation nav = Navigation.get(orchestrator); + nav.open("/dashboard/index?id=unknown"); + nav.getErrorMessage().should(text("The requested project does not exist. Either it has never been analyzed successfully or it has been deleted.")); + // TODO verify that on global homepage } private void executeBuild(String projectLocation, String projectKey, String projectName) { diff --git a/it/it-tests/src/test/java/it/qualityProfile/QualityProfilesPageTest.java b/it/it-tests/src/test/java/it/qualityProfile/QualityProfilesPageTest.java index d9ffc805ad6..cd182dfe47d 100644 --- a/it/it-tests/src/test/java/it/qualityProfile/QualityProfilesPageTest.java +++ b/it/it-tests/src/test/java/it/qualityProfile/QualityProfilesPageTest.java @@ -19,16 +19,23 @@ */ package it.qualityProfile; +import com.codeborne.selenide.Condition; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; import com.sonar.orchestrator.selenium.Selenese; import it.Category4Suite; -import org.junit.*; -import org.junit.experimental.categories.Category; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; +import pageobjects.Navigation; import util.selenium.SeleneseTest; +import static com.codeborne.selenide.Selenide.$; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.projectDir; @@ -82,9 +89,9 @@ public class QualityProfilesPageTest { @Test public void testNotFound() { - Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("test_not_found", - "/qualityProfile/QualityProfilesPageTest/not_found.html").build(); - orchestrator.executeSelenese(selenese); + Navigation nav = Navigation.get(orchestrator); + nav.open("/profiles/show?key=unknown"); + $(".quality-profile-not-found").should(Condition.visible); } @Test diff --git a/it/it-tests/src/test/java/it/ui/UiTest.java b/it/it-tests/src/test/java/it/ui/UiTest.java index 7e3a84526be..c4960f9192e 100644 --- a/it/it-tests/src/test/java/it/ui/UiTest.java +++ b/it/it-tests/src/test/java/it/ui/UiTest.java @@ -20,24 +20,38 @@ package it.ui; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.selenium.Selenese; import it.Category4Suite; +import java.util.Map; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.categories.Category; -import util.selenium.SeleneseTest; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsResponse; +import pageobjects.Navigation; +import util.ItUtils; + +import static com.codeborne.selenide.Condition.hasText; public class UiTest { @ClassRule - public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + public static final Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR; + + @Rule + public Navigation nav = Navigation.get(ORCHESTRATOR); @Test - public void test_footer() { - new SeleneseTest( - Selenese.builder().setHtmlTestsInClasspath("ui-footer", - "/ui/UiTest/footer.html" - ).build()).runOn(orchestrator); + public void footer_contains_information() { + nav.getFooter() + .should(hasText("Documentation")) + .should(hasText("SonarSource SA")); } + @Test + public void footer_contains_version() { + WsResponse status = ItUtils.newAdminWsClient(ORCHESTRATOR).wsConnector().call(new GetRequest("api/system/status")); + Map statusMap = ItUtils.jsonToMap(status.content()); + + nav.getFooter().should(hasText((String) statusMap.get("version"))); + } } diff --git a/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java b/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java index 1fea840524b..04eaadb5de1 100644 --- a/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java +++ b/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java @@ -25,7 +25,6 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.junit.ClassRule; import org.junit.Test; -import org.junit.experimental.categories.Category; import org.sonar.wsclient.services.Plugin; import org.sonar.wsclient.services.UpdateCenterQuery; import util.selenium.SeleneseTest; diff --git a/it/it-tests/src/test/java/it/user/AuthenticationTest.java b/it/it-tests/src/test/java/it/user/AuthenticationTest.java new file mode 100644 index 00000000000..e15c6af1081 --- /dev/null +++ b/it/it-tests/src/test/java/it/user/AuthenticationTest.java @@ -0,0 +1,61 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.user; + +import com.codeborne.selenide.Condition; +import com.sonar.orchestrator.Orchestrator; +import it.Category4Suite; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import pageobjects.LoginPage; +import pageobjects.Navigation; + +public class AuthenticationTest { + + @ClassRule + public static Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR; + + @Rule + public Navigation nav = Navigation.get(ORCHESTRATOR); + + @Test + public void log_in_with_correct_credentials_then_log_out() { + nav.shouldNotBeLoggedIn(); + + Navigation page = nav.logIn().submitCredentials("admin", "admin"); + page.getRightBar().shouldHave(Condition.text("Administrator")); + nav.shouldBeLoggedIn(); + + nav.logOut(); + nav.shouldNotBeLoggedIn(); + } + + @Test + public void log_in_with_wrong_credentials() { + LoginPage page = nav + .logIn() + .submitWrongCredentials("admin", "wrong"); + page.getErrorMessage().shouldHave(Condition.text("Authentication failed")); + + nav.openHomepage(); + nav.shouldNotBeLoggedIn(); + } +} diff --git a/it/it-tests/src/test/java/pageobjects/LoginPage.java b/it/it-tests/src/test/java/pageobjects/LoginPage.java new file mode 100644 index 00000000000..bf946b27afa --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/LoginPage.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package pageobjects; + +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.page; + +public class LoginPage { + + public LoginPage() { + $("#login_form").should(Condition.exist); + } + + public Navigation submitCredentials(String login, String password) { + return submitCredentials(login, password, Navigation.class); + } + + public LoginPage submitWrongCredentials(String login, String password) { + return submitCredentials(login, password, LoginPage.class); + } + + public SelenideElement getErrorMessage() { + return $(By.cssSelector("#login_form .alert")); + } + + private T submitCredentials(String login, String password, Class expectedResultPage) { + $("#login").val(login); + $("#password").val(password); + $(By.name("commit")).click(); + return page(expectedResultPage); + } +} diff --git a/it/it-tests/src/test/java/pageobjects/Navigation.java b/it/it-tests/src/test/java/pageobjects/Navigation.java new file mode 100644 index 00000000000..395509c5fad --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/Navigation.java @@ -0,0 +1,112 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package pageobjects; + +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.Selenide; +import com.codeborne.selenide.SelenideElement; +import com.codeborne.selenide.WebDriverRunner; +import com.sonar.orchestrator.Orchestrator; +import org.junit.rules.ExternalResource; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.page; + +public class Navigation extends ExternalResource { + + public static Navigation get(Orchestrator orchestrator) { + String browser = orchestrator.getConfiguration().getString("orchestrator.browser", "firefox"); + SelenideConfig.INSTANCE + .setBrowser(browser) + .setBaseUrl(orchestrator.getServer().getUrl()); + return new Navigation(); + } + + @Override + protected void before() throws Throwable { + WebDriverRunner.getWebDriver().manage().deleteAllCookies(); + openHomepage(); + } + + public Navigation openHomepage() { + return open("/", Navigation.class); + } + + public void open(String relativeUrl) { + Selenide.open(relativeUrl); + } + + public

P open(String relativeUrl, Class

pageObjectClassClass) { + return Selenide.open(relativeUrl, pageObjectClassClass); + } + + public void shouldBeLoggedIn() { + loggedInDropdown().should(Condition.visible); + } + + public void shouldNotBeLoggedIn() { + logInLink().should(Condition.visible); + } + + public LoginPage logIn() { + logInLink().click(); + return Selenide.page(LoginPage.class); + } + + public Navigation logOut() { + SelenideElement dropdown = loggedInDropdown(); + // click must be on the but not on the dropdown

  • + // for compatibility with phantomjs + dropdown.find(".dropdown-toggle").click(); + dropdown.find(By.linkText("Log out")).click(); + return this; + } + + public RulesPage clickOnRules() { + $(By.linkText("Rules")).click(); + return page(RulesPage.class); + } + + public SelenideElement clickOnQualityProfiles() { + return $(By.linkText("Quality Profiles")); + } + + public SelenideElement getRightBar() { + return $("#global-navigation .navbar-right"); + } + + public SelenideElement getFooter() { + return $("#footer"); + } + + public SelenideElement getErrorMessage() { + return $("#error"); + } + + private SelenideElement logInLink() { + return $(By.linkText("Log in")); + } + + private SelenideElement loggedInDropdown() { + return $(".js-user-authenticated"); + } + +} diff --git a/it/it-tests/src/test/java/pageobjects/RuleItem.java b/it/it-tests/src/test/java/pageobjects/RuleItem.java new file mode 100644 index 00000000000..454b04617ed --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/RuleItem.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package pageobjects; + +import com.codeborne.selenide.SelenideElement; + +public class RuleItem { + + private final SelenideElement elt; + + public RuleItem(SelenideElement elt) { + this.elt = elt; + } + + public SelenideElement getTitle() { + return elt.$(".coding-rule-title"); + } + + public SelenideElement getMetadata() { + return elt.$(".coding-rule-meta"); + } + + +} diff --git a/it/it-tests/src/test/java/pageobjects/RulesPage.java b/it/it-tests/src/test/java/pageobjects/RulesPage.java new file mode 100644 index 00000000000..6d5d1343fd7 --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/RulesPage.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package pageobjects; + +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.ElementsCollection; +import java.util.List; +import java.util.stream.Collectors; +import org.openqa.selenium.By; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; + +public class RulesPage { + + public RulesPage() { + $(By.cssSelector(".coding-rules")).should(Condition.exist); + } + + public ElementsCollection getRules() { + return $$(".coding-rules .coding-rule"); + } + + public List getRulesAsItems() { + return getRules() + .stream() + .map(elt -> new RuleItem(elt)) + .collect(Collectors.toList()); + } + + public int getTotal() { + // warning - number is localized + return Integer.parseInt($("#coding-rules-total").text()); + } +} diff --git a/it/it-tests/src/test/java/pageobjects/SelenideConfig.java b/it/it-tests/src/test/java/pageobjects/SelenideConfig.java new file mode 100644 index 00000000000..a7e9bcf6ed1 --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/SelenideConfig.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package pageobjects; + +import com.codeborne.selenide.Configuration; +import com.google.common.collect.ImmutableSet; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + +enum SelenideConfig { + INSTANCE; + + private static final Set SUPPORTED_BROWSERS = ImmutableSet.of("firefox", "phantomjs"); + + SelenideConfig() { + Configuration.reportsFolder = "target/screenshots"; + } + + public SelenideConfig setBrowser(String browser) { + checkArgument(SUPPORTED_BROWSERS.contains(requireNonNull(browser)), "Browser is not supported: %s", browser); + Configuration.browser = browser; + return this; + } + + public SelenideConfig setBaseUrl(String s) { + Configuration.baseUrl = requireNonNull(s); + return this; + } + +} diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java index 50a2fc1d414..795def12588 100644 --- a/it/it-tests/src/test/java/util/ItUtils.java +++ b/it/it-tests/src/test/java/util/ItUtils.java @@ -24,6 +24,8 @@ import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarRunner; @@ -31,10 +33,12 @@ import com.sonar.orchestrator.container.Server; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import java.io.IOException; +import java.lang.reflect.Type; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -280,18 +284,24 @@ public class ItUtils { public static List extractCeTaskIds(BuildResult buildResult) { String logs = buildResult.getLogs(); return from(LINE_SPLITTER.split(logs)) - .filter(new Predicate() { - @Override - public boolean apply(String s) { - return s.contains("More about the report processing at"); - } - }).transform(new Function() { - @Nullable - @Override - public String apply(String s) { - return s.substring(s.length() - 20, s.length()); - } - }).toList(); + .filter(new Predicate() { + @Override + public boolean apply(String s) { + return s.contains("More about the report processing at"); + } + }).transform(new Function() { + @Nullable + @Override + public String apply(String s) { + return s.substring(s.length() - 20, s.length()); + } + }).toList(); } + public static Map jsonToMap(String json) { + Gson gson = new Gson(); + Type type = new TypeToken>() { + }.getType(); + return gson.fromJson(json, type); + } } diff --git a/it/it-tests/src/test/resources/measure/ProjectOverviewTest/should-display-nice-error-on-unknown-project.html b/it/it-tests/src/test/resources/measure/ProjectOverviewTest/should-display-nice-error-on-unknown-project.html deleted file mode 100644 index 3cbf2bf44fa..00000000000 --- a/it/it-tests/src/test/resources/measure/ProjectOverviewTest/should-display-nice-error-on-unknown-project.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - static-files - - - - - - - - - - - - - - - -
    open/dashboard/index?id=unknown
    waitForTexterror*The requested project does not exist. Either it has never been analyzed successfully or it has been deleted.*
    - - diff --git a/it/it-tests/src/test/resources/qualityProfile/QualityProfilesPageTest/not_found.html b/it/it-tests/src/test/resources/qualityProfile/QualityProfilesPageTest/not_found.html deleted file mode 100644 index 220d39856d6..00000000000 --- a/it/it-tests/src/test/resources/qualityProfile/QualityProfilesPageTest/not_found.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - not_found - - - - - - - - - - - - - - - -
    open/profiles/show?key=unknown
    waitForElementPresentcss=.quality-profile-not-found
    - - \ No newline at end of file diff --git a/it/it-tests/src/test/resources/ui/UiTest/footer.html b/it/it-tests/src/test/resources/ui/UiTest/footer.html deleted file mode 100644 index 4fea7c4a5d9..00000000000 --- a/it/it-tests/src/test/resources/ui/UiTest/footer.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
    footer
    open/
    waitForTextfooter*SonarSource SA*
    - - diff --git a/travis.sh b/travis.sh index 4af83f56364..6ac9d81517f 100755 --- a/travis.sh +++ b/travis.sh @@ -2,6 +2,20 @@ set -euo pipefail +function installPhantomJs { + echo "Setup PhantomJS 2.1" + mkdir -p ~/phantomjs + pushd ~/phantomjs > /dev/null + if [ ! -d "phantomjs-2.1.1-linux-x86_64" ]; then + wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O phantomjs-2.1.1-linux-x86_64.tar.bz2 + tar -xf phantomjs-2.1.1-linux-x86_64.tar.bz2 + rm phantomjs-2.1.1-linux-x86_64.tar.bz2 + fi + popd > /dev/null + export PHANTOMJS_HOME=~/phantomjs/phantomjs-2.1.1-linux-x86_64 + export PATH=$PHANTOMJS_HOME/bin:$PATH +} + function configureTravis { mkdir ~/.local curl -sSL https://github.com/SonarSource/travis-utils/tarball/v31 | tar zx --strip-components 1 -C ~/.local @@ -21,6 +35,14 @@ CI) set_maven_build_version $TRAVIS_BUILD_NUMBER fi + if [[ $INITIAL_VERSION =~ "-SNAPSHOT" ]]; then + echo "======= Found SNAPSHOT version =======" + # Do not deploy a SNAPSHOT version but the release version related to this build + set_maven_build_version $TRAVIS_BUILD_NUMBER + else + echo "======= Found RELEASE version =======" + fi + if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo 'Analyse and trigger QA of master branch' @@ -68,7 +90,9 @@ CI) -Dsource.skip=true fi - ./run-integration-tests.sh "Lite" "" + + installPhantomJs + ./run-integration-tests.sh "Lite" "" -Dorchestrator.browser=phantomjs ;; WEB) -- 2.39.5