Skip to content

Commit

Permalink
WIP: Firefox support (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 authored Aug 8, 2023
1 parent a1dcfe1 commit 8690290
Show file tree
Hide file tree
Showing 24 changed files with 2,157 additions and 214 deletions.
51 changes: 39 additions & 12 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
until,
} from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome';
import firefox from 'selenium-webdriver/firefox';
import { expect } from 'vitest';
import { erc20ABI } from 'wagmi';

Expand All @@ -22,13 +23,23 @@ const BINARY_PATHS = {
mac: {
chrome: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
brave: '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
firefox: '/Applications/Firefox.app/Contents/MacOS/Firefox',
},
linux: {
chrome: process.env.CHROMIUM_BIN,
brave: process.env.BRAVE_BIN,
firefox: process.env.FIREFOX_BIN,
},
};

export const getRootUrl = () => {
const browser = process.env.BROWSER || 'chrome';
if (browser === 'firefox') {
return 'moz-extension://';
}
return 'chrome-extension://';
};

export const byTestId = (id: string) => By.css(`[data-testid="${id}"]`);
export const byText = (text: string) =>
By.xpath(`//*[contains(text(),"${text}")]`);
Expand Down Expand Up @@ -90,18 +101,34 @@ export async function initDriverWithOptions(opts) {
'--enable-logging',
];

const options = new chrome.Options()
.setChromeBinaryPath(BINARY_PATHS[opts.os][opts.browser])
.addArguments(...args);
options.setAcceptInsecureCerts(true);

const service = new chrome.ServiceBuilder().setStdio('inherit');

return await new Builder()
.setChromeService(service)
.forBrowser('chrome')
.setChromeOptions(options)
.build();
if (opts.browser === 'firefox') {
const options = new firefox.Options()
.setBinary(BINARY_PATHS[opts.os][opts.browser])
.addArguments(...args.slice(1))
.addExtensions('rainbowbx.xpi');
options.setAcceptInsecureCerts(true);

const service = new firefox.ServiceBuilder().setStdio('inherit');

return await new Builder()
.setFirefoxService(service)
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
} else {
const options = new chrome.Options()
.setChromeBinaryPath(BINARY_PATHS[opts.os][opts.browser])
.addArguments(...args);
options.setAcceptInsecureCerts(true);

const service = new chrome.ServiceBuilder().setStdio('inherit');

return await new Builder()
.setChromeService(service)
.forBrowser('chrome')
.setChromeOptions(options)
.build();
}
}

export async function getExtensionIdByName(driver, extensionName) {
Expand Down
3 changes: 2 additions & 1 deletion e2e/parallel/importWalletFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { afterAll, beforeAll, describe, it } from 'vitest';
import {
checkWalletName,
getExtensionIdByName,
getRootUrl,
importWalletFlow,
initDriverWithOptions,
} from '../helpers';
import { TEST_VARIABLES } from '../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/parallel/importWalletFlowPkey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { afterAll, beforeAll, describe, it } from 'vitest';
import {
checkWalletName,
getExtensionIdByName,
getRootUrl,
importWalletFlow,
initDriverWithOptions,
} from '../helpers';
import { TEST_VARIABLES } from '../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/parallel/newWalletFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
findElementByTestIdAndClick,
findElementByText,
getExtensionIdByName,
getRootUrl,
goToPopup,
goToWelcome,
initDriverWithOptions,
Expand All @@ -18,7 +19,7 @@ import {
waitAndClick,
} from '../helpers';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/parallel/settingsFlows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
findElementByTestIdAndClick,
findElementByTextAndClick,
getExtensionIdByName,
getRootUrl,
goBackTwice,
importWalletFlow,
initDriverWithOptions,
Expand All @@ -18,7 +19,7 @@ import {
} from '../helpers';
import { TEST_VARIABLES } from '../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/parallel/settingsPrivacyFlows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
findElementByTextAndClick,
getExtensionIdByName,
getNumberOfWallets,
getRootUrl,
goToPopup,
importWalletFlow,
initDriverWithOptions,
Expand All @@ -22,7 +23,7 @@ import {
} from '../helpers';
import { TEST_VARIABLES } from '../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/serial/dappInteractions/1_appInteractionsFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
findElementByText,
getAllWindowHandles,
getExtensionIdByName,
getRootUrl,
getTextFromText,
getWindowHandle,
goToPopup,
Expand Down Expand Up @@ -60,7 +61,7 @@ const TYPED_MESSAGE = {
};
const MESSAGE = 'rainbow rocks 🌈';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/serial/dappInteractions/2_dappInteractionFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getAllWindowHandles,
getExtensionIdByName,
getOnchainBalance,
getRootUrl,
getTextFromDappText,
getWindowHandle,
goToPopup,
Expand All @@ -28,7 +29,7 @@ import {
} from '../../helpers';
import { TEST_VARIABLES } from '../../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/serial/send/1_sendFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
findElementByTestIdAndClick,
findElementByText,
getExtensionIdByName,
getRootUrl,
goToPopup,
goToWelcome,
initDriverWithOptions,
Expand All @@ -24,7 +25,7 @@ import {
} from '../../helpers';
import { TEST_VARIABLES } from '../../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/serial/swap/1_swapFlow1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
findElementByTestIdAndDoubleClick,
findElementByText,
getExtensionIdByName,
getRootUrl,
getTextFromText,
getTextFromTextInput,
goToPopup,
Expand All @@ -30,7 +31,7 @@ import {
import { convertRawAmountToDecimalFormat, subtract } from '../../numbers';
import { SWAP_VARIABLES, TEST_VARIABLES } from '../../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
3 changes: 2 additions & 1 deletion e2e/serial/swap/2_swapFlow2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
findElementByTestIdAndClick,
findElementByText,
getExtensionIdByName,
getRootUrl,
getTextFromText,
goToPopup,
goToWelcome,
Expand All @@ -30,7 +31,7 @@ import {
import { convertRawAmountToDecimalFormat, subtract } from '../../numbers';
import { SWAP_VARIABLES, TEST_VARIABLES } from '../../walletVariables';

let rootURL = 'chrome-extension://';
let rootURL = getRootUrl();
let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
Expand Down
1 change: 1 addition & 0 deletions e2e/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default defineConfig({
watch: false,
retry: 2,
bail: 1,
hookTimeout: 30_000,
},
}) as UserConfig;
Loading

0 comments on commit 8690290

Please sign in to comment.