观察结果:
我正在运行我的数据驱动的UI自动化使用 selenium 与pytest框架和有60个测试用例。
现在Scope处于会话级别,并且在设置模块中仅登录应用程序一次。
所以现在的场景是,测试用例开始执行:
1.会话级别的设置和拆除:
@pytest.fixture(scope=“session”)setup module():login_to_the_application()拆卸模块():kill_browser_instance()
1.测试用例开始:
@pytest.mark.ui def test_verify_table_data(setup_module,data):#data是在www.example.com文件中创建并设置为fixture的全局变量conftest.py。
db_records = fetching_records_for_data_from_db(data)
#db_records consist 200 rows of data and this we will validate from ui one by one row.
for record in db_records():
value = validating_row_data_in_ui_table(record)
if value is True:
print(pass)
else:
print(fail)
因此,这个完整的流程只执行到4到5个数据,然后自动显示消息,如您必须关闭浏览器才能完成注销过程。
不知道该如何处理这种情况。任何帮助或线索都是好的先谢谢你。
1条答案
按热度按时间pcww981p1#
下面是一个完整的脚本,可以用
pytest
运行,它定义了setUp()
和tearDown()
方法,这样浏览器就可以在测试开始和结束时自动打开和关闭:(这是使用fixture的替代方案,因为pytest
可以与unittest.TestCase
结合使用,这可能有助于更好地构建内容,以确保在测试结束时关闭浏览器。