Skip to content
Merged
15 changes: 13 additions & 2 deletions test/functional/services/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export async function RemoteProvider({ getService }: FtrProviderContext) {
const coveragePrefix = 'coveragejson:';
const coverageDir = resolve(__dirname, '../../../../target/kibana-coverage/functional');
let logSubscription: undefined | Rx.Subscription;
type BrowserStorage = 'sessionStorage' | 'localStorage';

const clearBrowserStorage = async (storageType: BrowserStorage) => {
try {
await driver.executeScript(`window.${storageType}.clear();`);
} catch (error) {
if (!error.message.includes(`Failed to read the ${storageType} property from 'Window'`)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to have single quotes around the storage type, which one is correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right Spencer, I actually tested with quotes 😫

throw error;
}
}
};

const { driver, By, until, consoleLog$ } = await initWebDriver(
log,
Expand Down Expand Up @@ -128,8 +139,8 @@ export async function RemoteProvider({ getService }: FtrProviderContext) {
.manage()
.window()
.setRect({ width, height });
await driver.executeScript('window.sessionStorage.clear();');
await driver.executeScript('window.localStorage.clear();');
await clearBrowserStorage('sessionStorage');
await clearBrowserStorage('localStorage');
});

lifecycle.on('cleanup', async () => {
Expand Down