【问题标题】:pytest-selenium installed but not available as plugin for pytest. What have I done wrong?pytest-selenium 已安装,但不能作为 pytest 的插件使用。我做错了什么?
【发布时间】:2021-06-16 16:35:00
【问题描述】:

我已经安装了 pytest-selenium,但我无法将它与 pytest 一起使用。

  def test_sanity(selenium):
E       fixture 'selenium' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, check, cov, dash_br, dash_duo, dash_process_server, dash_thread_server, dashr, dashr_server, doctest_namespace, install_cbm_dash, install_dir, metadata, mock, mocker, monkeypatch, most_recent_installer_exe, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, run_installer, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, uninstall_after_run
>       use 'pytest --fixtures [testpath]' for help on them.

λ pytest --fixtures
======================================================= test session starts ======================================================= platform win32 -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\dbak\Downloads\cmder
plugins: allure-pytest-2.7.0, dash-1.7.0, flaky-3.6.0, check-0.3.5, cov-2.10.0, html-1.21.1, metadata-1.8.0, mock-1.10.4, profiling-1.7.0

这可能是什么根本原因?我该如何解决?

【问题讨论】:

    标签: selenium pytest pytest-selenium


    【解决方案1】:

    这意味着没有名为selenium 的夹具。

    您可能需要初始化 selenium。你可以在你想使用它的每个函数中执行此操作,但这很烦人。因此,更好的选择是在conftest.py 中添加一个函数。这样您就可以继续使用 selenium 作为测试函数的参数。

    import pytest
    
    @pytest.fixture()
    def selenium():
        #do some initialisation for selenium here.
        return your_selenium_instance
    

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 2019-04-08
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      相关资源
      最近更新 更多