Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 selenium脚本时,我遇到了fixture错误_Python_Selenium_Pytest - Fatal编程技术网

从命令行运行python selenium脚本时,我遇到了fixture错误

从命令行运行python selenium脚本时,我遇到了fixture错误,python,selenium,pytest,Python,Selenium,Pytest,我正在使用selenium和python创建一个自动化框架,所以在conftest.py文件中我使用了fixture,但是当我通过cmd行运行测试用例时,我发现了一个错误 我已经检查了一次又一次,但我没有得到这个错误的根本原因 此代码在我的conftest.py文件下 import pytest @pytest.fixture(scope="class") def test_setup(request): from selenium import webdriver brows

我正在使用selenium和python创建一个自动化框架,所以在conftest.py文件中我使用了fixture,但是当我通过cmd行运行测试用例时,我发现了一个错误

我已经检查了一次又一次,但我没有得到这个错误的根本原因

此代码在我的conftest.py文件下

import pytest
@pytest.fixture(scope="class")
def test_setup(request):
    from selenium import webdriver

    browser =  request.config.getoption("--browser")
    if browser == "chrome":
        driver = webdriver.Chrome(executable_path="/home/akash/PycharmProjects/AutomationFramework/drivers/chromedriver")     
        request.cls.driver = driver
        yield
        driver.quit()
下面是测试用例文件

@pytest.mark.usefixtures("test_setup")
class TestLogin:

    def test_login(self):
        driver = self.driver
        driver.get(utils.URL)
当我以python-mpytest的形式运行命令时,我得到了以下错误 但是,它应该打开浏览器并完成这项工作

我得到的错误

rootdir: /home/akash/PycharmProjects/AutomationFramework
plugins: html-1.21.1, metadata-1.8.0
collected 2 items                                                                                                                                    

tests/login_test.py EE                                                                                                                         [100%]

======================================================================= ERRORS =======================================================================
_______________________________________________________ ERROR at setup of TestLogin.test_login _______________________________________________________

cls = <class '_pytest.runner.CallInfo'>, func = <function call_runtest_hook.<locals>.<lambda> at 0x7f8e17b4ed08>, when = 'setup'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)

    @classmethod
    def from_call(cls, func, when, reraise=None):
        #: context of invocation: one of "setup", "call",
        #: "teardown", "memocollect"
        start = time()
        excinfo = None
        try:
>           result = func()

venv/lib/python3.6/site-packages/_pytest/runner.py:220: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.6/site-packages/_pytest/runner.py:192: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
venv/lib/python3.6/site-packages/pluggy/hooks.py:289: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv/lib/python3.6/site-packages/_pytest/runner.py:110: in pytest_runtest_setup
    item.session._setupstate.prepare(item)
venv/lib/python3.6/site-packages/_pytest/runner.py:359: in prepare
    col.setup()
venv/lib/python3.6/site-packages/_pytest/python.py:1455: in setup
    fixtures.fillfixtures(self)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:288: in fillfixtures
    request._fillfixtures()
venv/lib/python3.6/site-packages/_pytest/fixtures.py:461: in _fillfixtures
    item.funcargs[argname] = self.getfixturevalue(argname)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:471: in getfixturevalue
    return self._get_active_fixturedef(argname).cached_result[0]
venv/lib/python3.6/site-packages/_pytest/fixtures.py:494: in _get_active_fixturedef
    self._compute_fixture_value(fixturedef)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:575: in _compute_fixture_value
    fixturedef.execute(request=subrequest)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:883: in execute
    return hook.pytest_fixture_setup(fixturedef=self, request=request)
venv/lib/python3.6/site-packages/pluggy/hooks.py:289: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv/lib/python3.6/site-packages/_pytest/fixtures.py:923: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

fixturefunc = <function test_setup at 0x7f8e17b61f28>, request = <SubRequest 'test_setup' for <Function test_login>>
kwargs = {'request': <SubRequest 'test_setup' for <Function test_login>>}

    def call_fixture_func(fixturefunc, request, kwargs):
        yieldctx = is_generator(fixturefunc)
        if yieldctx:
            it = fixturefunc(**kwargs)
>           res = next(it)
E           StopIteration

venv/lib/python3.6/site-packages/_pytest/fixtures.py:779: StopIteration
______________________________________________________ ERROR at setup of TestLogin.test_logout _______________________________________________________

cls = <class '_pytest.runner.CallInfo'>, func = <function call_runtest_hook.<locals>.<lambda> at 0x7f8e179ba048>, when = 'setup'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)

    @classmethod
    def from_call(cls, func, when, reraise=None):
        #: context of invocation: one of "setup", "call",
        #: "teardown", "memocollect"
        start = time()
        excinfo = None
        try:
>           result = func()

venv/lib/python3.6/site-packages/_pytest/runner.py:220: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.6/site-packages/_pytest/runner.py:192: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
venv/lib/python3.6/site-packages/pluggy/hooks.py:289: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv/lib/python3.6/site-packages/_pytest/runner.py:110: in pytest_runtest_setup
    item.session._setupstate.prepare(item)
venv/lib/python3.6/site-packages/_pytest/runner.py:359: in prepare
    col.setup()
venv/lib/python3.6/site-packages/_pytest/python.py:1455: in setup
    fixtures.fillfixtures(self)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:288: in fillfixtures
    request._fillfixtures()
venv/lib/python3.6/site-packages/_pytest/fixtures.py:461: in _fillfixtures
    item.funcargs[argname] = self.getfixturevalue(argname)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:471: in getfixturevalue
    return self._get_active_fixturedef(argname).cached_result[0]
