Run_Parallel_Tests_In_Firefox_Using_DockerCompose

Tutorial 33​​ ​​ Run Parallel Selenium Tests In Firefox Browser using Docker Compose

Please read the previous article before reading this one.

Let us now see how​​ to execute the tests in parallel on firefox browsers.

Edit Test1.java as shown below

Let us cd to directory where we have placed .yml file

Start docker engine by double clicking docker desktop icon

Wait for the docker engine to start.

Let us now bring down the containers

The tests in below xml point to same Test1.java​​ 

Save xml.

Let us spin up 2 firefox containers​​ 

Execute testng.xml

Launch​​ http://localhost:4444​​ 

Notice below 2 concurrent firefox sessions are running​​ 

Notice 2 firefox sessions

The tests pass

Bring down the containers

Snapshot (testng xml to execute Test1 in 2 parallel firefox sessions)

<!DOCTYPE​​ suite​​ SYSTEM​​ "https://testng.org/testng-1.0.dtd"​​ >

 ​​​​ 

<suite​​ name="suite"​​ parallel="tests">

 ​​​​ <test​​ name="ff1">

 ​​ ​​ ​​​​ <classes>

 ​​ ​​ ​​ ​​ ​​ ​​​​ <class​​ name="sel4scripts.Test1"​​ /> ​​ ​​ ​​ ​​ ​​ ​​​​ 

 ​​ ​​ ​​​​ </classes>

 ​​​​ </test> ​​​​ 

 ​​​​ 

 ​​​​ <test​​ name="ff2">

 ​​ ​​ ​​​​ <classes>

 ​​ ​​ ​​ ​​ ​​ ​​​​ <class​​ name="sel4scripts.Test1"​​ /> ​​ ​​ ​​ ​​ ​​ ​​​​ 

 ​​ ​​ ​​​​ </classes>

 ​​​​ </test>

</suite>

Code snippet (Test1.java for firefox browser)

package​​ sel4scripts;

 

import​​ java.net.MalformedURLException;

import​​ java.net.URL;

import​​ org.openqa.selenium.By;

import​​ org.openqa.selenium.firefox.FirefoxOptions;

import​​ org.openqa.selenium.WebDriver;

import​​ org.openqa.selenium.chrome.ChromeOptions;

import​​ org.openqa.selenium.remote.RemoteWebDriver;

import​​ org.testng.annotations.Test;

 

public​​ class​​ Test1 {

 

@Test

public​​ void​​ TestParallel()​​ throws​​ MalformedURLException, InterruptedException​​ 

 {

//ChromeOptions opt = new ChromeOptions();

 FirefoxOptions​​ opt​​ =​​ new​​ FirefoxOptions();

 WebDriver​​ driver​​ =​​ new​​ RemoteWebDriver(new​​ URL("http://localhost:4444"),opt);

driver.get("http://google.com");

driver.findElement(By.name("q")).sendKeys("Learning Standalone grid");

 System.out.println("Test executed successfully");

 

 }

 

}

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 7th DEC 2024