Skip to content

Commit 54a099c

Browse files
committed
MWPW-132336 Analytics tests for browser ext modal
1 parent 50f8af0 commit 54a099c

File tree

9 files changed

+135
-13
lines changed

9 files changed

+135
-13
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"homepage": "https://github.com/adobecom/college#readme",
2828
"devDependencies": {
2929
"@amwp/platform-ui-automation": "^0.0.3",
30-
"@amwp/platform-ui-lib-adobe": "^0.0.2",
30+
"@amwp/platform-ui-lib-adobe": "^0.0.3",
3131
"@babel/core": "7.17.7",
3232
"@babel/eslint-parser": "7.17.0",
3333
"@babel/register": "7.17.0",

test/e2e/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,24 @@ It can also compare the rendering of two different browers. For exmaple, the fol
3131

3232
```
3333
npx run test/e2e/frictionless -t "@visual and @gnav" -b webkit --baseBrowser firefox
34+
```
35+
36+
## Anaytics Test
37+
38+
An analytics test captures network post data to the service endpoints and verifies the events are as expected.
39+
40+
For example, the feature file `test/e2e/frictionless/features/smoke/analytics.feature` should have an analytics spec file `test/e2e/frictionless/features/smoke/analytics/analytics_spec.yml`
41+
42+
The command line should have the argument `--enableAnalytics` to turn on network logging
43+
44+
Chromium-based and Firefox browsers are supported. Currently Chromium has [the bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1058404), which causes some post data not captured. The workaround is to bypess Playwright and use a CDP session to retrieve post data.
45+
46+
```
47+
npx run test/e2e/frictionless -t "@smoke and @analytics" --enableAnalytics
48+
```
49+
50+
To debug analytics logs, add the argument `--printAnalyticsLogs` to dump collected logs.
51+
52+
```
53+
npx run test/e2e/frictionless -t "@smoke and @analytics" --enableAnalytics --printAnalyticsLogs
3454
```

test/e2e/frictionless/features/regression/analytics.feature

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,21 @@ Feature: Analytics - Frictionless Pages
1818
| pdf-to-ppt | verb-id=verb-pdf-to-ppt | test-files/test.pdf |
1919
| word-to-pdf | verb-id=verb-word-to-pdf | test-files/test.docx |
2020
| excel-to-pdf | verb-id=verb-excel-to-pdf | test-files/test.xlsx |
21-
| ppt-to-pdf | verb-id=verb-ppt-to-pdf | test-files/test.pptx |
21+
| ppt-to-pdf | verb-id=verb-ppt-to-pdf | test-files/test.pptx |
22+
23+
@MWPW-130084 @regression @analytics @extension
24+
Scenario Outline: Display the modal if Acrobat extension is not already installed
25+
Given I have a new browser context
26+
And I go to the <Verb> page
27+
And I resize the browser window to 1366x768
28+
When I upload the file "<File>"
29+
And I wait for the conversion
30+
Then I should see a modal promoting the browser extension
31+
When I dismiss the extension modal
32+
And I wait for 3 seconds
33+
And I read expected analytics data with replacements "browser"
34+
Then I should see analytics data posted within all logs matched with "Close the extension modal"
35+
36+
Examples:
37+
| Verb | File |
38+
| excel-to-pdf | test-files/test.xlsx |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Page load:
2+
- c.digitalData.primaryEvent.eventInfo.eventName: acrobat:<verb-id>:dropzone:shown
3+
- c.digitalData.primaryEvent.eventInfo.eventName: acrobat:<verb-id>:landing:shown
4+
- c.digitalData.primaryEvent.eventInfo.eventName: productRating
5+
6+
Download:
7+
- c.digitalData.primaryEvent.eventInfo.eventName: acrobat:<verb-id>:complete:download-success
8+
9+
Leave a review:
10+
- c.digitalData.primaryEvent.eventInfo.interaction.comment: <comment>
11+
- c.digitalData.primaryEvent.eventInfo.interaction.rating: <rating>
12+
13+
Close the extension modal:
14+
- c.digitalData.primaryEvent.eventInfo.eventName: Get the extension-1|viewer-extension|<browser>-extension
15+
- c.digitalData.primaryEvent.eventInfo.eventName: Get the extension-1|close-viewer-extension|<browser>-extension
16+
- c.digitalData.primaryEvent.eventInfo.eventName: Get the extension-1|already-closed-viewer-extension|<browser>-extension
17+

test/e2e/frictionless/features/smoke/analytics.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ Feature: Analytics - Frictionless Pages
66
@MWPW-130083 @smoke @analytics
77
Scenario Outline: Analytics - Frictionless page load
88
Given I go to the <Verb> page
9-
Then I load expected analytics data from wiki page "2871483205" with replacements "<Replacements>"
10-
Then I upload the file "test-files/test.pdf"
11-
Then I download the converted file
129
Then I wait for 3 seconds
10+
Then I read expected analytics data with replacements "<Replacements>"
1311
And I should see analytics data posted within all logs matched with "Page load"
1412

1513
Examples:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Page load:
2+
- c.digitalData.primaryEvent.eventInfo.eventName: acrobat:<verb-id>:dropzone:shown
3+
- c.digitalData.primaryEvent.eventInfo.eventName: acrobat:<verb-id>:landing:shown
4+
- c.digitalData.primaryEvent.eventInfo.eventName: productRating
5+
6+
Download:
7+
- c.digitalData.primaryEvent.eventInfo.eventName: acrobat:<verb-id>:complete:download-success
8+
9+
Leave a review:
10+
- c.digitalData.primaryEvent.eventInfo.interaction.comment: <comment>
11+
- c.digitalData.primaryEvent.eventInfo.interaction.rating: <rating>

test/e2e/frictionless/page-objects/frictionless.page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class FrictionlessPage extends classes(DcGnavPage, PdfWidgetSection) {
2929
reviewCommentSubmit: '.hlx-Review-commentFields input[type="submit"]',
3030
reviewInputField: 'fieldset.hlx-Review-ratingFields input',
3131
signUp: '[href*="https://auth.services.adobe.com"][href*="signup"]',
32-
extensionModal: '#chromeext',
33-
closeExtensionModal: '#chromeext .dialog-close',
32+
extensionModal: '#chromeext, #edgeext',
33+
closeExtensionModal: '#chromeext .dialog-close, #edgeext .dialog-close',
3434
});
3535
}
3636

