SeleniumHQ / selenium-ide

Open Source record and playback test automation for the web.
https://selenium.dev/selenium-ide/
Apache License 2.0
2.84k stars 768 forks source link

Is there a way to clear browser data? #1198

Open cmacdonnacha opened 3 years ago

cmacdonnacha commented 3 years ago

Is there a way to clear browser data via the Selenium IDE chrome extension? Cookies, cache etc. I'd like to run this before each test.

samuelarogbonlo commented 3 years ago

If the tester is using Selenium WebDriver for test automation, then you can create a void method below and then call the method before navigating to the application URL.

I have a codeblock in java but you could understand the logic and relate to a language that works for you otherwise use this:

public void ClearBrowserCache()
{
webDriver.Manage().Cookies.DeleteAllCookies(); 
Thread.Sleep(7000); /
}
darkartswizard commented 3 years ago

Two questions:

Why the 7-second Thread.sleep?

And how does the Thread.sleep work without a Try/catch?

On Thu, May 27, 2021 at 10:51 AM Samuel Arogbonlo @.***> wrote:

If the tester is using Selenium WebDriver for test automation, then you can create a void method below and then call the method before navigating to the application URL.

I have a codeblock in java but you could understand the logic and relate to a language that works for you otherwise use this:

public void ClearBrowserCache() { webDriver.Manage().Cookies.DeleteAllCookies(); Thread.Sleep(7000); / }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/selenium-ide/issues/1198#issuecomment-849745609, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMDP3YK6NOXM5JEL4KMPHKDTPZS7JANCNFSM4YCXY22Q .

samuelarogbonlo commented 3 years ago
  1. More like to wait 7 seconds to clear the cookies
  2. The syntax settles that; it calls the method before navigating to the app URL

But then you could do it manually if that is overwhelming. The manual pattern is shown:

  1. Navigate to the chrome settings page with Selenium by executing the driver.get(‘chrome://settings/clearBrowserData’)
  2. Click on the Clear Data button to clear the cache.
  3. Right-click on the button and then click on Inspect to open Chrome Developer Tools.
  4. Now locate the element using XPath or Chropath. Use it in the Selenium script and apply wait commands to wait till the cache is cleared.
cmacdonnacha commented 3 years ago

Using the Selenium IDE chrome extension.

toddtarsi commented 1 year ago

Huge update, v4 is currently on its 40th iteration in alpha testing 😄

https://github.com/SeleniumHQ/selenium-ide/releases/tag/latest

laikas123 commented 1 year ago

@toddtarsi oh very cool! :smile:

So this might be supported soon?

toddtarsi commented 1 year ago

@laikas123 - On v4, it would be very easy to add a command for this, but it's not currently in line with my focus.

My current focus is on optimizing around and allowing for REPL like interactions with java framework code, then javascript, and so forth. Basically, I am pivoting this tool away from a shared-runtime experience (cypress-like) to an IDE that primarily drives test frameworks by REPL interactions. This is to remove all traces of test-framework from the tool. The idea here is that convenience interactions like that already exist in a myriad of test-framework tools (nightwatch, seleniumbase, cypress even) and the drivers themselves driver.manage().cookies().delete() or something. I'd rather remove us from the process of adding commands and seeing and using that code, so that any org can use the IDE to generate code in their framework of choice and not mine.

laikas123 commented 1 year ago

@toddtarsi that totally makes sense and thanks for the clear and helpful answer. In our case we are using the selenium ide extension to create tests and then using the command line runner to execute said tests later using the .side file. What's awesome is the command line runner automatically clears cookies for each test (from the looks of it). We were hoping to be able to clear cookies for the QA folks when they run a test from the extension before exporting to a .side file that way they don't have to clear cookies each time a test is run.

With that being said this is a really amazing extension and kudos for the awesome functionality it already has.

I don't suppose there's any "hacky" way I could modify the source code of the extension to clear cookies before running each test in the extension?

toddtarsi commented 1 year ago

@laikas123 - I don't intend to deprecate the runtime until I have a much better alternative. Honestly my plan is to transition y'all (and myself) from that to using a wrapper on nightwatch-js for playback. I really think the v4 ide will give you a better experience here as-is right now, although much polish is needed still. The reason we moved to v4 is that from electron, our local playback uses the same runtime as the side-runner, so I just have much less pain and environment difference in general.

laikas123 commented 1 year ago

@toddtarsi thank you for al the help :+1: