Clear the browser cache in Quantum
For various reasons, the standard approaches do not work in the latest Quantum projects. For example, clearing the cache for Chrome using URL chrome://settings/clearBrowserData does not work because of limitations related to Selenium version 3 and later. This results in an exception (invalid URI). Due to security reasons, the driver.get()
method accesses only URLs that start with the http://
protocol in Selenium 3 and later.
Because Quantum always uses the latest Selenium version, and it is not possible to downgrade it, you have the following options:
- Downgrade the Quantum version. This is not a good idea because of bug fixes and features introduced in the new versions
-
Use the following code as a function called as part of your clear cache step. This option works for all browsers.
Copypublic static void jsClearLocalStorage() {
getQAFDriver().get("Your URL to delete the Cache for");
getQAFDriver().manage().deleteAllCookies();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
JavascriptExecutor js = (JavascriptExecutor) getQAFDriver();
System.out.println("--Local Storage Clear Start--");
js.executeScript(String.format("window.localStorage.clear();"));
js.executeScript(String.format("window.sessionStorage.clear();"));
System.out.println("--Local Storage Clear End--");
}