↩ī¸Ž

selenium-chrome-clear-cache

🗑 Clear cache of a chrome browser in a Selenium flow

const webdriver = require('selenium-webdriver');
const driver = await new Builder().forBrowser('chrome').build();
const clearCache = require('selenium-chrome-clear-cache');

await driver.get('http://www.website.com/login');
await driver.findElement(By.name('username')).sendKeys('admin');
await driver.findElement(By.name('password')).sendKeys('4dM!n', Key.RETURN);
// Web page redirects us
await driver.wait(until.urlIs('http://www.website.com/'), 1000);

await clearCache({webdriver, driver});

await driver.get('http://www.website.com/');
// Gather logged in performance metrics

Uses chrome driver. Get one

Behaviour and Options

The default behaviour clears the cache and history from the last hour. Options can be applied (in form of named arguments) to configure what the browser should clear

name default
cookies false
cache true
history true
await clearCache({webdriver, driver}, {cookies: true}); // Also clears the cookies

await clearCache({webdriver, driver}, {history: false}); // Do not clear the history

Measuring page performance example

image