[CentralOH] pytest and selenium

John Cassidy jocassid at gmail.com
Fri Dec 23 17:06:31 EST 2016


After I sent my email, I stumbled upon the answer to my question

http://pythontesting.net/framework/pytest/pytest-fixtures-nuts-bolts/#modular

has an example of fixtures depending on fixtures.  I wound up with a
loggedIn fixture that looks like this:

@fixture(scope='module')
def loggedIn(request, driver, baseUrl):
    driver.get(baseUrl + '/login.aspx')
    driver.find_element_by_id('username').send_keys('username')
    driver.find_element_by_id('password').send_keys('password')
    driver.find_element_by_id('loginButton').click()
    return "home" == driver.title

driver and baseUrl are my existing fixtures.  A typical test looks
something like:

def testSomething(driver, baseUrl, loggedIn):
    assert loggedIn  # makes sure that login happened
    # other selenium commands and assert statements
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20161223/8f92bb13/attachment.html>


More information about the CentralOH mailing list