LambdaTest Community

Find answers, support, and inspiration from other users

LambdaTest Community

How can I perform Automated cross browser testing with Pytest & Selenium?

I want to know how can I perform Automated cross browser testing with Pytest & Selenium, can anyone please guide me onto that.

Up Vote Down Vote 0 Votes
Posted 4 months ago


When you are looking out for a test automation framework, you would probably require a test framework that would suffice all your requirements i.e. unit test, functional test, acceptance tests, etc. The framework should have the ability to log events, generate test reports, and should have good community support. Pytest fulfils all these requirements and test automation using pytest with Selenium WebDriver is highly recommended as it does not involve a steep learning curve.

When you are planning to develop test automation using pytest with Selenium WebDriver, the first concern that you need to look into is when should load the browser. Loading a new browser instance after each test is not recommended since it is not a scalable solution and might increase the overall test execution time. It is recommended to load the browser (under test) before the actual test cases have started & unloaded/closed the browser instance as soon as the tests are complete. This is possible by using Fixtures [discussed below in Automation Testing Using Pytest – Fixtures (Usage and Implementation) section] in pytest. As mentioned earlier, Fixtures make extensive use of a concept termed as ‘Dependency Injection’ where dependencies can be loaded before the actual tests have started.

By default fixtures have ‘function’ scope, depending on the requirements; you can change the implemented fixture’s scope to a module, session, or class. Like ‘lifetime of variables in C language’, the scope of fixtures indicates how many times the particular fixture will be created.


  • Function Fixture is executed/run once per test session

  • Session One fixture is created for the entire test session

  • Class Only one fixture is created per class of tests

  • Module Fixture is created once per module

Once the tests have been executed, you might be interested to capture the test results in a report format. You need to install pytest-html module for the same.

Up Vote Down Vote 0 Votes
Posted 3 months ago