Saturday 27 February 2021

Docker and Selenium Grid Set Up for Parallel Test Execution? Cross Browser testing with Grid and Docker? Selenium Grid Integration with Docker



Refer Below Link for Docker Commands used in the set up:
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

TOP 50 Selenium Automation Testing Interview Question:
https://automationreinvented.blogspot.com/2020/11/top-50-interview-questions-on.html

Check Selenium Interview questions from 1 to 10 below:


Check Selenium-SDET-UIAutomation Questions set 11 to 20:
Qus Set - 11 to 20

Check Selenium-SDET-UIAutomation Questions set 21 to 30:



Pre-Requisite:
First we need to install docker in the machine using below link: Docker Installation Step

Lets learn about Docker, Selenium Grid and CrossbrowserTesting ==>

Docker Overview:

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.


To know more about Docker please refer : https://docs.docker.com/

Selenium Grid

Want to run tests in parallel across multiple machines? Then, Grid is for you.

Selenium Grid allows the execution of WebDriver scripts on remote machines by routing commands sent by the client to remote browser instances.

Grid aims to:

  • Provide an easy way to run tests in parallel on multiple machines
  • Allow testing on different browser versions
  • Enable cross platform testing

Interested? Go through the following sections to understand how Grid works, and how to set up your own.

Crossbrowser Testing

Cross Browser testing is a type of non-functional testing that lets you check whether your website works as intended when accessed through: Different Browser-OS combinations i.e., on popular browsers like Firefox, Chrome, Edge, Safari—on any of the popular operating systems like Windows, macOS, iOS and Android.


Lets start with steps to perform cross browser testing with Slenium grid and docker

Step-01:

Download docker in windows :
https://docs.docker.com/docker-for-windows/install/

Step-02:

Go to CMD and type below command:"docker --version"==>

C:\Users\sshukla>docker --version
O/P: Docker version 19.03.8, build afacb8b

Step-03:

Go to below docker hub link and search for images to pull into your local machine:

https://hub.docker.com/search?q=&type=image

Step-04:

Pull all the below three images using docker cmd:

Pull Selenium-hub image using command ~ docker pull selenium/hub
Pull FireFox Debug image using command ~ docker pull selenium/node-firefox-debug
Pull Chrome Debug image using below command ~ docker pull selenium/node-chrome-debug

***********************************************

How to run selenium tests from Jenkins? Maven and Jenkins Integration with Testng-Selenium?Run selenium maven project from command line?

Click Here For Steps with Screenshot

*********************************************** 

Step-05:

check that the images that has been pulled in step-04 is present by using command: docker images

C:\Users\sshukla>docker images

OUTPUT:

REPOSITORY      TAG         IMAGE ID        CREATED         SIZE
selenium/standalone-chrome latest          3adc798b45d8    9 months ago    910MB
selenium/node-firefox-debug   latest          86e57cf1c72c    9 months ago    871MB
selenium/node-chrome-debug latest          845cb7d30dec    9 months ago    941MB
selenium/hub              latest          f476afa5404c    9 months ago    263MB
ubuntu                    latest          ccc6e87d482b    13 months ago   64.2MB
ubuntu                    <none>          775349758637    16 months ago   64.2MB
hello-world    latest        fce289e99eb9    2 years ago     1.84kB


Step:-06

Run the below three commands :

1. docker run -d -p 4446:4444 --name selenium-hub -P selenium/hub

2. docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug

3. docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug


==> Expect below results while running above three commands:


Please execute the first command as mentioned above in the command line:

docker run -d -p 4446:4444 --name selenium-hub -P selenium/hub

The expected output for the executed command will be similar to below:

O/P:3e4bc48fa50f45526e18f635e085caeb3ad548671e8cbcbd5977931a58075193


To confirm that the above command executed and container created use below:


==>C:\Users\sshukla>docker ps


OUTPUT:

CONTAINER ID   IMAGE   COMMAND     CREATED   STATUS   PORTS     NAMES
3e4bc48fa50f   selenium/hub "/opt/bin/entry_poin..."   14 seconds ago Up 11 seconds   0.0.0.0:4446->4444/tcp   selenium-hub


Please run the following command from the command line:

docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug

