Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.6k
Getting Started with Hub and Nodes
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.
This option can be used for a single host scenario (hub and nodes running in a single machine), but it is not recommended for longer term usage since this is a docker legacy feature. It could serve you as an option for a proof of concept, and for simplicity it is used in the examples shown from now on. To use the images without --link please check this section.
$ 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-firefox # 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.
importorg.openqa.selenium.remote.RemoteWebDriver; importorg.openqa.selenium.remote.DesiredCapabilities; publicclassMyTest{CapabilitieschromeCapabilities = DesiredCapabilities.chrome(); CapabilitiesfirefoxCapabilities = DesiredCapabilities.firefox(); publicstaticvoidmain(){WebDriverchrome = newRemoteWebDriver(newURL("http://localhost:4444/wd/hub"), chromeCapabilities); WebDriverfirefox = newRemoteWebDriver(newURL("http://localhost:4444/wd/hub"), firefoxCapabilities); // run against chromechrome.get("https://www.google.com"); System.out.println(chrome.getTitle()); // run against firefoxfirefox.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')putschrome.titlefirefox.get('http://google.com')putsfirefox.titlechrome.quitfirefox.quitfromseleniumimportwebdriverfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitieschrome=webdriver.Remote( command_executor='http://localhost:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME) firefox=webdriver.Remote( command_executor='http://localhost:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX) chrome.get('https://www.google.com') print(chrome.title) firefox.get('https://www.google.com') print(firefox.title) chrome.quit() firefox.quit()/*** Refer: [here](https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/example/google_search_test.js)*/const{Builder, By, until}=require('selenium-webdriver');consttest=require('../testing');test.describe('Google Search',function(){letdriver;test.before(function*(){driver=yieldnewBuilder().forBrowser('firefox').usingServer('http://localhost:4444/wd/hub').build();});test.it('works with generators',function*(){yielddriver.get('http://www.google.com/ncr');yielddriver.findElement(By.name('q')).sendKeys('webdriver');yielddriver.findElement(By.name('btnG')).click();yielddriver.wait(until.titleIs('webdriver - Google Search'),1000);});test.after(()=>driver.quit());});