How references in front of the variable pytest

This article is a summary of the pre- and post-pytest how return parameters

We are doing automated process, if the use is pytest the case, will encounter how to use the pre-conditions variable

such as:

@pytest.fixture()
def init_driver():
    driver = webdriver.Chrome()
    login = LoginPageOperation(driver)
    home = HomePageOperation(driver)
    driver.get(common_datas.login_url)
    driver.maximize_window()
    yield 
    driver.quit()

In front of this, how we use this driver, login, home do?

In fact, through our essence, the pre- and post itself is a function, since it is a function, then it is surely possible that returns a value, then the question is, where should this return value it?

Look at the code:

@pytest.fixture()
def init_driver():
    driver = webdriver.Chrome()
    login = LoginPageOperation(driver)
    home = HomePageOperation(driver)
    driver.get(common_datas.login_url)
    driver.maximize_window()
    yield driver, login, home
    driver.quit()

The price is more than a place where I added, it can be seen that the return value is followed yield, and this I now write return value is a Ganso, calls on all the time in the index can be called up, E.g:

@pytest.fixture()
def init_driver():
    driver = webdriver.Chrome()
    login = LoginPageOperation(driver)
    home = HomePageOperation(driver)
    driver.get(common_datas.login_url)
    driver.maximize_window()
    yield driver, login, home
    driver.quit()


class TestLogin:

    @pytest.mark.usefixtures("init_driver")
    def test_success_login(self, init_driver):
        """
        Login successful test case
        """
        init_driver[1].login(test_login_datas.login_success_data["name"], test_login_datas.login_success_data["passwd"])
        assert(init_driver[-1].logout_text())

d

Guess you like

Origin www.cnblogs.com/LCboss/p/12027977.html