Skip to content

Commit

Permalink
test(extension): lw-4700 analytics interception spike
Browse files Browse the repository at this point in the history
  • Loading branch information
bslabiak committed Jun 2, 2023
1 parent 1998185 commit a45ff2d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/e2e-tests/package.json
Expand Up @@ -35,6 +35,7 @@
"@wdio/spec-reporter": "8.8.6",
"@wdio/types": "8.8.6",
"@wdio/devtools-service": "8.8.6",
"wdio-intercept-service": "4.4.0",
"allure-commandline": "^2.21.0",
"clipboardy": "2.3.0",
"eslint": "8.38.0",
Expand Down
@@ -0,0 +1,33 @@
@SendSimpleTransaction-Extended-E2E @Testnet
Feature: Analytics

Background:
Given Wallet is synced

@wip
Scenario: Extended View - Send transaction goal event analytics
And I set up request interception for 5 matomo analytics request(s)
And I click "Send" button on page header
And I validate latest analytics request(s) information:
| Event Category | Event Action | Event Name |
| send-transaction | click-event | send-tx-button-browser |
And I fill bundle 1 with "WalletReceiveSimpleTransactionE2E" address with following assets:
| type | assetName | ticker | amount |
| ADA | Cardano | tADA | 1.1234 |
And I click "Review transaction" button on "Send" page
And I validate latest analytics request(s) information:
| Event Category | Event Action | Event Name |
| send-transaction | click-event | review-tx-details-browser |
And I click "Confirm" button on "Transaction summary" page
And I validate latest analytics request(s) information:
| Event Category | Event Action | Event Name |
| send-transaction | click-event | confirm-tx-details-browser |
And I fill correct password and confirm
And I validate latest analytics request(s) information:
| Event Category | Event Action | Event Name |
| send-transaction | click-event | input-tx-password-browser |
| send-transaction | click-event | tx-success-browser |
Then I validate existence and number of expected analytics request(s)



2 changes: 2 additions & 0 deletions packages/e2e-tests/src/hooks/scenarioTagRunner.ts
Expand Up @@ -5,6 +5,7 @@ import testContext from '../utils/testContext';
import { clearBackgroundStorageKey } from '../utils/browserStorage';
import { closeAllTabsExceptOriginalOne } from '../utils/window';
import networkManager from '../utils/networkManager';
import { browser } from '@wdio/globals';

// eslint-disable-next-line no-unused-vars
Before(async () => {
Expand All @@ -13,6 +14,7 @@ Before(async () => {

After(async () => {
await networkManager.closeOpenedCdpSessions();
await browser.disableInterceptor();
testContext.clearContext();
await clearBackgroundStorageKey(); // FIXME: does not work for onboarding scenarios - error is thrown
await localStorageManager.cleanLocalStorage();
Expand Down
35 changes: 35 additions & 0 deletions packages/e2e-tests/src/steps/analyticsSteps.ts
@@ -0,0 +1,35 @@
import { DataTable, When } from '@cucumber/cucumber';
import { URLSearchParams } from 'url';
import { expect } from 'chai';
import { browser } from '@wdio/globals';

export const getRequestInLatestOrderParams = async (requestIndexInLatestOrder: number): Promise<URLSearchParams> => {
const requests = await browser.getRequests({ includePending: true, orderBy: 'START' });
const decodedLatestRequestUrl = decodeURIComponent(requests[requests.length - 1 - requestIndexInLatestOrder].url);
return new URLSearchParams(decodedLatestRequestUrl.split('?')[1]);
};

When(/^I set up request interception for (\d) matomo analytics request\(s\)$/, async (numberOfRequest: number) => {
await browser.setupInterceptor();
await browser.excludeUrls([new RegExp('^(?!https://matomo).*')]);
for (let i = 0; i < numberOfRequest; i++) {
await browser.expectRequest('GET', new RegExp('^https://matomo.*'), 200);
}
});

When(/^I validate latest analytics request\(s\) information:$/, async (eventInfo: DataTable) => {
await browser.pause(1000);
for (let i = 0; i < eventInfo.rows().length; i++) {
const requestIndexInLatestOrder = eventInfo.rows().length - 1 - i;
const actualEventInfo = await getRequestInLatestOrderParams(requestIndexInLatestOrder);
const [expectedEventCategory, expectedEventAction, expectedEventName] = eventInfo.rows()[i];
expect(actualEventInfo.get('e_c')).to.equal(expectedEventCategory);
expect(actualEventInfo.get('e_a')).to.equal(expectedEventAction);
expect(actualEventInfo.get('e_n')).to.equal(expectedEventName);
}
});

When(/^I validate existence and number of expected analytics request\(s\)$/, async () => {
await browser.assertRequests();
await browser.disableInterceptor();
});
3 changes: 2 additions & 1 deletion packages/e2e-tests/tsconfig.json
Expand Up @@ -8,7 +8,8 @@
"@wdio/cucumber-framework",
"expect-webdriverio",
"chai",
"@wdio/devtools-service"
"@wdio/devtools-service",
"wdio-intercept-service"
],
"lib": [
"es2015",
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-tests/wdio.conf.chrome.ts
Expand Up @@ -36,7 +36,7 @@ const chromeConfig: WebdriverIO.Config = {
}
}
],
services: ['devtools']
services: ['devtools', 'intercept']
};

if (!process.env.CI) {
Expand All @@ -48,7 +48,8 @@ if (!process.env.CI) {
args: { drivers }
}
],
'devtools'
'devtools',
'intercept'
];
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -32778,6 +32778,11 @@ wcwidth@^1.0.0, wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

wdio-intercept-service@4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/wdio-intercept-service/-/wdio-intercept-service-4.4.0.tgz#8f20d8c75c91aef2a0c27b30a6c51e5d3a389db2"
integrity sha512-9ao5WVTWmr/NEOTwqHNvYPso7Ygzx+PvITaZvYvC5RPXlGv1LPdDdP+WCGzwDlvqdOaty7Nko5BfJDyuBscH7A==

web-namespaces@^1.0.0:
version "1.1.4"
resolved "https://registry.yarnpkg.com/web-namespaces/-/web-namespaces-1.1.4.tgz#bc98a3de60dadd7faefc403d1076d529f5e030ec"
Expand Down

0 comments on commit a45ff2d

Please sign in to comment.