content of 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
function in page object 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
function in another 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()
What I am trying to over here is
test_insurance_pages_open_successfully_using_fixtures
takes 3 fixtures as arguments 1.
page_object
that provides a page object at a session-level 2.
load_home_page
to load the home page again at session-level 3.
insurance_data fixture
in conftest.py
which suppliers list of link texts read from some CSV file
So, in essence, it will load the page and open all links one by one for website - https://www.coverfox.com/
First test case passes for link Two-wheelers insurance but for 2nd test data run it fails giving an exception of stale element reference on the point where it is trying to move to(move_to
function) insurance link again.
I am not storing elements anywhere and function is written in a way that it will find the element again.
What is causing this? Or Pytest does some sort of element caching in the background