test/e2e/frictionless/step-definitions/dc.steps.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,46 @@ import { expect } from "@playwright/test";
2626
const os = require("os");
2727
const path = require("path");
2828
const fs = require("fs");
29+
const YAML = require('js-yaml');
2930
import { getComparator } from 'playwright-core/lib/utils';
3031

3132
async function enableNetworkLogging(page) {
3233
if (global.config.profile.enableAnalytics) {
33-
let networklogs = [];
34+
const networklogs = [];
3435
page.networklogs = networklogs;
36+
3537
console.log('Before all tests: Enable network logging');
38+
3639
// Enable network logging
40+
if (/chromium|msedge|chrome/.test(global.config.profile.browser)) {
41+
const client = await page.native.context().newCDPSession(page.native);
42+
await client.send('Network.enable');
43+
const handleNetworkRequest = async (x) => {
44+
if ('hasPostData' in x.request) {
45+
if (!x.request.postData) {
46+
try {
47+
const res = await client.send('Network.getRequestPostData', { requestId: x.requestId });
48+
x.request.postData = res.postData;
49+
} catch (err) {
50+
console.log(err);
51+
}
52+
}
53+
networklogs.push({
54+
url: () => x.request.url,
55+
postData: () => x.request.postData,
56+
});
57+
}
58+
};
59+
60+
client.on('Network.requestWillBeSent', handleNetworkRequest);
61+
} else {
3762
await page.native.route('**', (route) => {
38-
const url = route.request().url();
3963
networklogs.push(route.request());
4064
route.continue();
4165
});
4266
}
4367
}
68+
}
4469

4570
Then(/^I have a new browser context$/, async function () {
4671
PW.context = await PW.browser.newContext(PW.contextOptions);
@@ -341,3 +366,37 @@ Then(/^I switch to the new page after clicking "Buy now" button in the header$/,
341366
this.page.native = newPage;
342367
});
343368

369+
Then(/^I read expected analytics data with replacements "([^"]*)"$/, async function (replacements) {
370+
const baseDir = this.gherkinDocument.uri.replace('.feature', '');
371+
372+
let ymlRaw = fs.readFileSync(`${baseDir}/analytics_spec.yml`, 'utf8');
373+
374+
const kvs = replacements.split(',').map((x) => x.trim());
375+
for (const kv of kvs) {
376+
const keyValue = kv.split('=').map((x) => x.trim());
377+
if (keyValue.length === 1) {
378+
if (keyValue[0] === 'browser') {
379+
keyValue.push({chromium: 'Chrome', chrome: 'Chrome', msedge: 'MSFT-Edge'}[global.config.profile.browser]);
380+
}
381+
}
382+
ymlRaw = ymlRaw.replace(new RegExp(`<${keyValue[0]}>`, 'g'), keyValue[1]);
383+
}
384+
385+
const events = YAML.load(ymlRaw);
386+
for (const event in events) {
387+
const normalizeLogs = [];
388+
if (events[event]) {
389+
for (const log of events[event]) {
390+
const normalizeLog = {};
391+
for (const key in log) {
392+
normalizeLog.key = key;
393+
normalizeLog.value = log[key];
394+
}
395+
normalizeLogs.push(normalizeLog);
396+
}
397+
}
398+
events[event] = normalizeLogs;
399+
}
400+
401+
this.page.wikiAnalyticsData = events;
402+
});

0 commit comments

Comments
 (0)