Docker - Selenium Grid Web Demo

  
--------------------------------DOCKER INTALLATION----------------------------------------------
Step 1: We need to install docker
  
Go to the docker offical website https://www.docker.com/
Click on Get started button
Then Download docker as per your OS. I have used macOS for demo purpose
  
After downloading, Just install it.
  
  
Step 2:- Create a free account on docker website
  
Step 3:- Check docker installed or not successfully
  
Open terminal and hit following command
  
docker version
We will get docker info Then hit following command to get complete info of docker
docker info
Then try to verify image
docker run hello-world
Then hit following command to get list of images exist into docker container docker run hello-world Step 4: Start docker application and login in.
Now we are going to create selenium grid docker demo
--------------------------------SELENIUM GRID IMAGES INSTALLATION---------------------------------------------- Step 5: First we need to install all required images Go to the google and search
docker selenium
and open first result or docker selenium url https://github.com/SeleniumHQ/docker-selenium Install following docker dependecies to execute Selenium Grid Open terminal and hit following command one by one Selenium hub
docker pull selenium/hub
Selenium firefox node
docker pull selenium/node-firefox
Selenium chrome node
docker pull selenium/node-chrome
Selenium firefox debug
docker pull selenium/node-firefox-debug
Selenium chrome debug
docker pull selenium/node-chrome-debug
Then check list of images, We will get above mentioned all images in result. Same will get in Docker desktop Application
docker images
--------------------------------START HUB AND NODE--------------------------------------------- Step 6: Now we need to start hub and node to execute script Start hub :
docker run -d -p 4545:4444 --name selenium-hub selenium/hub
Note:- Here we can take any name To check hub is started or not, Open browser and enter
http://localhost:4545/
. We will get hub console Start Node for Firefox
docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug
To check node started or not, Open broweser and check node into hub Start Node for Chrome
docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug
To check node started or not, Open broweser and check node into hub
--------------------------------VNC INSTALLATION TO VIEW NODE CONSOLE ---------------------------------- Step 7: To view firefox and chrome docker console, We need to download vnc and install it https://www.realvnc.com/en/connect/download/viewer/macos/ Start vnc , enter node url 0.0.0.0:55000 chrome will start , here 55000 is assigned to chrome browser node 0.0.0.0:55001 Firefox will start , here 55001 is assigned to firefox browser node
--------------------------------SELENIUM SCRIPT---------------------------------------------- Step 8: We need to create demo automation script to execute on nodes Create selenium script ex. Firefox
import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; public class ffdemo { @Test public void testApp() throws MalformedURLException, InterruptedException { DesiredCapabilities cap= new DesiredCapabilities(); cap.setBrowserName(BrowserType.FIREFOX); WebDriver driver=new RemoteWebDriver(new URL("http://localhost:4545/wd/hub"),cap); driver.get("https://www.google.com/"); driver.findElement(By.name("q")).sendKeys("Autoamtion testing"); Thread.sleep(5000); driver.quit(); } }
ex. Chrome package dockerdemo; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; public class chromedemo { @Test public void testApp() throws MalformedURLException, InterruptedException { DesiredCapabilities cap= new DesiredCapabilities(); cap.setBrowserName(BrowserType.CHROME); WebDriver driver=new RemoteWebDriver(new URL("http://localhost:4545/wd/hub"),cap); driver.get("https://www.google.com/"); driver.findElement(By.name("q")).sendKeys("Autoamtion testing"); Thread.sleep(5000); driver.quit(); } } tetsng.xml for parallel execution How to execute script:- Right click on testng.xml and run as suite
--------------------------------EXECUTE SCRIPT---------------------------------------------- Step 9: Execute script , Execution will start on both console , Firefox ( 0.0.0.0:55001) and chrome ( 0.0.0.0:55000 )
--------------------------------EXECUTION DEMO---------------------------------------------- Execution Demo