Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用JSON中的数据参数化登录设置装置&;命令行和_Python_Python 3.x_Parameter Passing_Pytest_Fixtures - Fatal编程技术网

Python 如何使用JSON中的数据参数化登录设置装置&;命令行和

Python 如何使用JSON中的数据参数化登录设置装置&;命令行和,python,python-3.x,parameter-passing,pytest,fixtures,Python,Python 3.x,Parameter Passing,Pytest,Fixtures,我正在pytest中为我的web应用程序设置一些基本的UI测试。此应用中的每个功能测试都要求用户首先登录。我想创建一个安装夹具,它将打开一个浏览器(什么浏览器,什么服务器-取决于命令行参数),然后使用JSON文件中的数据登录(没有硬编码值)。我不想让我的测试用例基于登录测试用例(它有多组数据),我想使用一个单独的夹具 我成功地创建了一个打开所需浏览器和使用所需服务器的设置,但我不知道如何参数化装置,也不知道如何使用JSON中的数据 因此,如果我想在我的安装装置中使用一个让我登录并需要登录和密码等

我正在pytest中为我的web应用程序设置一些基本的UI测试。此应用中的每个功能测试都要求用户首先登录。我想创建一个安装夹具,它将打开一个浏览器(什么浏览器,什么服务器-取决于命令行参数),然后使用JSON文件中的数据登录(没有硬编码值)。我不想让我的测试用例基于登录测试用例(它有多组数据),我想使用一个单独的夹具

我成功地创建了一个打开所需浏览器和使用所需服务器的设置,但我不知道如何参数化装置,也不知道如何使用JSON中的数据

因此,如果我想在我的安装装置中使用一个让我登录并需要登录和密码等参数的函数:

login_page = LoginPage(driver)
login_page.log_me_in(login, password)
如何将其添加到安装夹具中

这是我的conftest.py设置:

@pytest.fixture(scope="class")
def setup(request, browser, server_instance):
    if browser is None:
        browser = "iexplorer"

    if server_instance is None:
        server_instance = "test"

    driver = WebdriverFactory(browser, server_instance).webdriver_instance()

    if request.cls is not None:
        request.cls.driver = driver

    yield driver
    driver.quit()
以及从命令行添加参数:

def pytest_addoption(parser):
    parser.addoption("--browser", help="choose test browser: iexplorer, 
    firefox, chrome")
    parser.addoption("--server_instance", help="choose test server instance: 
    test, user")


@pytest.fixture(scope="class")
def browser(request):
   return request.config.getoption("--browser")


@pytest.fixture(scope="class")
def server_instance(request):
    return request.config.getoption("--server_instance")
我尝试使用pytest_generate_测试,但我不完全理解参数后来如何以及基于什么添加到夹具中

或者我应该添加另一个使用安装夹具的夹具,并让我登录?但是,如何从文件中传递参数

请给我指出正确的方向!谢谢大家!