<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>
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();
}
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;
}
}
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();
</tr>
</thead>
<tbody>
+<tr>
+ <td>open</td>
+ <td>/sessions/logout</td>
+ <td></td>
+</tr>
<tr>
<td>open</td>
<td>/sessions/login</td>
<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>