My extension commands in manifest.json
to toggle alert with Ctrl + Shift + X key press combination.
"commands": {
"toggle_extension": {
"suggested_key": {
"default": "Ctrl+Shift+X",
"mac": "Command+Shift+X"
},
"description": "Toggle Your Extension"
}
}
My dev dependencies:
"devDependencies": {
"@types/chrome": "^0.0.262",
"@types/cypress": "^1.1.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.24",
"copy-webpack-plugin": "^12.0.2",
"cypress": "^13.6.6",
"ts-loader": "^9.5.1",
"typescript": "5.3.3",
"webpack": "^5.90.3",
"webpack-cli": "^5.1.4"
}
My test case
describe("Test alert", () => {
it("passes", () => {
cy.visit("");
cy.window().trigger('keydown', {
key: "x", // "X" key code
keyCode: 88,
ctrlKey: true,
shiftKey: true,
});
cy.get("#alert").should("exist");
})
});
My cypress.config.ts
. Extension code in directory called release
.
import { defineConfig } from "cypress";
import * as path from "path";
export default defineConfig({
e2e: {
baseUrl: "https://example.com",
specPattern: "tests/**/*.cy.ts",
supportFile: false,
fixturesFolder: false,
defaultCommandTimeout: 5000,
viewportWidth: 1280,
viewportHeight: 720,
chromeWebSecurity: false,
testIsolation: true,
screenshotOnRunFailure: false,
setupNodeEvents(on, config) {
on('before:browser:launch', (browser, launchOptions) => {
launchOptions.extensions.push(path.resolve(__dirname, "release"));
return launchOptions;
});
}
},
});
Running cypress with npx cypress run --browser chrome --headed
and extension seems to be loaded but test case does not work as expected and alert element never shows up. Am I missing something or attempting something impossible?