What is the difference between Selenium Grid and pytest-xdist plugin?

1.3k Views Asked by At

I'm new to parallel testing and I was wondering what the difference is between them.

Apparently, pytest-xdist does not need Selenium Grid to run. It can be used with Selenium alone.

Does anybody have any clue or resource where I can learn the difference?

Thanks and kind regards.

1

There are 1 best solutions below

2
On

Just in case this is useful for anybody I will write down what I learnt:

pytest-xdist: It is used for running parallel tests in the browsers that are installed in the local machine where tests will be run. This means that each test has a browser configured (e.g.: Firefox, Chrome) such as:

driver = webdriver.Firefox()

or

driver = webdriver.Chrome()

And so each test will run with the driver that was specified in the code. Obviously, the local machine needs the browser drivers to be available in any PATH location, so that tests can be run with them.

Selenium Grid: It allows the execution of tests in different browsers, browser versions and operating systems configurations.

Selenium Grid combined with pytest-xdist allows the execution of parallel tests in different browser-OS environments (configured with capabilities, I think).

An execution command example would be:

pytest -n5 -v -s -m "test or ready" --capability browserName firefox

-n5: (pytest parameter) means that 5 instances of the browser will be launched simultaneously.

test or ready: these are the markers that can be combined to execute tests that have these markers.

browserName firefox: It is a capability that indicates that tests must be run in the specified browser, in this case, Firefox. Some possible values are: chrome, firefox, internet explorer, safari.

Some other capabilities are:

version: The browser version to use.

platform: The platform in which the browser will be executed. Some possible values are: WINDOWS, XP, VISTA, MAC, LINUX, UNIX, ANDROID.

To set up the Selenium Grid environment go along the following steps:

  1. Download selenium-server-standalone-[version].jar from https://www.selenium.dev/downloads/.
  2. Initiate the HUB: java -jar selenium-server-standalone-[version].jar -role hub
  3. Initiate as many NODES as you want with: java -jar selenium-server-standalone-[version].jar -role node -hub http://[URL_HUB]/wd/hub
  4. Configure a RemoteDriver in the tests, for example: driver = webdriver.Remote( desired_capabilities = DesiredCapabilities.CHROME, command_executor = 'http://[URL_HUB]:4444/wd/hub')

I still need to learn how to pass the capabilities args as parameters for the RemoteDriver. In conftest.pyfile I can get the capabilities as a list with config.getoption('--capability')). I still need to figure out how to pass the capabilities I want to the setUp method of all my tests.

If someone knows, I will really appreciate a hint on this.

I hope this helps someone who is as lost as I was at the beginning :)