feat: swallow newtab notifications during e2e tests [#1436]
Description
During e2e tests, opening a newtab notification is causing many tests to fail because it unexpectedly hijacks the focus of the window. To prevent this, we want to be able to disable newtab notifications during e2e tests.
The approach
We can easily detect if the current execution context is e2e test or not by checking if the browser is being controlled by automation or not. This is accessible through the navigator.webdriver
property. This property as very good xbrowser support.
Still I validated that this would actually return true in our lambdatest enviornment, so I wrote a little test and ran it myself:
Code of the test
const {beforeSequence, globalRetriesNumber} =
require("../helpers");
const {expect} = require("chai");
describe("test page links - first run", function()
{
this.retries(globalRetriesNumber);
before(async function()
{
await beforeSequence();
});
it("should return true when accessing navigator.webdriver", async() =>
{
const isWebdriver = await browser.
executeScript("return navigator.webdriver;", []);
console.log({isWebdriver});
expect(isWebdriver).to.eq(true);
});
});
Results:
We can simply check for navigator.webdriver in the check that decides if we should swallow the notification or not. In the very worst case where the API is not supported (because the browser is actually very old), the check will return undefined, and the navigator
global itself has just such a broad support so we will never run into a case of the "trying to access property of undefined"
error.
Related to #1436 (closed)