0

I am using following method to clear session storage value

public static void CleanCache()
{
WebDriver driver = new WebDriver()
LocalStorage local =((WebStorage)driver).getSessionStorage().clear()
}

But getting following error

Getting Following error:

01-22-2018 03:16:59 PM - [ERROR]  - Cannot cast object 'CInternetExplorerDriver: internet explorer on WINDOWS (c0f0e132-d574-48c3-a339-9180555b0e33)' with class 'com.kms.katalon.selenium.driver.CInternetExplorerDriver' to class 'org.openqa.selenium.html5.WebStorage'
01-22-2018 03:16:59 PM - [ERROR]  - Test Cases/01_UserManagement/Login FAILED because (of) org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'CInternetExplorerDriver: internet explorer on WINDOWS (c0f0e132-d574-48c3-a339-9180555b0e33)' with class 'com.kms.katalon.selenium.driver.CInternetExplorerDriver' to class 'org.openqa.selenium.html5.WebStorage'

Any help would be appreciated?

ChanGan
  • 4,254
  • 11
  • 74
  • 135
  • 2
    It looks like `clear` returns the instance of the driver, but you are assigning it to `local` which is of type `LocalStorage`. Simply remove `LocalStorage local =`. – Florent B. Jan 22 '18 at 16:33
  • 1
    @FlorentB. The error is actually that he's casting `driver` as `WebStorage`. I think you found another issue that will crop up ... my guess is that `clear()` probably doesn't return anything so I think the next error he will get (after fixing the above) is that `void` can't be cast to `LocalStorage.` – JeffC Jan 22 '18 at 19:30

1 Answers1

1

From looking at the error, driver cannot be cast to WebStorage. Change the code to the below:

public static void CleanCache()
{
    WebDriver driver = new WebDriver()
    driver.getSessionStorage().clear()
}

If you can't find anything else that works, you can always use JS

window.sessionStorage.clear()

See this for more details.

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • 1
    Thanks for the answer. The Intelligence is not showing getSessionStorage() method on driver. Do I need to import any Jars? – ChanGan Jan 23 '18 at 02:12
  • I'm not sure. I don't use groovy but I did see this code used as is somewhere in my searches earlier. Maybe it was an old reference that's no longer valid. You might try the JS and see if that does what you want. – JeffC Jan 23 '18 at 05:12
  • OK. I will try JS. – ChanGan Jan 23 '18 at 05:19
  • Does it need browser to opended? – ChanGan Jan 23 '18 at 05:22
  • You should probably read the link that I posted and some other info on how to use it and how it works, etc. I'm not that familiar with all the details. – JeffC Jan 23 '18 at 14:21