Skip to content

Instantly share code, notes, and snippets.

@JAffleck
Last active December 14, 2018 17:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JAffleck/305af03d147d9438899e82bb9711d65a to your computer and use it in GitHub Desktop.
Save JAffleck/305af03d147d9438899e82bb9711d65a to your computer and use it in GitHub Desktop.
Running Webdriver tests in VirtualBox VM in Microsoft Edge in Selenium Grid 3

// This doc assumes you have a basic understanding of authoring/running WebDriver tests
// Tested on 11/1/2017 in the following environment
ChromeDriver 2.33,
EdgeDriver Release 16299,
Selenium 3.40.0,
Java: jdk1.8.0_131,
Windows 7 Host

download VirtualBox to your computer
download and install VM loaded with Edge
set enviroment variable in VM for JDK_HOME.
download edgeDriver and
download chromeDriver into %USER_PROFILE%\Desktop\GridFiles
download Java JRE onto VM computer
Copy StartNode.bat,StartHub.bat,Node.json, and [using Oxford comma because reasons] Hub.json into %USER_PROFILE%\Desktop\GridFiles on VM
VM -> Machine > Settings > Network > Attached To: Bridged Adapter
Also you will need to Search for Windows Defender Firewall and turn it off.
In Windows Explorer Nav to %USER_PROFILE%\Desktop\GridFiles
Run StartHub.bat
Run StartHub.bat
If either of these closes immediately, you'll want to open a command prompt: and
cd %USER_PROFILE%\Desktop\GridFiles
Rerun the failed batch file:
StartHub.bat

Normally this is in `C:\Progam Files\Java\jre1.X.0_XX' (replace X's with the numbers from your version)
// Note JDK version on Host Machine and JRE on VM must be >= 1.8
Install Intellij Idea to Host i.e. not in VM
Run the test file in Intellij. Note: You will need to get the IP of the VM with

Add the IP_ADDRESS to TestEdgeFT, this is obtained by ipconfig from a command prompt.
(Also you should be able to ping the VM from the host)

{
"port": 4444,
"newSessionWaitTimeout": -1,
"servlets" : [],
"withoutServlets": [],
"custom": {},
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"cleanUpCycle": 5000,
"role": "hub",
"hubHost": "http://localhost:4444",
"debug": false,
"browserTimeout": 0,
"timeout": 1800
}
{
"capabilities":
[
{
"browserName": "MicrosoftEdge",
"maxInstances": 1,
"platform": "WINDOWS",
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 1,
"platform": "WINDOWS",
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
@title selenium-hub
@set GRIDFILES=%USERPROFILE%\Desktop\GridFiles\
@set JSONFILE="%GRIDFILES%Hub.json"
@set JARFILE="%GRIDFILES%selenium-server-standalone-3.4.0.jar"
java -jar %JARFILE% -role hub -hubConfig %JSONFILE%
@title SeleniumNode
@set GRIDFILES=%USERPROFILE%\Desktop\GridFiles\
@set EDGEDRIVER="%GRIDFILES%MicrosoftWebDriver.exe"
@set JARFILE="selenium-server-standalone-3.4.0.jar"
@set JSONFILE="%GRIDFILES%Node.json"
java -Dwebdriver.edge.driver=%EDGEDRIVER% -jar %JARFILE% -role node -nodeConfig %JSONFILE%
package com.bomb.yourcompany;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author james.affleck
*/
public class TestEdgeFT {
private String IP_ADDRESS; //obatined using ipconfig on VirtualBox VM with Edge Installed
private static WebDriver getDriver(DesiredCapabilities caps) {
URL hub;
try {
hub = new URL("http://" + IP_ADDRESS +":4444/wd/hub");
} catch (MalformedURLException e) {
throw new RuntimeException("Bad hub URL");
}
return new RemoteWebDriver(hub, caps);
}
private static WebDriver getEdgeDriver() {
return getDriver(DesiredCapabilities.edge());
}
private static WebDriver getChromeDriver() {
DesiredCapabilities caps = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments(Arrays.asList(
"start-maximized",
"no-default-browser-check",
"disable-save-password-bubble",
"disable-infobars",
"disable-extensions",
"--disable-extensions-file-access-check"
));
Map<String, Object> prefs = new HashMap<>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
caps.setCapability(ChromeOptions.CAPABILITY, options);
return getDriver(caps);
}
public static void main(String[] args) {
WebDriver driver = getEdgeDriver();
// WebDriver driver = getChromeDriver();
driver.get("https://www.wikipedia.org");
System.out.println("U R HERE");
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment