Reputation: 185
H community, I am trying to set up the Selenium Grid on EC2 server, and below are the steps I took so far.
1.start the hub on port 4044
java -jar /ebst/wrangler/upla/bin/selenium-server-standalone-3.141.59.jar -role hub -port 4044
2.Register a node on 4045
java -Dwebdriver.chrome.driver="~/chromedriver" -jar ~/selenium-server-standalone-3.141.59.jar -role node -hub http://hubURL:4044/grid/register -port 4045
3.Start Webdriver in my Java code
import cucumber.api.java.Before;
import org.openqa.selenium.Platform;
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;
public class Test {
WebDriver driver;
@Before
public void setup() throws MalformedURLException {
String nodeURL = "http://hubURL:4044/wd/hub";
System.out.println("setting up");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
desiredCapabilities.setBrowserName("chrome");
desiredCapabilities.setPlatform(Platform.LINUX);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments(
"--verbose",
"--headless",
"--disable-web-security",
"--ignore-certificate-errors",
"--allow-running-insecure-content",
"--allow-insecure-localhost",
"--no-sandbox",
"--disable-gpu");
chromeOptions.merge(desiredCapabilities);
driver = new RemoteWebDriver(new URL(nodeURL), chromeOptions);
System.out.println("setting up done");
}
}
On the console, I got the following error due to timeout.
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 3.10.0-1062.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: 'ip-10-160-169-203.syd.non.c1.macquarie.com', ip: '10.160.169.203', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1062.el7.x86_64', java.version: '1.8.0_181'
Driver info: driver.version: unknown Command duration or timeout: 523 milliseconds
As I navigate back to the node server, this is the message displayed.
22:44:05.604 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 3459
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1567550645.675][SEVERE]: bind() failed: Cannot assign requested address (99)
22:44:05.988 INFO [ActiveSessionFactory.apply] - Capabilities are: { "browserName": "chrome", "goog:chromeOptions": { "args": [ "--verbose", "--headless", "--disable-web-security", "--ignore-certificate-errors", "--allow-running-insecure-content", "--allow-insecure-localhost", "--no-sandbox", "--port:4040", "--disable-gpu" ], "extensions": [ ] }, "platform": "LINUX", "version": "" }
I understand the error occurs because within our company, only certain ports were available, and the ChromeDriver is started on random port every time. In order to specify the port this ChromeDriver starts on every time, I tried all kinds of specification for my ChromeOptions and RemoteWebDriver in the Java code, but in vain.
Did anyone else encounter this issue too? If so could you please give me advice on what to do? Or more broadly, is this the correct way of starting the selenium server on EC2? Any help will be highly appreciated!
Upvotes: 1
Views: 10895
Reputation: 443
Try using this to launch chromedriver:
ChromeOptions options = new ChromeOptions();
options.addArguments("--whitelisted-ips");
ChromeDriver driver = new ChromeDriver(options);
Upvotes: 0
Reputation: 5905
Try to pass -Dwebdriver.chrome.whitelistedIps=
into chromedriver
like
java -Dwebdriver.chrome.driver="~/chromedriver" -Dwebdriver.chrome.whitelistedIps= -jar ~/selenium-server-standalone-3.141.59.jar -role node -hub http://hubURL:4044/grid/register -port 4045
Upvotes: 0