Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: centralize e2e test setup and env config #497

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PASSWORD=aaaaaaa
RECOVERY_WORDS=bbbbbbb
E2E_CHROMIUM_HEADLESS = false
E2E_CHROMIUM_HEADLESS=false
TEST_ENV=dev
27 changes: 27 additions & 0 deletions e2e/conf/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { chromium, BrowserContext } from "playwright";
import { URL } from './configuration';

/**
* Creates a browser context with MetaMask extension loaded
* @returns {Promise<BrowserContext>} Configured browser context
*/
export async function createBrowserContext(): Promise<BrowserContext> {
const extensionPath = require('path').join(__dirname, '../extension-source');
const headless = process.env.E2E_CHROMIUM_HEADLESS === 'true';

return await chromium.launchPersistentContext('', {
headless,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
}

/**
* Returns the appropriate test URL based on environment
* @returns {string} Test environment URL
*/
export function getTestUrl(): string {
return process.env.TEST_ENV === 'prod' ? URL.PROD : URL.DEV;
}
15 changes: 3 additions & 12 deletions e2e/tests/account-details-display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@ import { chromium, BrowserContext } from "playwright";
import { test, expect } from '@playwright/test';
import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to show account address details', () => {
let browserContext: BrowserContext;
let metaMaskPage: MetaMaskPage;
let applicationPage: DappPage;

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -39,8 +31,7 @@ test.describe('Starknet dapp should be able to show account address details', ()
await applicationPage.page.bringToFront();
await applicationPage.page.waitForTimeout(1000);

// TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();
await applicationPage.page.waitForSelector('//*[contains(text(),"Send")]', {timeout: 90000});
Expand Down
25 changes: 6 additions & 19 deletions e2e/tests/account-view-explorer.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { chromium, BrowserContext } from "playwright";
import { BrowserContext } from "playwright";
import { test, expect } from '@playwright/test';
import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to show account on voyager explorer', () => {
let browserContext: BrowserContext;
let metaMaskPage: MetaMaskPage;
let applicationPage: DappPage;

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -39,8 +31,7 @@ test.describe('Starknet dapp should be able to show account on voyager explorer'
await applicationPage.page.bringToFront();
await applicationPage.page.waitForTimeout(1000);

// TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();
await applicationPage.page.waitForSelector('//*[contains(text(),"Send")]', {timeout: 90000});
Expand All @@ -49,12 +40,8 @@ test.describe('Starknet dapp should be able to show account on voyager explorer'
await applicationPage.page.bringToFront();
await applicationPage.page.waitForTimeout(1000);
await applicationPage.checkCopyAddress();
await applicationPage.checkAccountInfo();

// Check view on explorer link for account
await applicationPage.clickViewOnExplorerLink();
const [accountPage] = await Promise.all([browserContext.waitForEvent('page')]);
expect(accountPage.url()).toContain('/voyager.online/contract/0x');
await accountPage.close()
// Check user can view account on voyager explorer
await applicationPage.checkViewOnExplorer();
});
});
14 changes: 3 additions & 11 deletions e2e/tests/add-token-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { test } from '@playwright/test';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to add token and should be able to recover the account', () => {
let browserContext: BrowserContext;
let metaMaskPage: MetaMaskPage;
let applicationPage: DappPage;

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -39,8 +32,7 @@ test.describe('Starknet dapp should be able to add token and should be able to r
await applicationPage.page.bringToFront();
await applicationPage.page.waitForTimeout(1000);

// TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();
await applicationPage.page.bringToFront();
Expand Down
12 changes: 3 additions & 9 deletions e2e/tests/connect-disconnect-metamask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { test, expect } from '@playwright/test';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to connect and disconnect to MetaMask flask', () => {
let browserContext: BrowserContext;
Expand All @@ -11,14 +12,7 @@ test.describe('Starknet dapp should be able to connect and disconnect to MetaMas

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -42,7 +36,7 @@ test.describe('Starknet dapp should be able to connect and disconnect to MetaMas
await applicationPage.page.waitForTimeout(1000);

//TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();

Expand Down
12 changes: 3 additions & 9 deletions e2e/tests/export-private-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { test } from '@playwright/test';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to show account private key', () => {
let browserContext: BrowserContext;
Expand All @@ -11,14 +12,7 @@ test.describe('Starknet dapp should be able to show account private key', () =>

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -40,7 +34,7 @@ test.describe('Starknet dapp should be able to show account private key', () =>
await applicationPage.page.waitForTimeout(1000);

// TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();
await applicationPage.page.bringToFront();
Expand Down
17 changes: 4 additions & 13 deletions e2e/tests/initial-display.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import { chromium, BrowserContext } from "playwright";
import { BrowserContext } from "playwright";
import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { test, expect } from '@playwright/test';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to initilize account and have correct homepage display', () => {
let browserContext: BrowserContext;
let metaMaskPage: MetaMaskPage;
let applicationPage: DappPage;

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -39,8 +31,7 @@ test.describe('Starknet dapp should be able to initilize account and have correc
await applicationPage.page.bringToFront();
await applicationPage.page.waitForTimeout(1000);

//TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();
await applicationPage.page.bringToFront();
Expand Down
14 changes: 3 additions & 11 deletions e2e/tests/send-receive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ import MetaMaskPage from "../utils/MetaMaskPage";
import DappPage from "../utils/DappPage";
import { URL } from '../conf/configuration';
import { test } from '@playwright/test';
import { createBrowserContext, getTestUrl } from '../conf/test-helpers';

test.describe('Starknet dapp should be able to send and receive token', () => {
let browserContext: BrowserContext;
let metaMaskPage: MetaMaskPage;
let applicationPage: DappPage;

//TODO: Put the beforeEach in config file that all tests can use
test.beforeEach(async () => {
const extensionPath = require('path').join(__dirname, '../extension-source')
browserContext = await chromium.launchPersistentContext('', {
headless: false,
args: [
`--disable-extensions-except=${extensionPath}`,
`--load-extension=${extensionPath}`
]
});
browserContext = await createBrowserContext();
});

test.afterEach(async () => {
Expand All @@ -39,8 +32,7 @@ test.describe('Starknet dapp should be able to send and receive token', () => {
await applicationPage.page.bringToFront();
await applicationPage.page.waitForTimeout(1000);

// TODO: Put the DEV parameter in environmental variable
await applicationPage.page.goto(URL.DEV);
await applicationPage.page.goto(getTestUrl());
await applicationPage.clickConnectButton();
await metaMaskPage.confirmConnectUI();
await applicationPage.page.bringToFront();
Expand Down
Loading