filmov
tv
How To Run Selenium PyTests In Parallel (2 Min) In Python
Показать описание
In this tutorial, you'll learn how to run selenium tests in parallel using Pytests & Python.
—
—
Video Transcript:
—
Hi guys, this is Abhi from Gokce DB. In this video, you are going to learn how to run SELENIUM TESTS in PARALLEL using PYTEST in PYTHON.
Let’s start by clicking on the PYTHON PACKAGES button and ensure that PYTEST, PYTEST dash XDIST, and PYTEST dash FORKED packages are installed.
Next, let’s look at the TESTS directory structure. I have an AMAZON underscore TESTS directory which contains three files. CONFTEST dot PY file contains the fixture function or driver to initialize the web driver.
I also have two TESTS files. The first test searches for the keyword SUNGLASSES then click on the AMAZON CHOICE product and asserts whether the keyword UV FOUR HUNDRED PROTECTION appears on the product page or not.
In the second test file, instead of searching for SUNGLASSES, I’m searching for SHOES. And the rest of the steps are the same.
I also have a PAGE underscore OBJECT directory which contains LOCATORS and PAGES. LOCATORS dot PY file contains the IDs and XPATHs that are being used on the HOME page and the SEARCH page.
Whereas, the PAGES dot PY file contains the helper method for the AMAZON HOME page and the AMAZON SEARCH page classes. To execute the two tasks sequentially, right-click on the AMAZON underscore TESTS folder then hit RUN PYTEST.
Here, I’m expecting the first test to PASS and the second test to FAIL. Now, if you wanted to run this test in parallel click on the PYTEST dropdown then click on edit configuration.
Type HYPHEN N space TWO in additional arguments, where two is the number of workers. If I re-run the test again, you’ll notice two browser windows popups because both the tests are running in parallel.
Finally, to export the test results click on the EXPORT TESTS RESULTS button. There you have it.
Make sure you like, subscribe, and turn on the notification bell. Until next time.
def test_keyword_in_search_result(driver):
amazon_home_page = AmazonHomePage(driver)
amazon_search_page = AmazonSearchPage(driver)
def test_keyword_in_search_result(driver):
amazon_home_page = AmazonHomePage(driver)
amazon_search_page = AmazonSearchPage(driver)
class AmazonHomePage:
def __init__(self, driver):
@staticmethod
def get_url():
def get_search_text_box_by_id(self):
def get_search_submit_button_by_id(self):
class AmazonSearchPage:
def __init__(self, driver):
def get_amazons_choice_product_by_xpath(self):
class AmazonHomePageLocator:
search_text_box_id = "twotabsearchtextbox"
search_submit_button_id = "nav-search-submit-button"
class AmazonSearchPageLocator:
import pytest
from selenium import webdriver
import os
def driver():
driver = webdriver.Chrome(executable_path=root_dir + '/resources/chromedriver')
# Time in seconds driver should wait when searching for an element if it is not
# immediately present
yield driver
—
—
Video Transcript:
—
Hi guys, this is Abhi from Gokce DB. In this video, you are going to learn how to run SELENIUM TESTS in PARALLEL using PYTEST in PYTHON.
Let’s start by clicking on the PYTHON PACKAGES button and ensure that PYTEST, PYTEST dash XDIST, and PYTEST dash FORKED packages are installed.
Next, let’s look at the TESTS directory structure. I have an AMAZON underscore TESTS directory which contains three files. CONFTEST dot PY file contains the fixture function or driver to initialize the web driver.
I also have two TESTS files. The first test searches for the keyword SUNGLASSES then click on the AMAZON CHOICE product and asserts whether the keyword UV FOUR HUNDRED PROTECTION appears on the product page or not.
In the second test file, instead of searching for SUNGLASSES, I’m searching for SHOES. And the rest of the steps are the same.
I also have a PAGE underscore OBJECT directory which contains LOCATORS and PAGES. LOCATORS dot PY file contains the IDs and XPATHs that are being used on the HOME page and the SEARCH page.
Whereas, the PAGES dot PY file contains the helper method for the AMAZON HOME page and the AMAZON SEARCH page classes. To execute the two tasks sequentially, right-click on the AMAZON underscore TESTS folder then hit RUN PYTEST.
Here, I’m expecting the first test to PASS and the second test to FAIL. Now, if you wanted to run this test in parallel click on the PYTEST dropdown then click on edit configuration.
Type HYPHEN N space TWO in additional arguments, where two is the number of workers. If I re-run the test again, you’ll notice two browser windows popups because both the tests are running in parallel.
Finally, to export the test results click on the EXPORT TESTS RESULTS button. There you have it.
Make sure you like, subscribe, and turn on the notification bell. Until next time.
def test_keyword_in_search_result(driver):
amazon_home_page = AmazonHomePage(driver)
amazon_search_page = AmazonSearchPage(driver)
def test_keyword_in_search_result(driver):
amazon_home_page = AmazonHomePage(driver)
amazon_search_page = AmazonSearchPage(driver)
class AmazonHomePage:
def __init__(self, driver):
@staticmethod
def get_url():
def get_search_text_box_by_id(self):
def get_search_submit_button_by_id(self):
class AmazonSearchPage:
def __init__(self, driver):
def get_amazons_choice_product_by_xpath(self):
class AmazonHomePageLocator:
search_text_box_id = "twotabsearchtextbox"
search_submit_button_id = "nav-search-submit-button"
class AmazonSearchPageLocator:
import pytest
from selenium import webdriver
import os
def driver():
driver = webdriver.Chrome(executable_path=root_dir + '/resources/chromedriver')
# Time in seconds driver should wait when searching for an element if it is not
# immediately present
yield driver
Комментарии