问题描述
下面的代码基于使用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 (将#修改为@)