Giter Site home page Giter Site logo

eliasnogueira / selenium-dynamic-grid-example Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 1.0 45 KB

Example project that run multi-browser web test automation in parallel using Selenium Grid and Docker

License: MIT License

Java 100.00%
grid java parallel-tests selenium-webdriver test-automation

selenium-dynamic-grid-example's Introduction

Selenium Dynamic Grid Example

Selenium 4 has the Selenium Grid project where we can use docker images to run the test targeting a container with a browser. We can approach this in different ways, and one of the most beneficial for multi-browser testing is using the Dynamic Grid.

Note that this project contains basic examples using TestNG and JUnit 5. The main intent is to give you examples to run multi-browser parallel tests.

Don’t forget to give this project a star!

How to run this project

  1. Navigate to the grid folder:

    cd grid
  2. Start the Selenium Grid:

    • if you have a MacOS machine first run in your Terminal socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock:

docker-compose up
  1. Open the grid dashboard at http://localhost:4444/

  2. Run the test:

    • src/test/java/com.eliasnogueira.junit.MultiBrowserDetectorTest for JUnit 5

    • src/test/resources/testng/parallel.xml for TestNG

How this project is structured

Grid

In the grid folder we will see two files: * docker-compose.yml * config.toml

General

Configuration

The general.properties file has basic common values like URL, timeout, and headless execution. The grid.properties file has the url and port of the grid, to configure it.

Normally we add those values in the properties files to easily. You can change these values running the test using a CI/CD tool.

The class Configuration has all the bindings to the properties file, where the ConfigurationManager is responsible to load it. To make this happen the Owner library is in use.

Browser Factory

The BrowserFactory class is an enumeration that returns the browser options. These driver options are used in the TargetFactory which will create a remote execution using the selected browser. The DriverManager adds the driver in a thread to avoid concurrency issues.

Both BaseWeb classes, placed in the test package use the TargetFactory to create the remote browser instance for the test execution.

driver=new TargetFactory().createInstance(browser);

Using TestNG to run multi-browser parallel tests

The TestNG tests are located at src/test/java/com.eliasnogueira.testng and they are composed by:

  • BaseWeb: base test class which has the pre and post-test conditions to create the browser instance and quit it

  • BrowserDetectorTest: test run a parameterized test based on the implemented browsers

How TestNG runs the tests in parallel

TestNG has a built-in feature to run parallel tests using a test suite, which is an XML file to group different tests for execution. The parallel attribute of the <suite> tag is the indication of what should be run in parallel.

The BaseWeb class has a pre-condition that will match the required parameter with the parameter set by each test in the src/test/java/resources/testng/parallel.xml file.

Using JUnit to run multi-browser tests in parallel

The JUnit 5 tests are located at src/test/java/com.eliasnogueira.junit and they are composed by:

  • BaseWeb: base test class which has the post-test condition to quit the browser and a method to create the browser instance which will be used by the test

  • MultiBrowserDetectorTest: test run a parameterized test based on the implemented browsers

How JUnit run the tests in parallel

We know that the MultiBrowserDetectorTest will run the test for each browser present in the BrowserFactory class.

The file junit-platform.properties has configurations set to run the tests in parallel, in a concurrent mode, and with a fixed number of parallel tests. You can take a look at the file to see the configurations set.

selenium-dynamic-grid-example's People

Contributors

eliasnogueira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

svsid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.