[CentralOH] pytest and selenium
kedlav at gmail.com
Fri Dec 23 15:51:52 EST 2016
I typically write a class extending whatever test class you have to create a client and login as part of init. The painful part of that is that each test you init will login, which is slow. A potential solution for that is to have a factory class that logs in once, then shares the session. This can be risky for testing of too much state is associated server side, as you may poison your test cases. Alternatively, use a good parallel test runner and make sure you don't crash production... :)
Google Voice: 512-461-8210
> On Dec 23, 2016, at 3:04 PM, John Cassidy <jocassid at gmail.com> wrote:
> I'm testing a website using selenium and pytest. I have some tests functions involving the various search features on the site. I also had a test where selenium accesses the sites login page and logs in. When running all tests in the module the login test would run first and the user would be logged in for the other tests. The problem is that if I try to run an individual test then the login doesn't take place.
> How would I handle something like logging in within the pytest framework? I'd like to avoid doing a login as part of every test and would still like to be able to run tests individually.
> I've thought of writing the login as a fixture. To log in I need the selenium webdriver which I've written a fixture for and the base url which I also have a fixture for. I'm not sure how to handle the fixture depending on other fixtures.
> Any thoughts?
> CentralOH mailing list
> CentralOH at python.org
More information about the CentralOH