无法使用 pytest 固定装置在测试文件上使用页面实例

问题描述

下面的代码基于使用pytest和fixtures的页面对象模式,我创建了一个conftext.py文件来初始化浏览器,创建了一个页面一个测试文件

这是一个配置文件

"""conftest.py file"""
import pytest
from selenium import webdriver

@pytest.fixture(params=["chrome"],scope='class')
def init_driver(request):
    if request.param == "chrome":
        web_driver = webdriver.Chrome(executable_path="...")
    if request.param == "firefox":
        web_driver = webdriver.Firefox(executable_path="...")
    request.cls.driver = web_driver
    yield
    web_driver.close()

这是 test_Base.py 文件

"""test_Base.py file"""
import pytest
@pytest.mark.usefixtures("init_driver")
class BaseTest:
    pass    

这是一些页面文件

"""ABCPage.py file"""
from Pages.BasePage import BasePage

class ABCPage(BasePage):
    def __init__(self,driver):
        super().__init__(driver)

    def some_function1(self):
        ...
        ...

    def some_function2(self):
        ...
        ...

这是一个测试文件

"""test_ABC.py file"""
import pytest
Tests.test_Base import BaseTest
Pages.ABCPage import ABCPage
Pages.DEFPage import DEFPage

class Test_ABC(BaseTest):
    @pytest.fixture(scope='module')
    def instances(self):
        abcPage = ABCPage(self.driver)
        defPage = DEFPage(self.driver)
        return abcPage,defPage
    
    def test_verify_something(instances):
        abcPage.some_function1()
    
    def test_verify_something_in_defpage(instances):
        defPage.some_function11()

在编译和运行时出现以下错误

  """Getting ERROR"""
  def test_verify_something(instances):
  abcPage.some_function1()
  E NameError: name 'abcPage' is not defined
  Also 
  E AttributeError: 'Test_ABC' object has no attribute 'some_function1'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...