]> source.dussan.org Git - sonarqube.git/commitdiff
Upgrade Selenide to 4.4.3
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 12 May 2017 17:39:42 +0000 (19:39 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sat, 10 Jun 2017 13:56:58 +0000 (15:56 +0200)
it/it-tests/pom.xml
it/it-tests/src/test/java/pageobjects/Navigation.java
it/it-tests/src/test/java/pageobjects/SelenideConfig.java
it/it-tests/src/test/java/util/selenium/Browser.java
it/it-tests/src/test/resources/administration/UsersPageTest/admin_should_change_its_own_password.html
tests/upgrade/pom.xml

index 733dabdd89fd27be2acfd4b7c5b5314dc3655a16..0e1ee808e1437a986f11c2781e44e4b8c25371d8 100644 (file)
     <dependency>
       <groupId>com.codeborne</groupId>
       <artifactId>selenide</artifactId>
-      <version>3.7</version>
-      <scope>test</scope>
+      <version>4.4.3</version>
     </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
+      <!-- required for selenide -->
+      <version>21.0</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.sonar</groupId>
index 47a0dd966f6062d99718c201726398536c12da7d..2ff9f7733a7b9d11eefd269997d6fdfda0f53731 100644 (file)
@@ -42,10 +42,7 @@ 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());
+    SelenideConfig.configure(orchestrator);
     return new Navigation();
   }
 
index 1b9044ccaa3528a3741866f1af1f48d9aa84c15e..6bc67c3644db66a69ea19dca2721d4a0da70d29f 100644 (file)
 package pageobjects;
 
 import com.codeborne.selenide.Configuration;
-import com.google.common.collect.ImmutableSet;
-import java.util.Set;
+import com.sonar.orchestrator.Orchestrator;
+import java.util.stream.Collectors;
 
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
+import static java.util.Arrays.stream;
 
-enum SelenideConfig {
-  INSTANCE;
+class SelenideConfig {
 
-  private static final Set<String> SUPPORTED_BROWSERS = ImmutableSet.of("firefox", "phantomjs");
+  private enum Browser {
+    firefox("(v46 and lower)"),
+    marionette("(recent Firefox)"),
+    chrome("(require Chromedriver)"),
+    phantomjs("(headless)");
 
-  SelenideConfig() {
-    Configuration.timeout = 8000;
-    Configuration.reportsFolder = "target/screenshots";
-  }
+    private final String label;
 
-  public SelenideConfig setBrowser(String browser) {
-    checkArgument(SUPPORTED_BROWSERS.contains(requireNonNull(browser)), "Browser is not supported: %s", browser);
-    Configuration.browser = browser;
-    return this;
+    Browser(String label) {
+      this.label = label;
+    }
+
+    static Browser of(String s) {
+      try {
+        return Browser.valueOf(s);
+      } catch (Exception e) {
+        throw new IllegalArgumentException("Invalid browser: " + s + ". Supported values are " +
+          stream(values()).map(b -> b.name() + " " + b.label).collect(Collectors.joining(", ")));
+      }
+    }
   }
 
-  public SelenideConfig setBaseUrl(String s) {
-    Configuration.baseUrl = requireNonNull(s);
-    return this;
+  public static void configure(Orchestrator orchestrator) {
+    String browserKey = orchestrator.getConfiguration().getString("orchestrator.browser", Browser.firefox.name());
+    Browser browser = Browser.of(browserKey);
+    Configuration.browser = browser.name();
+    Configuration.baseUrl = orchestrator.getServer().getUrl();
+    Configuration.timeout = 8_000;
+    Configuration.reportsFolder = "target/screenshots";
+    Configuration.screenshots = true;
+    Configuration.captureJavascriptErrors = true;
+    Configuration.savePageSource = true;
   }
 
 }
index a0a99f060c6f6417efb70742798b82614ba7fa87..196df815e82f51043b76b938c2f22811affb6fd2 100644 (file)
 package util.selenium;
 
 import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.firefox.FirefoxOptions;
 import org.openqa.selenium.firefox.FirefoxProfile;
 
 public enum Browser {
   FIREFOX;
 
-  private final ThreadLocal<SeleniumDriver> perThreadDriver = new ThreadLocal<SeleniumDriver>() {
-    @Override
-    protected SeleniumDriver initialValue() {
-      FirefoxProfile profile = new FirefoxProfile();
-      profile.setPreference("browser.startup.homepage", "about:blank");
-      profile.setPreference("startup.homepage_welcome_url", "about:blank");
-      profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");
-      profile.setPreference("nglayout.initialpaint.delay", 0);
-      profile.setPreference("extensions.checkCompatibility", false);
-      profile.setPreference("browser.cache.use_new_backend", 1);
-      profile.setPreference("geo.enabled", false);
-      profile.setPreference("layout.spellcheckDefault", 0);
-      return ThreadSafeDriver.makeThreadSafe(new FirefoxDriver(profile));
-    }
-  };
+  private final ThreadLocal<SeleniumDriver> perThreadDriver = ThreadLocal.withInitial(() -> {
+    FirefoxProfile profile = new FirefoxProfile();
+    profile.setPreference("browser.startup.homepage", "about:blank");
+    profile.setPreference("startup.homepage_welcome_url", "about:blank");
+    profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");
+    profile.setPreference("nglayout.initialpaint.delay", 0);
+    profile.setPreference("extensions.checkCompatibility", false);
+    profile.setPreference("browser.cache.use_new_backend", 1);
+    profile.setPreference("geo.enabled", false);
+    profile.setPreference("layout.spellcheckDefault", 0);
+    FirefoxOptions options = new FirefoxOptions().setProfile(profile).setLegacy(true);
+    FirefoxDriver driver = new FirefoxDriver(options);
+    return ThreadSafeDriver.makeThreadSafe(driver);
+  });
 
   public SeleniumDriver getDriverForThread() {
     return perThreadDriver.get();
index 6152139f9d5d47880f6d9a4a726783f7d413d989..f7b84ad9f739f61d48933d3a47d16063207d2158 100644 (file)
 </tr>
 </thead>
 <tbody>
+<tr>
+       <td>open</td>
+       <td>/sessions/logout</td>
+       <td></td>
+</tr>
 <tr>
        <td>open</td>
        <td>/sessions/login</td>
index e86a26767cee04561ef2170055ba51eccff2b5f6..78076b21a59ead4dbe87a2a3ec07fd384b12a95f 100644 (file)
       <artifactId>assertj-core</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <!-- required for selenide -->
+      <version>21.0</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>com.codeborne</groupId>
       <artifactId>selenide</artifactId>
-      <version>3.7</version>
+      <version>4.4.3</version>
       <scope>test</scope>
     </dependency>
   </dependencies>