aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-06-13 14:43:05 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-06-17 17:28:21 +0200
commit8edf9e906a56163c23d34230bcab1b8c9f87f849 (patch)
tree35ce706cd049e5a9c98c5e81585d6d49f05fc18b
parent7404d8a4583948e6bf8e69f26211af8513b79068 (diff)
downloadsonarqube-8edf9e906a56163c23d34230bcab1b8c9f87f849.tar.gz
sonarqube-8edf9e906a56163c23d34230bcab1b8c9f87f849.zip
Support recent browsers in Selenese HTML tests
-rw-r--r--it/it-tests/src/test/java/pageobjects/Navigation.java3
-rw-r--r--it/it-tests/src/test/java/pageobjects/SelenideConfig.java13
-rw-r--r--it/it-tests/src/test/java/util/selenium/Browser.java47
-rw-r--r--it/it-tests/src/test/java/util/selenium/LazyDomElement.java9
-rw-r--r--it/it-tests/src/test/java/util/selenium/SeleneseRunner.java13
-rw-r--r--it/it-tests/src/test/java/util/selenium/SeleniumDriver.java23
-rw-r--r--it/it-tests/src/test/java/util/selenium/ThreadSafeDriver.java80
7 files changed, 23 insertions, 165 deletions
diff --git a/it/it-tests/src/test/java/pageobjects/Navigation.java b/it/it-tests/src/test/java/pageobjects/Navigation.java
index 2ff9f7733a7..5123f5f91a6 100644
--- a/it/it-tests/src/test/java/pageobjects/Navigation.java
+++ b/it/it-tests/src/test/java/pageobjects/Navigation.java
@@ -22,7 +22,6 @@ 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 java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@@ -48,7 +47,7 @@ public class Navigation extends ExternalResource {
@Override
protected void before() throws Throwable {
- WebDriverRunner.getWebDriver().manage().deleteAllCookies();
+ SelenideConfig.getWebDriver().manage().deleteAllCookies();
openHomepage();
}
diff --git a/it/it-tests/src/test/java/pageobjects/SelenideConfig.java b/it/it-tests/src/test/java/pageobjects/SelenideConfig.java
index 6bc67c3644d..e69bfdc7739 100644
--- a/it/it-tests/src/test/java/pageobjects/SelenideConfig.java
+++ b/it/it-tests/src/test/java/pageobjects/SelenideConfig.java
@@ -20,16 +20,18 @@
package pageobjects;
import com.codeborne.selenide.Configuration;
+import com.codeborne.selenide.WebDriverRunner;
import com.sonar.orchestrator.Orchestrator;
import java.util.stream.Collectors;
+import org.openqa.selenium.WebDriver;
import static java.util.Arrays.stream;
-class SelenideConfig {
+public class SelenideConfig {
private enum Browser {
firefox("(v46 and lower)"),
- marionette("(recent Firefox)"),
+ marionette("(recent Firefox, require Geckodriver)"),
chrome("(require Chromedriver)"),
phantomjs("(headless)");
@@ -49,7 +51,7 @@ class SelenideConfig {
}
}
- public static void configure(Orchestrator orchestrator) {
+ public static WebDriver configure(Orchestrator orchestrator) {
String browserKey = orchestrator.getConfiguration().getString("orchestrator.browser", Browser.firefox.name());
Browser browser = Browser.of(browserKey);
Configuration.browser = browser.name();
@@ -59,6 +61,11 @@ class SelenideConfig {
Configuration.screenshots = true;
Configuration.captureJavascriptErrors = true;
Configuration.savePageSource = true;
+ Configuration.browserSize = "1280x1024";
+ return getWebDriver();
}
+ static WebDriver getWebDriver() {
+ return WebDriverRunner.getWebDriver();
+ }
}
diff --git a/it/it-tests/src/test/java/util/selenium/Browser.java b/it/it-tests/src/test/java/util/selenium/Browser.java
deleted file mode 100644
index 196df815e82..00000000000
--- a/it/it-tests/src/test/java/util/selenium/Browser.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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 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 = 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();
- }
-}
diff --git a/it/it-tests/src/test/java/util/selenium/LazyDomElement.java b/it/it-tests/src/test/java/util/selenium/LazyDomElement.java
index bdf4cb76be8..27c5199f820 100644
--- a/it/it-tests/src/test/java/util/selenium/LazyDomElement.java
+++ b/it/it-tests/src/test/java/util/selenium/LazyDomElement.java
@@ -29,25 +29,26 @@ import java.util.NoSuchElementException;
import javax.annotation.Nullable;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
class LazyDomElement {
- private final SeleniumDriver driver;
+ private final WebDriver driver;
private final By selector;
private final ElementFilter filter;
private final Retry retry;
- LazyDomElement(SeleniumDriver driver, By selector) {
+ LazyDomElement(WebDriver driver, By selector) {
this(driver, selector, Retry._30_SECONDS);
}
- LazyDomElement(SeleniumDriver driver, By selector, Retry retry) {
+ LazyDomElement(WebDriver driver, By selector, Retry retry) {
this(driver, selector, ElementFilter.any(), retry);
}
- private LazyDomElement(SeleniumDriver driver, By selector, ElementFilter filter, Retry retry) {
+ private LazyDomElement(WebDriver driver, By selector, ElementFilter filter, Retry retry) {
this.driver = driver;
this.selector = selector;
this.filter = filter;
diff --git a/it/it-tests/src/test/java/util/selenium/SeleneseRunner.java b/it/it-tests/src/test/java/util/selenium/SeleneseRunner.java
index 01e6b690355..cefc5c6ef09 100644
--- a/it/it-tests/src/test/java/util/selenium/SeleneseRunner.java
+++ b/it/it-tests/src/test/java/util/selenium/SeleneseRunner.java
@@ -32,12 +32,14 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.openqa.selenium.By;
-import org.openqa.selenium.Dimension;
+import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NotFoundException;
+import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
+import pageobjects.SelenideConfig;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
@@ -49,15 +51,14 @@ class SeleneseRunner {
private Map<String, String> variables;
private String baseUrl;
- private SeleniumDriver driver;
+ private WebDriver driver;
void runOn(Selenese selenese, Orchestrator orchestrator) {
this.variables = new HashMap<>();
this.baseUrl = orchestrator.getServer().getUrl();
- this.driver = Browser.FIREFOX.getDriverForThread();
+ this.driver = SelenideConfig.configure(orchestrator);
driver.manage().deleteAllCookies();
- driver.manage().window().setSize(new Dimension(1280, 1024));
for (File file : selenese.getHtmlTests()) {
System.out.println();
@@ -82,7 +83,7 @@ class SeleneseRunner {
}
}
- private static void analyzeLog(SeleniumDriver driver) {
+ private static void analyzeLog(WebDriver driver) {
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
@@ -293,7 +294,7 @@ class SeleneseRunner {
_30_SECONDS.execute(new Runnable() {
@Override
public void run() {
- Object result = driver.executeScript("return " + expression);
+ Object result = ((JavascriptExecutor) driver).executeScript("return " + expression);
if (result == null) {
throw new NotFoundException(expression);
}
diff --git a/it/it-tests/src/test/java/util/selenium/SeleniumDriver.java b/it/it-tests/src/test/java/util/selenium/SeleniumDriver.java
deleted file mode 100644
index 48414111600..00000000000
--- a/it/it-tests/src/test/java/util/selenium/SeleniumDriver.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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 util.selenium;
-
-public interface SeleniumDriver extends org.openqa.selenium.WebDriver, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.interactions.HasInputDevices, org.openqa.selenium.HasCapabilities, org.openqa.selenium.TakesScreenshot {
-}
diff --git a/it/it-tests/src/test/java/util/selenium/ThreadSafeDriver.java b/it/it-tests/src/test/java/util/selenium/ThreadSafeDriver.java
deleted file mode 100644
index a0520fd822d..00000000000
--- a/it/it-tests/src/test/java/util/selenium/ThreadSafeDriver.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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 util.selenium;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import org.openqa.selenium.remote.RemoteWebDriver;
-import org.openqa.selenium.remote.UnreachableBrowserException;
-
-class ThreadSafeDriver {
- private ThreadSafeDriver() {
- // Static class
- }
-
- static SeleniumDriver makeThreadSafe(final RemoteWebDriver driver) {
- Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- driver.quit();
- } catch (UnreachableBrowserException e) {
- // Ignore. The browser was killed properly
- }
- }
- }));
-
- return (SeleniumDriver) Proxy.newProxyInstance(
- Thread.currentThread().getContextClassLoader(),
- findInterfaces(driver),
- new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getName().equals("quit")) {
- return null; // We don't want anybody to quit() our (per thread) driver
- }
-
- try {
- return method.invoke(driver, args);
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
- });
- }
-
- private static Class[] findInterfaces(Object driver) {
- Set<Class<?>> interfaces = new LinkedHashSet<>();
-
- interfaces.add(SeleniumDriver.class);
-
- for (Class<?> parent = driver.getClass(); parent != null; ) {
- Collections.addAll(interfaces, parent.getInterfaces());
- parent = parent.getSuperclass();
- }
-
- return interfaces.toArray(new Class[interfaces.size()]);
- }
-}