ui5-community / wdi5

official UI5 end-to-end test framework for UI5 web-apps. wdi5 = Webdriver.IO + UI5 Test API
https://ui5-community.github.io/wdi5/
Apache License 2.0
102 stars 43 forks source link

Stale element reference error when trying to retrieve control, that has been retrieved before (after reload) #346

Closed Scotti-Scholter-Marichal closed 2 years ago

Scotti-Scholter-Marichal commented 2 years ago

I have ran into an issue when trying to get a control, that has been retrieved previously already. I am using browser.asControl with the same UI5 selector in both cases. The problem is, that the html web element of the button changes after a reload (id changes), but the browser.asControl() still fetches the old "version" of the button.

Problem description:

  1. I retrieve a button control with WDI5’s browser.asControl(buttonSelector). The property dom_id of the button control starts with “__fiori0”.
  2. I checked the id of the button element on the web page and it is the same as the button controls dom_id. I then fire the .press() function of the button and everything works as expected.
  3. However, when I reload the page the id of the button web element changes and now starts with “__fiori1”.
  4. Trying to retrieve the button control again with browser.asControl() with the same selector as before results in getting the old instance of the button, which has a dom_id starting with “fiori0”. When I try to call any method (like getProperty()) on this outdated button control, WDI5 then throws a stale element reference error, because there actually is no button on the web page with an id starting with “fiori0” anymore.

I did not save the button control in a variable. I always fetch the control inline with the browser.asControl method. For the tests we are using chrome version ^105.0.0.

Just to clarify further:

Does WDI5 automatically save the retrieved controls in some kind of cache (when you use the same selector)? Is this a bug or intended behavior? How can we make sure to always fetch the right / current control of an element that has been retrieved before?

Any advice would be greatly appreciated. Let me know if you need any more information or explanation on this topic. Thank you!

Siolto commented 2 years ago

Hi @Scotti-Scholter-Marichal,

the behavior you described is actually intended. We store the already located controls internally to save time and roundtrips to the browser scope. To explicitly load the element again you can use forceSelect.

const oSelector = {
    forceSelect: true, // forces the test framework to again retrieve the control from the browser context
    selector: {
      id: "UI5control_ID",
      viewName: "your.namespace.App"
    }

Regards Simon

Scotti-Scholter-Marichal commented 2 years ago

That makes sense! Thank you.

Best wishes, Scotti