Skip to content

Commit

Permalink
fix: get extensionId from the driver
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Sep 24, 2024
1 parent c31e747 commit c4e62c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
17 changes: 10 additions & 7 deletions test/e2e/api-specs/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const pollForResult = async (
export const createCaip27DriverTransport = (
driver: Driver,
scopeMap: Record<string, string>,
extensionId: string,
) => {
// use externally_connectable to communicate with the extension
// https://developer.chrome.com/docs/extensions/mv3/messaging/
Expand All @@ -103,14 +104,14 @@ export const createCaip27DriverTransport = (
// will hang in selenium since it can only do one thing at a time.
// the workaround is to put the response on window.asyncResult and poll for it.
driver.executeScript(
([m, p, g, s]: [
([m, p, g, s, e]: [
string,
unknown[] | Record<string, unknown>,
string,
ScopeString,
string
]) => {
const EXTENSION_ID = 'famgliladofnadeldnodcgnjhafnbnhj';
const extensionPort = chrome.runtime.connect(EXTENSION_ID);
const extensionPort = chrome.runtime.connect(e);

const listener = ({
type,
Expand Down Expand Up @@ -154,14 +155,15 @@ export const createCaip27DriverTransport = (
params,
generatedKey,
scopeMap[method],
extensionId,
);
},
});
return pollForResult(driver, generatedKey);
};
};

export const createMultichainDriverTransport = (driver: Driver) => {
export const createMultichainDriverTransport = (driver: Driver, extensionId: string) => {
// use externally_connectable to communicate with the extension
// https://developer.chrome.com/docs/extensions/mv3/messaging/
return async (
Expand All @@ -184,13 +186,13 @@ export const createMultichainDriverTransport = (driver: Driver) => {
// will hang in selenium since it can only do one thing at a time.
// the workaround is to put the response on window.asyncResult and poll for it.
driver.executeScript(
([m, p, g]: [
([m, p, g, e]: [
string,
unknown[] | Record<string, unknown>,
string,
string
]) => {
const EXTENSION_ID = 'famgliladofnadeldnodcgnjhafnbnhj';
const extensionPort = chrome.runtime.connect(EXTENSION_ID);
const extensionPort = chrome.runtime.connect(e);

const listener = ({
type,
Expand Down Expand Up @@ -227,6 +229,7 @@ export const createMultichainDriverTransport = (driver: Driver) => {
method,
params,
generatedKey,
extensionId,
);
},
});
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ async function withFixtures(options, testSuite) {
getServerMochaToBackground();
}

let webDriver;
let driver;
let webDriver;
let extensionId;
let failed = false;

try {
if (!disableGanache) {
await ganacheServer.start(ganacheOptions);
Expand Down Expand Up @@ -184,7 +186,9 @@ async function withFixtures(options, testSuite) {

setManifestFlags(manifestFlags);

driver = (await buildWebDriver(driverOptions)).driver;
const wd = await buildWebDriver(driverOptions);
driver = wd.driver;
extensionId = wd.extensionId;
webDriver = driver.driver;

if (process.env.SELENIUM_BROWSER === 'chrome') {
Expand Down Expand Up @@ -222,6 +226,7 @@ async function withFixtures(options, testSuite) {
mockedEndpoint,
bundlerServer,
mockServer,
extensionId,
});

const errorsAndExceptions = driver.summarizeErrorsAndExceptions();
Expand Down
11 changes: 8 additions & 3 deletions test/e2e/run-api-specs-multichain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
unlockWallet,
DAPP_URL,
ACCOUNT_1,
Fixtures,
} from './helpers';
import { MultichainAuthorizationConfirmation } from './api-specs/MultichainAuthorizationConfirmation';
import transformOpenRPCDocument from './api-specs/transform';
Expand All @@ -44,7 +45,7 @@ async function main() {
disableGanache: true,
title: 'api-specs coverage',
},
async ({ driver }: { driver: Driver }) => {
async ({ driver, extensionId }: any) => {
await unlockWallet(driver);

// Navigate to extension home screen
Expand Down Expand Up @@ -81,7 +82,7 @@ async function main() {
'net_version',
];

const transport = createMultichainDriverTransport(driver);
const transport = createMultichainDriverTransport(driver, extensionId);
const [transformedDoc, filteredMethods, methodsWithConfirmations] =
transformOpenRPCDocument(
MetaMaskOpenRPCDocument as OpenrpcDocument,
Expand Down Expand Up @@ -189,7 +190,11 @@ async function main() {

const testCoverageResultsCaip27 = await testCoverage({
openrpcDocument: MetaMaskOpenRPCDocument as OpenrpcDocument,
transport: createCaip27DriverTransport(driver, reverseScopeMap),
transport: createCaip27DriverTransport(
driver,
reverseScopeMap,
extensionId,
),
reporters: ['console-streaming'],
skip: [
'eth_coinbase',
Expand Down
1 change: 1 addition & 0 deletions test/e2e/webdriver/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ChromeDriver {
return {
driver,
extensionUrl: `chrome-extension://${extensionId}`,
extensionId,
};
}

Expand Down

0 comments on commit c4e62c9

Please sign in to comment.