Skip to content

Commit

Permalink
Addition of driver for Edge and upgrade to Seleniuṁ 4.7.2 (undera#25)
Browse files Browse the repository at this point in the history
* Upgrade of dependencies.
Removal of deprecated Phantomjs.
Removal of deprecated code.
Addition of "SuppressWarnings" tags where needed. To de resolved at a later stage.

* Adding IE capabilities for RemoteWebDriver.

* Upgrade of function call.

* Addition of field in the UI to set the path to the Firefox Gecko driver.

* Wiki update.

* Addition of input field for msegde.exe

* Clean-ups and finalisations.

* Addition of IE11 in MsEdge for Remote execution.

* Integrating changes from Shinu on Aug 26, 2019.

* Merging of thefuckingcode changes from Apr 17, 2021.

* Setting of default value of path to msedge.exe

* Update of Chrome tests to JDK 17.

* Update of Firefox tests to JDK 17.

* Upgrade of HTMLUntit tests to JDK 17.

* Update of InternetExplorer tests to JDK 17.

* Update of RemoteDriver tests to JDK 17.

* Update of WebDriver tests to JDK 17.

* Formatting fixes.

* Formatting fixes 2.

* Formatting fixes #3.

* Addition of Geckodriver v0.31 for Firefox tests.

* Usage of GeckoDriver default service for unit tests instead of real Geckodriver.exe.

* Update to Selenium 4.5

* Ui fix.

* Addition of geckodriver to travis CI for the firefox tests

* Matching Continous Integration test conditions.

* Setting IE's Protected Mode to "off" to allow IE to start in all environments.

* Removaĺ of path to Edge as from IEDriver v4.5.0, the driver will
 automatically locate Edge on the system.

* Ui Refactor 1

* Update to Seleniuṁ 4.6.0

* UI Refactor

* Adding of new wiki page for direct browseŕ testing.

* Updating wiki pages for new UI.

* Tests update 1.

* Update of Chrome and IE tests.

* Pom update.

* Imporţclean-ups.

* Update of Readme.md.

* Fix of broken wiki links.

* Fix of broken link #2.

* Take #3

* Code format

* Code format #2

* Syntax highlight.

* Initial Browser URL now in UI and not hard coded.

* Test fixes.

* Upgrade to Selenium 4.7.2 and addition of driver for Edge.

* Update of tests.

* Removing "ignoring zoom levels" in IE as it is no longer required from Seleniuṁ 4.7.0.
  • Loading branch information
rbourga authored Dec 18, 2022
1 parent 16f50ce commit 3a716d5
Show file tree
Hide file tree
Showing 22 changed files with 770 additions and 110 deletions.
14 changes: 11 additions & 3 deletions DirectDriverConfig.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ These configurations are suited when you want to test desktop browsers on the sa

For an overview of performing client side performance testing, refer to the [[WebDriverTutorial.wiki|Web Driver Tutorial]].

At the time of writing, four types of browsers are supported by JMeter Web Driver plugin:
At the time of writing, five types of browsers are supported by JMeter Web Driver plugin:
* Chrome (Chrome Driver Config);
* Edge (Edge Driver Config);
* Firefox (Firefox Driver Config);
* Internet Explorer (InternetExplorer Driver Config);
* HtmlUnit (HtmlUnit Driver Config), a GUI-Less browser;
For Internet Explorer, the system will start Edge in "IE Mode" as Internet Explorer is now deprecated as of June 2022. Upon start-up, IE will load "http://wwww.bing.com". So ensure the browser can access this url otherwise the driver will fail.
For Internet Explorer, the system will start Edge in "IE Mode" as Internet Explorer is now deprecated as of June 2022.

HtmlUnit is a good compromise between speed of execution and the CPU usage per thread while maintaining Selenium API.
The main drawback is that there is no screen so it's more difficult to understand the cause of problems and also that the javascript engine is not powerful as browsers such Firefox or Chrome.
Expand Down Expand Up @@ -40,6 +41,11 @@ In the Options tab of Chrome for instance, you can specify the location of a Chr

You can find more information on the Chrome options presented in this tab at [https://chromedriver.chromium.org/capabilities Capabilities & ChromeOptions].

=== Edge ===
In the Options tab of Edge, you can specify the path to a fixed Edge version to use in case you want to test a different version of the default one on your PC. Leave this field blank if you are happy to test the Edge that is defined in your path variable.

You can find more information on the Edge options presented in this tab at [https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options Capabilities & EdgeOptions]

=== Firefox ===
In the Options tab of Firefox, you can override the user agent of Firefox. To do so, check the 'Override User Agent' checkbox and then paste in the user agent string to use. The UserAgentString.com site has an [https://www.useragentstring.com/pages/useragentstring.php extensive list of user agent strings].

Expand All @@ -48,7 +54,9 @@ There is also an option to enable NTLM.
You can find more information on the Firefox options presented in this tab at [https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions firefoxOptions].

=== Internet Explorer ===
You can find more information on the IE options presented in this tab at [https://www.selenium.dev/documentation/webdriver/browsers/internet_explorer/ IE specific functionality]
In this tab, specify the url IE will load on start-up. By default, it will go to "https://wwww.bing.com".

You can find information on the other options presented in this tab at [https://www.selenium.dev/documentation/webdriver/browsers/internet_explorer/ IE specific functionality]

== Proxy Tab ==
The default configuration (Use system proxy) is suitable for most. However, if you are in a corporate environment and a browser fails to connect to a URL, this is most likely because the environmemt needs a proxy to be accessed.
Expand Down
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-webdriver</artifactId>
<version>4.6.0</version>
<version>4.7.2</version>
<packaging>jar</packaging>

<name>WebDriver/Selenium</name>
Expand Down Expand Up @@ -34,7 +34,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<selenium.version>4.6.0</selenium.version>
<selenium.version>4.7.2</selenium.version>
</properties>

<build>
Expand Down Expand Up @@ -136,7 +136,7 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>${selenium.version}</version>
<version>4.7.0</version>
</dependency>

<!-- begin need this libraries for HtmlUnitDriver -->
Expand All @@ -148,17 +148,17 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.15</version>
<version>4.4.16</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.13</version>
<version>4.5.14</version>
</dependency>
<!--
<dependency>
Expand Down Expand Up @@ -193,5 +193,10 @@
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-edge-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.googlecode.jmeter.plugins.webdriver.config;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.edge.EdgeOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EdgeDriverConfig extends WebDriverConfig<EdgeDriver> {

private static final long serialVersionUID = 100L;
private static final Logger LOGGER = LoggerFactory.getLogger(EdgeDriverConfig.class);

private static final Map<String, EdgeDriverService> services = new ConcurrentHashMap<String, EdgeDriverService>();
Map<String, EdgeDriverService> getServices() {
return services;
}

@Override
protected EdgeDriver createBrowser() {
final EdgeDriverService service = getThreadService();
EdgeOptions options = createEdgeOptions();
return service != null ? new EdgeDriver(service, options) : null;
}

@Override
public void quitBrowser(final EdgeDriver browser) {
super.quitBrowser(browser);
final EdgeDriverService service = services.remove(currentThreadName());
if (service != null && service.isRunning()) {
service.stop();
}
}

private EdgeDriverService getThreadService() {
EdgeDriverService service = services.get(currentThreadName());
if (service != null) {
return service;
}
try {
service = new EdgeDriverService.Builder().usingDriverExecutable(new File(getDriverPath())).build();
service.start();
services.put(currentThreadName(), service);
} catch (IOException e) {
LOGGER.error("Failed to start edge service");
service = null;
}
return service;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ private InternetExplorerDriverService getThreadService() {
return service;
}
try {
/*
* For debugging purposes
* System.setProperty("webdriver.ie.driver.loglevel", "DEBUG");
* System.setProperty("webdriver.ie.driver.logfile", "C:\\DEV\\WebDriverIeDriver.log");
*/
service = new InternetExplorerDriverService.Builder().usingDriverExecutable(new File(getDriverPath())).build();
service.start();
services.put(currentThreadName(), service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum RemoteCapability {
CHROME,
EDGE,
FIREFOX,
INTERNET_EXPLORER
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class RemoteDriverConfig extends WebDriverConfig<RemoteWebDriver> {
@Override
protected RemoteWebDriver createBrowser() {
try {
// We pass the browser option instance to the remote so it can determine which
// browser to use
RemoteWebDriver driver = new RemoteWebDriver(new URL(getSeleniumGridUrl()), createCapabilities());
if (isLocalFileDectedor()) {
driver.setFileDetector(new LocalFileDetector());
Expand All @@ -36,11 +34,15 @@ protected RemoteWebDriver createBrowser() {
}

Capabilities createCapabilities() {
// We pass the browser option instance to the remote so it knows which browser to use
AbstractDriverOptions<?> caps = null;
switch (getCapability()) {
case CHROME:
caps = createChromeOptions();
break;
case EDGE:
caps = createEdgeOptions();
break;
case FIREFOX:
caps = createFirefoxOptions();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerOptions;
Expand Down Expand Up @@ -57,8 +58,12 @@ public abstract class WebDriverConfig<T extends WebDriver> extends ConfigTestEle
private static final String DEV_MODE = "WebDriverConfig.dev_mode";

// Constants for Chrome
private static final String ADDITIONAL_ARGS = "ChromeDriverConfig.additional_args";
private static final String BINARY_PATH = "ChromeDriverConfig.binary_path";
private static final String CHROME_ADDITIONAL_ARGS = "ChromeDriverConfig.additional_args";
private static final String CHROME_BINARY_PATH = "ChromeDriverConfig.binary_path";

// Constants for Edge
private static final String EDGE_ADDITIONAL_ARGS = "EdgeDriverConfig.additional_args";
private static final String EDGE_BINARY_PATH = "EdgeDriverConfig.binary_path";

// Constants for Firefox
private static final String GENERAL_USERAGENT_OVERRIDE = "FirefoxDriverConfig.general.useragent.override";
Expand All @@ -72,6 +77,7 @@ public abstract class WebDriverConfig<T extends WebDriver> extends ConfigTestEle
private static final String ENSURE_CLEAN_SESSION = "InternetExplorerDriverConfig.ensure_clean_session";
private static final String IGNORE_PROTECTED_MODE = "InternetExplorerDriverConfig.ignore_protected_mode";
private static final String SILENT = "InternetExplorerDriverConfig.silent";
private static final String INITIAL_IE_URL = "InternetExplorerDriverConfig.initial_browser_url";

// Constants for Proxy
private static final String PROXY_PAC_URL = "WebDriverConfig.proxy_pac_url";
Expand Down Expand Up @@ -269,13 +275,13 @@ protected ChromeOptions createChromeOptions() {
}
options.setHeadless(isHeadless());

String additionalArgs = trimmed(getAdditionalArgs());
String additionalArgs = trimmed(getChromeAdditionalArgs());
if (null != additionalArgs && !additionalArgs.isEmpty()) {
options.addArguments(additionalArgs.split("\\s+"));
}

// Starting browser in a specified location
String binaryPath = trimmed(getBinaryPath());
String binaryPath = trimmed(getChromeBinaryPath());
if (null != binaryPath && !binaryPath.isEmpty()) {
options.setBinary(binaryPath);
}
Expand All @@ -286,18 +292,40 @@ protected ChromeOptions createChromeOptions() {
return options;
}

protected FirefoxOptions createFirefoxOptions() {
FirefoxOptions options = new FirefoxOptions();
protected EdgeOptions createEdgeOptions() {
EdgeOptions options = new EdgeOptions();

// Custom Firefox capabilities
// Custom Edge capabilities
// Arguments
if (isBrowserMaximized()) {
options.addArguments("--start-maximized");
}
options.setHeadless(isHeadless());
options.setProfile(createProfile());

String additionalArgs = trimmed(getAdditionalArgs());
String additionalArgs = trimmed(getEdgeAdditionalArgs());
if (null != additionalArgs && !additionalArgs.isEmpty()) {
options.addArguments(additionalArgs.split("\\s+"));
}

// Starting browser in a specified location
String binaryPath = trimmed(getEdgeBinaryPath());
if (null != binaryPath && !binaryPath.isEmpty()) {
options.setBinary(binaryPath);
}

// Capabilities shared by all browsers
setSharedCaps(options);

return options;
}

protected FirefoxOptions createFirefoxOptions() {
FirefoxOptions options = new FirefoxOptions();

// Custom Firefox capabilities
options.setHeadless(isHeadless());
options.setProfile(createProfile());

// Capabilities shared by all browsers
setSharedCaps(options);

Expand Down Expand Up @@ -368,9 +396,7 @@ InternetExplorerOptions createIEOptions() {
// Settings to launch Microsoft Edge in IE mode
// As of v4.5.0, IE Driver will automatically locate Edge on the system.
options.attachToEdgeChrome();
options.ignoreZoomSettings(); // always set otherwise driver may throw an exception
// Set an initial valid page otherwise IeDriver hangs on page load...
options.withInitialBrowserUrl("https://www.bing.com/");
options.withInitialBrowserUrl(getInitialIeUrl());

// Other options
options.waitForUploadDialogUpTo(Duration.ofMillis(getFileUploadDialogTimeout()));
Expand All @@ -396,11 +422,18 @@ public void setSharedCaps(AbstractDriverOptions<?> caps) {
caps.setProxy(createProxy());
}

public String getBinaryPath() {
return getPropertyAsString(BINARY_PATH);
public String getChromeBinaryPath() {
return getPropertyAsString(CHROME_BINARY_PATH);
}
public void setBinaryPath(String binaryPath) {
setProperty(BINARY_PATH, binaryPath);
public void setChromeBinaryPath(String binaryPath) {
setProperty(CHROME_BINARY_PATH, binaryPath);
}

public String getEdgeBinaryPath() {
return getPropertyAsString(EDGE_BINARY_PATH);
}
public void setEdgeBinaryPath(String binaryPath) {
setProperty(EDGE_BINARY_PATH, binaryPath);
}

public String getDriverPath() {
Expand All @@ -410,11 +443,18 @@ public void setDriverPath(String path) {
setProperty(DRIVER_PATH, path);
}

public String getAdditionalArgs() {
return getPropertyAsString(ADDITIONAL_ARGS);
public String getChromeAdditionalArgs() {
return getPropertyAsString(CHROME_ADDITIONAL_ARGS);
}
public void setAdditionalArgs(String additionalArgs) {
setProperty(ADDITIONAL_ARGS, additionalArgs);
public void setChromeAdditionalArgs(String additionalArgs) {
setProperty(CHROME_ADDITIONAL_ARGS, additionalArgs);
}

public String getEdgeAdditionalArgs() {
return getPropertyAsString(EDGE_ADDITIONAL_ARGS);
}
public void setEdgeAdditionalArgs(String additionalArgs) {
setProperty(EDGE_ADDITIONAL_ARGS, additionalArgs);
}

public String getFtpHost() {
Expand Down Expand Up @@ -601,6 +641,13 @@ public void setSilent(boolean state) {
setProperty(SILENT, state);
}

public String getInitialIeUrl() {
return getPropertyAsString(INITIAL_IE_URL);
}
public void setInitialIeUrl(String webUrl) {
setProperty(INITIAL_IE_URL, webUrl);
}

private String trimmed(String str) {
return null == str ? null : str.trim();
}
Expand Down
Loading

0 comments on commit 3a716d5

Please sign in to comment.