Selenium Python with Pytest Test Automation
Selenium Python with Pytest Test Automation

Selenium Python with Pytest Test Automation

Summary

  1. Selenium Web driver?is an open-source UI test automation tool for web and mobile applications.
  2. Python is a programming language and computing platform.
  3. Pytest?is a testing framework that allows users to write test codes using Python programming language. It helps to write simple and scalable test cases for UI also It helps to execute test cases, group, generate reports, etc.
  4. requirements.txt file is the most important file which has dependency and script compilation/installation information.

Usage:

  1. UI Web Test Automation with Selenium Python with Pytest
  2. Easily integrate with Appium for Mobile Test Automation.
  3. Easily verify all the links or Image links are working on the webpage.
  4. Parallel execution using the pytest-xdist plugin.

Framework Structure:

The structure for the integration of selenium python with Pytest framework.?

No alt text provided for this image
Framework Architecture

Peculiarity:

  1. Multi-Language Support: Selenium provides freedom to choose any programming language like JavaScript, PHP, Java, Python, C#, Perl, and Ruby to write our automation test scripts.
  2. Multi-Browser Testing: Selenium interacts with web applications and its web elements in a browser, it supports multiple browsers like?IE, Safari, Chrome, Firefox, and Edge.
  3. Easy Identification of Web Elements and Dynamic Handling of Web Elements: With the help of locator’s methods like xpath, CSS Selector, id, and class name identification of elements is easy. Selenium provides dynamic method handling with the Axes method like contains (), Text (), Following-sibling, Preceding, Ancestor, Descendant
  4. Multiple OS Support: Selenium supports different Operating Systems like Mac, Linux, UNIX, as well as Windows. Test scripts created for selenium can work on different platforms and OS.
  5. Fixtures: Fixtures are functions that will run before each test function to which it is applied. Fixtures are used to feed some data to the tests such as database connections, URLs to test, and some sort of input data. Therefore, instead of running the same code for every test, we can attach a fixture function to the tests, and it will run and return the data to the test before executing each test.
  6. Conftest.py: We can define the fixture functions in this file to make them accessible across multiple test files.
  7. Markers: Pytest provides different markers that are used to set various features/attributes to test functions. Pytest provides many inbuilt markers such as xfail, skip and parametrize. Apart from that, users can create their own marker names.
  8. Decorators: A decorator is a design pattern that allows you to modify the functionality of a function by wrapping it in another function.
  9. Assertions: Pytest assertions are checks that return either true or false status. In Python Pytest, if an assertion fails in a test method, then the remaining code in that test method will not be executed, and Pytest assertions will continue with the next test method.
  10. Retry Mechanism: During the execution of test scripts random failures may occur. They can be because of browser issues, hardware issues, Synchronization issues, etc. Pytest provides a Pytest-rerun-failure mechanism to execute failed scripts automatically as per the given retry count.
  11. Test Suite: ?As per the requirement we can group multiple test scripts and create multiple suites for the test scripts using markers.
  12. Well-Handled Synchronization: If the application slows down due to any reasons like network, heavy load, or test script, then the script may fail. It can be handled using Selenium waits like:

  • Implicit Wait
  • Explicit Wait
  • Fluent Wait

Reporting:

We can easily integrate multiple reporting tools like:

  • Allure Reports.
  • Excel Report
  • HTML Reports.
  • PDF

For more details on open-source reporting tools refer to our article on reporting:?https://www.dhirubhai.net/feed/update/urn:li:activity:7088557492661596161

CI/CD Integration:

To schedule nightly job execution selenium Pytest supports multiple CI/CD tools integration like Jenkins, Bamboo, TeamCity, etc.

Supplement:

  1. Easy prioritization, parallel execution, and data provider with Excel are possible.
  2. Wide community support for selenium with Python and Pytest.
  3. Easy integration with test management tools like JIRA, Dev Azure, etc.
  4. Selenium supports TDD/BDD in both design approaches.
  5. Easy Integration with any unit testing framework like Pytest etc.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了