Skip to content

Commit

Permalink
test(all): add service worker log capture (#1468)
Browse files Browse the repository at this point in the history
* test(all): add service worker log capture
* test(all): capture all log levels for service worker logs
  • Loading branch information
ljagiela authored Oct 17, 2024
1 parent 14a7d53 commit f097f64
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/actions/test/e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ runs:
BROWSER: ${{ inputs.BROWSER }}
DISPLAY: ${{ inputs.DISPLAY }}
BATCH: ${{ inputs.BATCH }}
SERVICE_WORKER_LOGS: true
run: |
commonTags="@Testnet and not @Pending"
tagsToRun="'${commonTags}'"
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ UI-mapped gherkin tests for the Lace browser extension
environment variable)
- `TEST_DAPP_URL=<url>`(required)
- url for test DApp (only for DApp Connector tests)
- `SERVICE_WORKER_LOGS=true|false` default=false (optional)
- enables service worker logs collection

## Run single feature file with params

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/src/assert/walletAddressPageAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WalletAddressPageAssert {
}
await WalletAddressPage.drawerHeaderCloseButton.waitForDisplayed();
await WalletAddressPage.drawerHeaderSubtitle.waitForDisplayed();
expect(await WalletAddressPage.drawerHeaderSubtitle.getText()).to.equal(
expect(await WalletAddressPage.drawerHeaderSubtitle.getText()).contains(
await t('qrInfo.scanQRCodeToConnectWallet')
);
await WalletAddressPage.qrCode.waitForDisplayed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Wallet accounts
When I click the menu button
And I click on chevron for wallet number 1
Then "Accounts" menu is displayed
And I see 24 accounts on the list
And I see 50 accounts on the list
And each account item contains icon, logo and path

@LW-9299
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Wallet accounts
When I click the menu button
And I click on chevron for wallet number 1
Then "Accounts" menu is displayed
And I see 24 accounts on the list
And I see 50 accounts on the list
And each account item contains icon, logo and path

@LW-9319
Expand Down
18 changes: 16 additions & 2 deletions packages/e2e-tests/src/hooks/scenarioTagRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { browser } from '@wdio/globals';
import consoleManager from '../utils/consoleManager';

import { clearWalletRepository } from '../fixture/walletRepositoryInitializer';
import allure from '@wdio/allure-reporter';

// eslint-disable-next-line no-unused-vars
Before(async () => {
// use Before hooks in feature steps file, see AddressBook.ts as an example
if (String(process.env.SERVICE_WORKER_LOGS) === 'true') {
await consoleManager.startLogsCollection();
}
});

After({ tags: 'not @Pending and not @pending' }, async () => {
Expand All @@ -27,5 +30,16 @@ After({ tags: 'not @Pending and not @pending' }, async () => {
});

AfterStep(async (scenario) => {
if (scenario.result.status === 'FAILED') await browser.takeScreenshot();
if (scenario.result.status === 'FAILED') {
await browser.takeScreenshot();

if (String(process.env.SERVICE_WORKER_LOGS) === 'true') {
const logs = await consoleManager.getLogsAsString();
if (logs !== undefined) {
allure.addAttachment('Service worker logs', logs, 'text/plain');
}
}
await consoleManager.clearLogs();
await consoleManager.closeOpenedCdpSessions();
}
});
13 changes: 10 additions & 3 deletions packages/e2e-tests/src/utils/consoleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export class ConsoleManager {
ConsoleManager.cdpSessions.push(client);
await client.send(this.CONSOLE_ENABLE);
client.on('Console.messageAdded', async (entry: any) => {
if (entry.message.level !== 'debug') {
ConsoleManager.capturedLogs.push(entry.message);
}
ConsoleManager.capturedLogs.push(entry.message);
});
});
});
Expand All @@ -42,6 +40,15 @@ export class ConsoleManager {
};

getLogs = async (): Promise<ConsoleLogEntry[]> => ConsoleManager.capturedLogs;

getLogsAsString = async (): Promise<string | undefined> => {
let logs;
for (const log of ConsoleManager.capturedLogs) {
logs = `${logs} ${JSON.stringify(log)}`;
}
return logs;
};

closeOpenedCdpSessions = async (): Promise<void> => {
await this.clearLogs();
ConsoleManager.cdpSessions.map(async (session) => {
Expand Down

0 comments on commit f097f64

Please sign in to comment.