venv/lib/python3.6/site-packages/_pytest/fixtures.py:494: in _get_active_fixturedef
    self._compute_fixture_value(fixturedef)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:575: in _compute_fixture_value
    fixturedef.execute(request=subrequest)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:874: in execute
    raise val.with_traceback(tb)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:923: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

fixturefunc = <function test_setup at 0x7f8e17b61f28>, request = <SubRequest 'test_setup' for <Function test_login>>
kwargs = {'request': <SubRequest 'test_setup' for <Function test_login>>}

    def call_fixture_func(fixturefunc, request, kwargs):
        yieldctx = is_generator(fixturefunc)
        if yieldctx:
            it = fixturefunc(**kwargs)
>           res = next(it)
E           StopIteration

venv/lib/python3.6/site-packages/_pytest/fixtures.py:779: StopIteration
rootdir:/home/akash/PycharmProjects/AutomationFramework
插件:html-1.21.1,metadata-1.8.0
收集2项
测试/登录\u test.py EE[100%]
================================================================================================错误=======================================================================
_______________________________________________________设置TestLogin.test\u登录时出错_______________________________________________________
cls=,func=,when='setup'
重放=(,)
@类方法
def from_调用(cls、func、when、reraise=None):
#:调用上下文:“设置”、“调用”之一,
#:“拆卸”、“备忘录收集”
开始=时间()
exinfo=None
尝试:
>结果=func()
venv/lib/python3.6/site-packages/_-pytest/runner.py:220:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.6/site-packages/_-pytest/runner.py:192:in
lambda:ihook(项目=项目,**kwds),when=when,reraise=reraise
venv/lib/python3.6/site-packages/pluggy/hooks.py:289:in\uu调用__
返回self._hookexec(self,self.get_hookimpls(),kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87:in\uhookexec
返回self.\u inner\u hookexec(钩子、方法、kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81:in
firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False,
venv/lib/python3.6/site-packages/\u-pytest/runner.py:110:在pytest\u-runtest\u设置中
项目。会话。\u设置状态。准备(项目)
venv/lib/python3.6/site-packages/_-pytest/runner.py:359:in-prepare
col.setup()
venv/lib/python3.6/site-packages/_-pytest/python.py:1455:安装中
fixture.fillfixture(self)
venv/lib/python3.6/site packages/_-pytest/fixtures.py:288:in-fillfixtures
请求。_fillfixtures()
venv/lib/python3.6/site packages/_-pytest/fixtures.py:461:in_-fillfixtures
item.funcargs[argname]=self.getfixturevalue(argname)
venv/lib/python3.6/site packages/_-pytest/fixtures.py:471:in-getfixturevalue
返回self.\u获取\u活动\u修复定义(argname).cached\u结果[0]
venv/lib/python3.6/site packages/_-pytest/fixtures.py:494:in\u-get\u-active\u-fixturedef
自计算夹具值(fixturedef)
venv/lib/python3.6/site packages/\u pytest/fixtures.py:575:in\u compute\u fixture\u值
执行(请求=子请求)
venv/lib/python3.6/site-packages/_-pytest/fixtures.py:883:in-execute
返回hook.pytest\u fixture\u设置(fixturedef=self,request=request)
venv/lib/python3.6/site-packages/pluggy/hooks.py:289:in\uu调用__
返回self._hookexec(self,self.get_hookimpls(),kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87:in\uhookexec
返回self.\u inner\u hookexec(钩子、方法、kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81:in
firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False,
venv/lib/python3.6/site packages/\u pytest/fixtures.py:923:在pytest\u fixture\u设置中
结果=调用\u fixture\u func(fixturefunc、request、kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
fixturefunc=,请求=
kwargs={'request':}
def call_fixture_func(fixturefunc、request、kwargs):
yieldctx=is_生成器(fixturefunc)
如果yieldctx:
it=fixturefunc(**kwargs)
>res=下一个(it)
停止迭代
venv/lib/python3.6/site packages/_-pytest/fixtures.py:779:StopIteration
______________________________________________________设置TestLogin.test\u注销时出错_______________________________________________________
cls=,func=,when='setup'
重放=(,)
@类方法
def from_调用(cls、func、when、reraise=None):
#:调用上下文:“设置”、“调用”之一,
#:“拆卸”、“备忘录收集”
开始=时间()
exinfo=None
尝试:
>结果=func()
venv/lib/python3.6/site-packages/_-pytest/runner.py:220:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
venv/lib/python3.6/site-packages/_-pytest/runner.py:192:in
lambda:ihook(项目=项目,**kwds),when=when,reraise=reraise
venv/lib/python3.6/site-packages/pluggy/hooks.py:289:in\uu调用__
返回self._hookexec(self,self.get_hookimpls(),kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87:in\uhookexec
返回self.\u inner\u hookexec(钩子、方法、kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81:in
firstresult=hook.spec.opts.get(“firstresult”),如果hook.spec else为False,
venv/lib/python3.6/site-packages/\u-pytest/runner.py:110:在pytest\u-runtest\u设置中
项目。会话。\u设置状态。准备(项目)
venv/lib/python3.6/site-packages/_-pytest/runner.py:359:in-prepare
col.setup()
venv/lib/python3.6/site-packages/_-pytest/python.py:1455:安装中
fixture.fillfixture(self)
venv/lib/python3.6/site packages/_-pytest/fixtures.py:288:in-fillfixtures
R
import pytest
@pytest.fixture(scope="class")
def test_setup(request):
    from selenium import webdriver

    browser =  request.config.getoption("--browser")
    if browser == "chrome":
        driver = webdriver.Chrome(executable_path="/home/akash/PycharmProjects/AutomationFramework/drivers/chromedriver")     
    request.cls.driver = driver
    yield
    driver.quit()