When you enter the above command in the cmd, you expect a reply as shown below:

O/P: bb839e51b74373c0a39477134658e93e42256ac15340625cb92fb95255538e70

To confirm that the above command executed and container created use below:

==> C:\Users\sshukla>docker ps


OUTPUT:

CONTAINER ID  IMAGE  COMMAND     CREATED  STATUS  PORTS     NAMES
bb839e51b743    selenium/node-chrome-debug   "/opt/bin/entry_poin..."   8 seconds ago   Up 6 seconds    0.0.0.0:32768->5900/tcp   bold_booth
3e4bc48fa50f    selenium/hub             "/opt/bin/entry_poin..."   2 minutes ago   Up 2 minutes    0.0.0.0:4446->4444/tcp selenium-hub


Now let’s move forward and execute the last command:

docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug

The expected output for the above command would be as below:

O/P: e6997998907ae917d392ee3559501d3e2324c5622a33b2be1d75d3f7dcebfcd4

To confirm that above command executed and container created use below:

==> C:\Users\sshukla>docker ps

OUTPUT:

CONTAINER ID  IMAGE   COMMAND  CREATED   STATUS    PORTS   NAMES
e6997998907a    selenium/node-firefox-debug   "/opt/bin/entry_poin..."   8 seconds ago   Up 8 seconds    0.0.0.0:32769->5900/tcp   vigorous_galois
bb839e51b743    selenium/node-chrome-debug "/opt/bin/entry_poin..."   2 minutes ago   Up 2 minutes    0.0.0.0:32768->5900/tcp   bold_booth
3e4bc48fa50f    selenium/hub              "/opt/bin/entry_poin..."   4 minutes ago   Up 4 minutes    0.0.0.0:4446->4444/tcp selenium-hub


 

Step:07 Creating Sample Test

Create two tests one for chrome and the other for firefox as below:


@Test
    public void chrome() throws MalformedURLException, InterruptedException {
 
  ChromeOptions dcc = new ChromeOptions();
  dcc.setCapability("browserName", "chrome");
  dcc.setCapability("OS", "Windows");
  WebDriver driver = new RemoteWebDriver(new URL("https://localhost:4446/wd/hub"),dcc);// pass the url of selenium hub
  driver.get("https://www.google.com");
  Thread.sleep(5000);
  driver.quit();
   
}

@Test
    public void firefox() throws MalformedURLException, InterruptedException {
 
  FirefoxOptions dcc = new FirefoxOptions();
  dcc.setCapability("browserName", "firefox");
  dcc.setCapability("OS", "Windows");
  WebDriver driver = new RemoteWebDriver(new URL("https://localhost:4446/wd/hub"),dcc);// pass the url of selenium hub
  driver.get("https://www.google.com");
  Thread.sleep(5000);
  driver.quit();
   
}


PRACTICE BELOW DOCKER COMMANDS in the CMD:
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html


****************************************************************

WANT TO KNOW HOW to integrate GRADLE + TESTNG + JENKINS CI-CD , click on below link for entire steps with screenshot:

How to run test automation TestNG suite with gradle from jenkins job? Jenkins Integration with Gradle and TestNG.xml suite?Run TestNG suite with Gradle? 

******************************************************************



Step-08:
 Create a testng xml file with parallel as tests and thread count=2 as we are trying to execute the test in two browsers in parallel


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automation Test Suite " parall="tests" thread-count="2">
    
    <test name="Automation Test CasesChrome">
        <classes>
              <class name="com.task.automation.testtwo.testone"/>
        </classes>
   </test>
   
   <test name="Automation Test Casesfirefox">
        <classes>
              <class name="com.task.automation.testtwo.testfirefox"/>
        </classes>
   </test>
   
</suite>

************************************************ 

GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT
************************************************

Thank you for reading this article… Have a nice day!


Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122
Entire course content can be found below:  COURSE CONTENT


Check Selenium-SDET-UIAutomation Questions set 31 to 40:

 Question Set 31-40  

Check Selenium-SDET-UIAutomation Questions set 41-50:

Q&A Set 41-50

Check Selenium-SDET-UIAutomation Questions set 51-70:

Q&A Set 51-70

 

SeleniumWebdriver Automation Testing Interview Questions:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions



2 comments:

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...