-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Getting Started with Hub and Nodes
Dj edited this page Apr 13, 2017
·
6 revisions
This is a step-by-step introduction to using the official Selenium Docker images using a basic hub/node configuration.
$ docker pull selenium/hub selenium/node-chrome selenium/node-firefox
This will pull from hub.docker.com, the three official images. Note: when you omit a version at the end, it will default to "latest" tag. To specify a version, simply add
:<version>
at the end. E.g:selenium/hub:3.3.1
Now that we have the images pulled down, let's run them.
$ docker run -p 4444:4444 --name selenium-hub selenium/hub
# Run the hub, forwarding the "4444" port from the docker container to the host machine.
$ docker run --link selenium-hub:hub selenium/node-chrome
# Run the chrome node and link it to the `--name` we specified for the hub.
$ docker run --link selenium-hub:hub selenium/node-chrome
# Run the firefox node and link it to the `--name` we specified for the hub.
Note: Please consult the official documentation if you are having issues with the following code.
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MyTest {
Capabilities chromeCapabilities = DesiredCapabilities.chrome();
Capabilities firefoxCapabilities = DesiredCapabilities.firefox();
public static void main() {
WebDriver chrome = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), chromeCapabilities);
WebDriver firefox = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), firefoxCapabilities);
// run against chrome
chrome.get("https://www.google.com");
System.out.println(chrome.getTitle());
// run against firefox
firefox.get("https://www.google.com");
System.out.println(firefox.getTitle());
chrome.quit();
firefox.quit();
}
}
require 'selenium-webdriver'
chrome_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome()
firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox()
chrome = Selenium::WebDriver.for(:remote, :url => 'http://localhost:4444/wd/hub', :desired_capabilities => chrome_capabilities)
firefox = Selenium::WebDriver.for(:remote, :url => 'http://localhost:4444/wd/hub', :desired_capabilities => firefox_capabilities)
chrome.get('http://google.com')
puts chrome.title
firefox.get('http://google.com')
puts firefox.title
chrome.quit
firefox.quit