Skip to content

Commit

Permalink
Settings & Privacy / Wallets & Keys test (BX-581) (#808)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Barbieri <[email protected]>
  • Loading branch information
BrodyHughes and brunobar79 authored Aug 2, 2023
1 parent ec1d9cb commit b26a9c0
Show file tree
Hide file tree
Showing 24 changed files with 446 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
path: build/
# CHROME TESTS
chrome-e2e-parallel:
runs-on: beefy-runner-bx
runs-on: ubuntu-latest
timeout-minutes: 16
needs: [build]
env:
Expand Down
76 changes: 66 additions & 10 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ export const byText = (text: string) =>

export async function goToTestApp(driver) {
await driver.get('https://bx-test-dapp.vercel.app/');
await delay(1000);
await delayTime('very-long');
}

export async function goToPopup(driver, rootURL, route = '') {
await driver.get(rootURL + '/popup.html' + route);
await delay(5000);
await delayTime('very-long');
}

export async function goToWelcome(driver, rootURL) {
await driver.get(rootURL + '/popup.html#/welcome');
await delay(1000);
await delayTime('very-long');
}

export async function getAllWindowHandles({
Expand Down Expand Up @@ -169,20 +169,20 @@ export async function doNotFindElementByTestId({ id, driver }) {
}

export async function findElementByTestIdAndClick({ id, driver }) {
await delay(200);
await delayTime('short');
const element = await findElementByTestId({ id, driver });
await waitAndClick(element, driver);
}

export async function findElementByTestIdAndDoubleClick({ id, driver }) {
await delay(400);
await delayTime('medium');
const actions = driver.actions();
const element = await findElementByTestId({ id, driver });
return await actions.doubleClick(element).perform();
}

export async function waitUntilElementByTestIdIsPresent({ id, driver }) {
await delay(500);
await delayTime('medium');
const element = await findElementByTestId({ id, driver });
if (element) {
return;
Expand All @@ -191,14 +191,21 @@ export async function waitUntilElementByTestIdIsPresent({ id, driver }) {
}

export async function findElementByIdAndClick({ id, driver }) {
await delay(200);
await delayTime('short');
const element = await findElementById({ id, driver });
await waitAndClick(element, driver);
}
export async function waitAndClick(element, driver) {
await delayTime('short');
await driver.wait(until.elementIsVisible(element), waitUntilTime);
return element.click();
try {
await delayTime('short');
await driver.wait(until.elementIsVisible(element), waitUntilTime);
await driver.wait(until.elementIsEnabled(element), waitUntilTime);
return element.click();
} catch (error) {
throw new Error(
`Failed to click element ${await element.getAttribute('testid')}`,
);
}
}

export async function typeOnTextInput({ id, text, driver }) {
Expand Down Expand Up @@ -232,6 +239,55 @@ export const untilIsClickable = (locator: Locator) =>

// various functions and flows

export async function goBackTwice(driver) {
await delayTime('short');
await findElementByTestIdAndClick({
id: 'navbar-button-with-back',
driver,
});
await findElementByTestIdAndClick({
id: 'navbar-button-with-back',
driver,
});
}

export async function getNumberOfWallets(driver, testIdPrefix) {
let numOfWallets = 0;

for (let i = 1; ; i++) {
try {
const el = await driver.wait(
until.elementLocated(By.css(`[data-testid="${testIdPrefix}${i}"]`)),
5000,
);
await driver.wait(until.elementIsVisible(el), 5000);

numOfWallets += 1;
} catch (err) {
// Element not found, break out of loop
break;
}
}

return numOfWallets;
}

export async function navigateToSettingsPrivacy(driver, rootURL) {
await goToPopup(driver, rootURL, '#/home');
await findElementByTestIdAndClick({ id: 'home-page-header-right', driver });
await findElementByTestIdAndClick({ id: 'settings-link', driver });
await findElementByTestIdAndClick({ id: 'privacy-security-link', driver });
await delayTime('medium');
}

export async function toggleStatus(id: string, driver: WebDriver) {
const toggleInput = await driver.wait(
until.elementLocated(By.css(`[data-testid="${id}"] input`)),
);
const checkedStatus: string = await toggleInput.getAttribute('aria-checked');
return checkedStatus;
}

export function shortenAddress(address) {
// if address is 42 in length and starts with 0x, then shorten it
// otherwise return the base value. this is so it doesn't break incase an ens, etc is input
Expand Down
109 changes: 109 additions & 0 deletions e2e/parallel/settingsFlows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* eslint-disable no-await-in-loop */
import 'chromedriver';
import 'geckodriver';
import { WebDriver } from 'selenium-webdriver';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import {
findElementByTestId,
findElementByTestIdAndClick,
findElementByTextAndClick,
getExtensionIdByName,
goBackTwice,
importWalletFlow,
initDriverWithOptions,
navigateToSettingsPrivacy,
toggleStatus,
typeOnTextInput,
} from '../helpers';
import { TEST_VARIABLES } from '../walletVariables';

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

const browser = process.env.BROWSER || 'chrome';
const os = process.env.OS || 'mac';

describe('Navigate Settings & Privacy and its flows', () => {
beforeAll(async () => {
driver = await initDriverWithOptions({
browser,
os,
});
const extensionId = await getExtensionIdByName(driver, 'Rainbow');
if (!extensionId) throw new Error('Extension not found');
rootURL += extensionId;
});
afterAll(async () => await driver.quit());

it('should be able import a wallet via seed', async () => {
await importWalletFlow(driver, rootURL, TEST_VARIABLES.EMPTY_WALLET.SECRET);
});

it('should be able to toggle analytics', async () => {
await navigateToSettingsPrivacy(driver, rootURL);
// find toggle status and expect to be true
expect(await toggleStatus('analytics-toggle', driver)).toBe('true');

await findElementByTestIdAndClick({ id: 'analytics-toggle', driver });
expect(await toggleStatus('analytics-toggle', driver)).toBe('false');

await findElementByTestIdAndClick({ id: 'analytics-toggle', driver });
expect(await toggleStatus('analytics-toggle', driver)).toBe('true');
});

it('should be able to hide asset balances', async () => {
// find toggle status and expect to be false
expect(await toggleStatus('hide-assets-toggle', driver)).toBe('false');
// go home + check balance is shown
await goBackTwice(driver);
const balanceShown = await findElementByTestId({
id: 'balance-shown',
driver,
});
expect(balanceShown).toBeTruthy;
// toggle to true
await navigateToSettingsPrivacy(driver, rootURL);
await findElementByTestIdAndClick({ id: 'hide-assets-toggle', driver });
expect(await toggleStatus('hide-assets-toggle', driver)).toBe('true');
// go home + check balance hidden
await goBackTwice(driver);
const balanceHidden = await findElementByTestId({
id: 'balance-hidden',
driver,
});
expect(balanceHidden).toBeTruthy;
});

// bug currently exists on this flow. will remove skip once fixed.
it.skip('should be able to change password and then lock and unlock with it', async () => {
await navigateToSettingsPrivacy(driver, rootURL);

await findElementByTestIdAndClick({
id: 'change-password-button',
driver,
});
await typeOnTextInput({ id: 'password-input', driver, text: 'test1234' });
await findElementByTextAndClick(driver, 'Continue');
await typeOnTextInput({
id: 'new-password-input',
driver,
text: 'test5678',
});
await typeOnTextInput({
id: 'confirm-new-password-input',
driver,
text: 'test5678',
});
await findElementByTextAndClick(driver, 'Update Password');
await goBackTwice(driver);
await findElementByTestIdAndClick({
id: 'home-page-header-right',
driver,
});
await findElementByTestIdAndClick({ id: 'lock', driver });

await typeOnTextInput({ id: 'password-input', driver, text: 'test5678' });
await findElementByTestIdAndClick({ id: 'unlock-button', driver });
});
});
Loading

0 comments on commit b26a9c0

Please sign in to comment.