-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: use network events from pw #488
feat: use network events from pw #488
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, just had small nits.
Also, can you confirm the testing method below is what we need in order to consider this change to have been E2E tested?
- Create an HTML file with an
a
tag that opens a popup with another HTML page in a new tab. - This new popup must contain some code to immediately close it and take some time to reach the
networkidle
state (ideally) - The agent should not throw an error.
- There should be network data for the opened popup (it should show any script requests from that popup) (easy to see with
--rich-events
).
I've followed testing steps at #253 with slight modifications:
popup1.html
<html> <head> </head> <body> Test popup page 1 <p><a href="popup2.html" onclick="return !window.open(this.href, 'Test Page', 'width=500,height=500')" target="_blank" id="linkWithPopup">Click</a> here (id=linkWithPopup) to open - Test Page - popup window</p> <p><a href="popup2.html" target="_blank" id="linkWithPopupNoNewWindow">Click</a> here (id=linkWithPopupNoNewWindow) to open - Test Page - new tab (not new window)</p> </body> </html>
popup2.html
<html> <head> <script src="https://google.com"></script> </head> <body> Test popup page 2 </body> </html>
example.journey.ts
// Replace the import here for the original package or the built branch to test const { journey, step } = require('../dist/index'); const { deepStrictEqual } = require('assert'); const { join } = require('path'); journey('Popup Test', async ({ page }) => { step('Popup Landing Page', async () => { const path = 'file://' + join(__dirname, '.', 'popup1.html'); await page.goto(path); await page.waitForSelector('text=Test popup page 1'); }); step('Open Popup', async () => { const [popup] = await Promise.all([ page.waitForEvent('popup'), page.click('#linkWithPopup'), ]); // Test 2 - new tab (not new popup window) //await page.click('#linkWithPopupNoNewWindow'); await popup.waitForSelector('text=Test popup page 2'); }); step('test', async () => { await new Promise(resolve => setTimeout(resolve, 5000)); }); });
Then, to run and check network data:
synthetics --rich-events ./ | jq -c 'select(.type == "journey/network_info")'
Do you think that would be a satisfactory test?
); | ||
// Guard aganist pages that gets closed before the emulation kicks in | ||
Promise.race([ | ||
new Promise<void>(resolve => page.on('close', () => resolve())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Promise<void>(resolve => page.on('close', () => resolve())), | |
new Promise<void>(resolve => page.on('close', resolve)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its done to satisfy the void type. Otherwise Page
object will be resolved which is not the intention here.
@lucasfcosta Thanks for the review, yeah the test details provided by Paul should suffice for the popup scenario and we dont need to explicity test for the barrier case as the unit tests catches that. But we need an E2E with HB and Kibana to check if everything looks fine on the Kibana side as the PR touches lots of network data. |
Missing data
http.version
data is not exposed, but we can add that as a follow up once PW adds support for it and we are not using it on the waterfall UI.