Xceptance / neodymium-library

A test automation library based on common other best practice open source libraries. It adds missing functionalities but does not reinvent the wheel. Just glues stuff together nicely and adds some sprinkles.
MIT License
80 stars 11 forks source link

Improvement: Improve clearing cookies on browser reuse #295

Open oomelianchuk opened 2 months ago

oomelianchuk commented 2 months ago

Quick Description

Neodymium offers a cool feature to reuse browsers for multiple test runs. It helps to decrease the system load created by test automation. To make tests independent from each other we try to delete cookies with wDSCont.getWebDriver().manage().deleteAllCookies(); before the test that is about to reuse the browser. Unfortunately, due to JS limitations, this command only deletes cookies for the currently open domain. Sometimes in test flows it's required to open pages with different domains. In this case, the tests currently become dependent on each other because only cookies for the last open domain in the test are removed. This may lead to test flakiness that is hard to debug.

It would be great to improve our library to remove cookies for all domains if it's technically possible. Here I found that it might be possible with DevTools (would then only work for a limited number of browsers that support Dev Tools but is still something). The shared link is pretty old, so the commands are likely different now. Please, research, what would be the new Dev Tool command for this, if such exists now and call it in the BrowserRunner#setUpTest for the case of a resued browser.

In case it's now possible to remove all cookies with DevTools, maybe we can make Neo save all / the first visited domain, so that before starting new test, all domains could be opened again to clear cookies with wDSCont.getWebDriver().manage().deleteAllCookies();

User Story

As a user who wants to reuse browser for multiple tests, I want the tests to stay independent so that all cookies set during last tests are cleared before new test starts

Example of the case when it could be useful

Test starts on the XYZ domain Browses different sites during test flow Ends on the ZYX domain Next Test starts on XYZ domain And expects clear state The cookies for XYZ domain were not removed The state is not cleared Test fails due to unexpected state

Upfront research

Documentation Requirements

Test Requirements