使用Python pytest硒处理替代品参考例外Coverfox网站

test_homepage.py

的内容
    def test_insurance_pages_open_successfully_using_fixtures(page_object,load_home_page,insurance_data):
            page_object.open_insurance(insurance_data)
            assert page_object.ui.contains_text('Buying two-wheeler insurance from Coverfox is simple')
页面对象open_insurance中的

home_page.py函数

    def open_insurance(self,insurance):
        self._ui.move_to(locators.drp_dwn_insurance)
        self._ui.click(format_locator(locators.lnk_insurance,insurance))

move_to在另一个file.py

中的功能
    def move_to(self,locator):
        to_element = self.find_element(locator)
        print("element value",to_element)
        self.action.move_to_element(to_element).perform()

我要在这里尝试的是 test_insurance_pages_open_successfully_using_fixtures以3个装置作为参数 1

page_object,它在会话级 2 上提供页面对象。

load_home_page,以在会话级 3 上再次加载主页。

insurance_data fixture中的conftest.py,哪个供应商从一些CSV文件中读取了链接文本

因此,从本质上讲,它将加载页面并逐个打开网站的所有链接-https://www.coverfox.com/

第一个测试用例通过了链接两轮保险,但是对于第二个测试数据运行,它在尝试移动到{move_to函数)的点上给出了陈旧元素引用,但失败了/ strong>保险链接。

我不在任何地方存储元素,并且编写函数时会再次找到该元素。

是什么原因造成的?或者Pytest在后台进行某种元素缓存

lkf1983 回答:使用Python pytest硒处理替代品参考例外Coverfox网站

似乎您应该对fixture使用功能级别的load_home_page或在完成某些操作后刷新页面。

在当前方法(至少是您所描述的方法)中,您将相同的页面和页面状态用于不同的测试。

您能否也分享灯具代码?

本文链接:https://www.f2er.com/3138314.html

大家都在问