Selenium Tips: Efficiently Removing Cookies
Sauce AI for Test Authoring: Move from intent to executing in moment.|xBack to ResourcesBlogPosted November 16, 2018
Selenium Tips: Efficiently Removing Cookies
Let ’ s say you receive a simple SaaS application with a setup that start a browser and logs in. Towards the end of the examination, the cleanup log the user out, so the future test will run on time. But something goes wrong, and logout perform not happen. The adjacent exam will go to the wrong screen, a blind with no username, countersign, or submit button field, cause long delays as the test waits for elements, false errors, and potential both.
The simple answer for this in FireFox and Chrome is to driver.quit at the end of each test. The new session will lose all the cookies. You might, however, not want to pay the cost of shutting down and restarting the browser. In that case, you could use the driver.clear_all_cookies () method.
That works fine for the webkit browsers, but what about internet adventurer and edge?
For those devices, things aren ’ t nearly as straightforward.
As of this publication, withsampling code in ruby, those commands merely don ’ t work for Edge or Internet Explorer. Neither do the commands to get the cooky - see this in the call to all_cookies in the like codification gmail_login_windows.rb. We may explore cookies through webdriver later. For now, know they don ’ t employment for the microsoft browsers.
Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.
Alternatives Under Windows
Today we ’ ll ply two examples. For internet explorer, reckon shelling out to the bid line to withdraw cookies:
scheme (“ RunDll32.exe InetCpl.cp, ClearMyTracksByProcess 2 ”);
For Edge, the simplest way is to go into browser settings, delete biscuit, so chatter the button to clear the constituent every time the browser quits.
It may also be possible to use the registry editor to delete cookies. Likewise, the example above uses some explicit delay, because the unquestioning waits miscarry. To earn some repute, ensure some code into github that delete the cookies/cache, mayhap as a batch file. Or suggest a workaround for the explicit waits. Your result could be featured in a future Selenium tip, and we ’ ll send you a $ 100 amazon gift card.
Another alternative, of course, let someone else figure it out expend for testing. For now, though, here ’ s how to do it yourself.
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free