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

Add full parameters for emulateNetworkConditions #24144

Merged
merged 2 commits into from
Aug 4, 2020
Merged
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
12 changes: 10 additions & 2 deletions docs/contributors/testing-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,18 @@ THROTTLE_CPU=4 npm run test-e2e
Related: https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-setCPUThrottlingRate

```
DOWNLOAD_THROUGHPUT=125000 npm run test-e2e
SLOW_NETWORK=true npm run test-e2e
```

`DOWNLOAD_THROUGHPUT` is a numeric value representing bytes-per-second network download (in this example, a 1Mbps download speed).
`SLOW_NETWORK` emulates a network speed equivalent to "Fast 3G" in the Chrome devtools.

Related: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions and https://github.com/ChromeDevTools/devtools-frontend/blob/80c102878fd97a7a696572054007d40560dcdd21/front_end/sdk/NetworkManager.js#L252-L274

```
OFFLINE=true npm run test-e2e
```

`OFFLINE` emulates network disconnection.

Related: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions

Expand Down
24 changes: 19 additions & 5 deletions packages/e2e-tests/config/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ const THROTTLE_CPU = process.env.THROTTLE_CPU;
*
* @type {string|undefined}
*/
const DOWNLOAD_THROUGHPUT = process.env.DOWNLOAD_THROUGHPUT;
const SLOW_NETWORK = process.env.SLOW_NETWORK;

/**
* Emulate no internet connection.
*
* @type {string|undefined}
*/
const OFFLINE = process.env.OFFLINE;

/**
* Set of console logging types observed to protect against unexpected yet
Expand Down Expand Up @@ -213,17 +220,24 @@ async function runAxeTestsForBlockEditor() {
* Simulate slow network or throttled CPU if provided via environment variables.
*/
async function simulateAdverseConditions() {
if ( ! DOWNLOAD_THROUGHPUT && ! THROTTLE_CPU ) {
if ( ! SLOW_NETWORK && ! OFFLINE && ! THROTTLE_CPU ) {
return;
}

const client = await page.target().createCDPSession();

if ( DOWNLOAD_THROUGHPUT ) {
if ( SLOW_NETWORK || OFFLINE ) {
// See: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions
// The values below simulate fast 3G conditions as per https://github.com/ChromeDevTools/devtools-frontend/blob/80c102878fd97a7a696572054007d40560dcdd21/front_end/sdk/NetworkManager.js#L252-L274
await client.send( 'Network.emulateNetworkConditions', {
// Simulated download speed (bytes/s)
downloadThroughput: Number( DOWNLOAD_THROUGHPUT ),
// Network connectivity is absent
offline: Boolean( OFFLINE || false ),
// Download speed (bytes/s)
downloadThroughput: ( ( 1.6 * 1024 * 1024 ) / 8 ) * 0.9,
// Upload speed (bytes/s)
uploadThroughput: ( ( 750 * 1024 ) / 8 ) * 0.9,
// Latency (ms)
latency: 150 * 3.75,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These numbers (particularly 150 and 0.9) are a bit "magic" so I think let's link to https://github.com/ChromeDevTools/devtools-frontend/blob/80c102878fd97a7a696572054007d40560dcdd21/front_end/sdk/NetworkManager.js#L252-L274 in an inline comment.

} );
}

Expand Down