pytest:pytest_generate_tests结果作为从另一个夹具返回的测试类的值

时间:2018-12-16 20:08:17

标签: python selenium pytest

继续previous question

因此,扩展了conftest.py并添加了测试参数:

import pytest
import os
from selenium import webdriver
from pages.signin_page import SigninPage

@pytest.fixture(scope='function', autouse=True)
def driver_provider(request):
    request.cls.driver = webdriver.Chrome(executable_path=os.path.join("web_drivers", "chromedriver.exe"))
    request.cls.signin = SigninPage(request.cls.driver)

    def fin():
        request.cls.driver.quit()
    request.addfinalizer(fin)

def pytest_generate_tests(metafunc):
    metafunc.parametrize("link, workspace", (
        ("https://slack.com/signin", "test"),))

signin_page以及提供工作区值的简单方法:

from pages.login_page import LogInPage

class SigninPage(object):
    def __init__(self, web_driver):
        # Initialize web driver
        self.driver = web_driver
        self.driver.get("https://slack.com/signin")  #<-- provide here link from parametrization instead
        self.input_field = self.driver.find_element_by_xpath("//input[@type='text' and @id='domain']")
        self.continue_button = self.driver.find_element_by_xpath("//button[@id='submit_team_domain']")

    def enter_workspace(self, workspace):
        self.input_field.send_keys(workspace)
        return self

    def click_on_continue_button(self):
        self.continue_button.click()
        return LogInPage(self.driver)

问题是-我如何提供link中的metafunc.parametrize值作为类self.driver.get中的SigninPage值,类似于为方法提供workspace? / p>

1)在初始化request.cls.signin = SigninPage(request.cls.driver)期间? 它的工作原理不像在工作区的情况下那样简单(将link添加到参数列表)-还有其他方法吗?

2)创建单独的夹具,该夹具将返回链接值,然后将其与@pytest.mark.usefixtures(?)或SigninPage方法(?)一起用于__init__ 但是,它可以与driver_provider固定装置一起用于一种方法吗?

但是linkworkspace应该保留在生成测试中,因为实际上应该从文件中读取(这部分被简化为示例,从文件中读取也可以)

0 个答案:

没有答案