-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[FTR] Implement browser network condition utils #163633
[FTR] Implement browser network condition utils #163633
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
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.
Core changes LGTM
Tested locally. Code LGTM. |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
💔 Some backports could not be created
Note: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
## 📓 Summary The PR implements some utilities into the `browser` service to allow controlling the network conditions during the execution of a functional test. ### `getNetworkConditions` Returns the current network simulation options. If none conditions are previously set, it returns `undefined` **N.B.**: _if the testing environment is not a Chromium browser, it throws an error that can be easily caught to manually skip the test or handle a fallback scenario._ ```ts it('should display a loading skeleton while loading', async function () { // Skip the test in case network condition utils are not available try { const networkConditions = await browser.getNetworkConditions(); // undefined await browser.setNetworkConditions('SLOW_3G'); const networkConditions = await browser.getNetworkConditions(); // { // offline: false, // latency: 2000, // download_throughput: 50000, // upload_throughput: 50000, // } } catch (error) { this.skip(); } }); ``` ### `setNetworkConditions` Set the desired network conditions. It supports different presets that match the [network profiles provided by Chrome debugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393): - `NO_THROTTLING` - `FAST_3G` - `SLOW_3G` - `OFFLINE` - `CLOUD_USER` (pre-existing) It also accepts ad-hoc options to configure more specifically the network conditions. **N.B.**: _if the testing environment is not a Chromium browser, it throws an error that can be easily caught to manually skip the test or handle a fallback scenario._ ```ts it('should display a loading skeleton while loading', async function () { // Skip the test in case network condition utils are not available try { await browser.setNetworkConditions('NO_THROTTLING'); await browser.setNetworkConditions('FAST_3G'); await browser.setNetworkConditions('SLOW_3G'); await browser.setNetworkConditions('OFFLINE'); await browser.setNetworkConditions('CLOUD_USER'); await browser.setNetworkConditions({ offline: false, latency: 5, // Additional latency (ms). download_throughput: 500 * 1024, // Maximal aggregated download throughput. upload_throughput: 500 * 1024, // Maximal aggregated upload throughput. }); } catch (error) { this.skip(); } }); ``` ### restoreNetworkConditions Restore the original network conditions, setting to `NO_THROTTLING`. The native implementation of `deleteNetworkConditions` exposed by selenium is unofficial and didn't consistently work, the recommended approach by the google dev tools team is to restore the connection setting the no throttling profile. **N.B.**: _if the testing environment is not a Chromium browser, it throws an error that can be easily caught to manually skip the test or handle a fallback scenario._ ```ts it('should display a loading skeleton while loading', async function () { // Skip the test in case network condition utils are not available try { await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions // Do your assertions await browser.restoreNetworkConditions(); // Restore network conditions } catch (error) { this.skip(); } }); ``` Co-authored-by: Marco Antonio Ghiani <[email protected]> Co-authored-by: Dzmitry Lemechko <[email protected]> (cherry picked from commit aa45152)
@dmlemeshko Do we need to backport this to 7.17 too? Being an enhancement and not a fix, shouldn't exist any test requiring these new methods. UPDATE: I fixed the conflicts and created the backport anyway, I guess won't hurt having these utils in 7.17 too. |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
) # Backport This will backport the following commits from `main` to `8.9`: - [[FTR] Implement browser network condition utils (#163633)](#163633) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Marco Antonio Ghiani","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-11T12:24:06Z","message":"[FTR] Implement browser network condition utils (#163633)\n\n## 📓 Summary\r\n\r\nThe PR implements some utilities into the `browser` service to allow\r\ncontrolling the network conditions during the execution of a functional\r\ntest.\r\n\r\n### `getNetworkConditions`\r\n\r\nReturns the current network simulation options. If none conditions are\r\npreviously set, it returns `undefined`\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n const networkConditions = await browser.getNetworkConditions(); // undefined\r\n\r\n await browser.setNetworkConditions('SLOW_3G');\r\n\r\n const networkConditions = await browser.getNetworkConditions();\r\n // {\r\n // offline: false,\r\n // latency: 2000,\r\n // download_throughput: 50000,\r\n // upload_throughput: 50000,\r\n // }\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### `setNetworkConditions`\r\n\r\nSet the desired network conditions.\r\nIt supports different presets that match the [network profiles provided\r\nby Chrome\r\ndebugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393):\r\n- `NO_THROTTLING`\r\n- `FAST_3G`\r\n- `SLOW_3G`\r\n- `OFFLINE`\r\n- `CLOUD_USER` (pre-existing)\r\nIt also accepts ad-hoc options to configure more specifically the\r\nnetwork conditions.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('NO_THROTTLING');\r\n await browser.setNetworkConditions('FAST_3G');\r\n await browser.setNetworkConditions('SLOW_3G');\r\n await browser.setNetworkConditions('OFFLINE');\r\n await browser.setNetworkConditions('CLOUD_USER');\r\n await browser.setNetworkConditions({\r\n offline: false,\r\n latency: 5, // Additional latency (ms).\r\n download_throughput: 500 * 1024, // Maximal aggregated download throughput.\r\n upload_throughput: 500 * 1024, // Maximal aggregated upload throughput.\r\n });\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### restoreNetworkConditions\r\n\r\nRestore the original network conditions, setting to `NO_THROTTLING`.\r\nThe native implementation of `deleteNetworkConditions` exposed by\r\nselenium is unofficial and didn't consistently work, the recommended\r\napproach by the google dev tools team is to restore the connection\r\nsetting the no throttling profile.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions\r\n \r\n // Do your assertions\r\n\r\n await browser.restoreNetworkConditions(); // Restore network conditions\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\nCo-authored-by: Marco Antonio Ghiani <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"aa45152a4e787f36014675b864fcc0fce7bd6758","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.10.0","v7.17.13","v8.9.2"],"number":163633,"url":"https://github.com/elastic/kibana/pull/163633","mergeCommit":{"message":"[FTR] Implement browser network condition utils (#163633)\n\n## 📓 Summary\r\n\r\nThe PR implements some utilities into the `browser` service to allow\r\ncontrolling the network conditions during the execution of a functional\r\ntest.\r\n\r\n### `getNetworkConditions`\r\n\r\nReturns the current network simulation options. If none conditions are\r\npreviously set, it returns `undefined`\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n const networkConditions = await browser.getNetworkConditions(); // undefined\r\n\r\n await browser.setNetworkConditions('SLOW_3G');\r\n\r\n const networkConditions = await browser.getNetworkConditions();\r\n // {\r\n // offline: false,\r\n // latency: 2000,\r\n // download_throughput: 50000,\r\n // upload_throughput: 50000,\r\n // }\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### `setNetworkConditions`\r\n\r\nSet the desired network conditions.\r\nIt supports different presets that match the [network profiles provided\r\nby Chrome\r\ndebugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393):\r\n- `NO_THROTTLING`\r\n- `FAST_3G`\r\n- `SLOW_3G`\r\n- `OFFLINE`\r\n- `CLOUD_USER` (pre-existing)\r\nIt also accepts ad-hoc options to configure more specifically the\r\nnetwork conditions.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('NO_THROTTLING');\r\n await browser.setNetworkConditions('FAST_3G');\r\n await browser.setNetworkConditions('SLOW_3G');\r\n await browser.setNetworkConditions('OFFLINE');\r\n await browser.setNetworkConditions('CLOUD_USER');\r\n await browser.setNetworkConditions({\r\n offline: false,\r\n latency: 5, // Additional latency (ms).\r\n download_throughput: 500 * 1024, // Maximal aggregated download throughput.\r\n upload_throughput: 500 * 1024, // Maximal aggregated upload throughput.\r\n });\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### restoreNetworkConditions\r\n\r\nRestore the original network conditions, setting to `NO_THROTTLING`.\r\nThe native implementation of `deleteNetworkConditions` exposed by\r\nselenium is unofficial and didn't consistently work, the recommended\r\napproach by the google dev tools team is to restore the connection\r\nsetting the no throttling profile.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions\r\n \r\n // Do your assertions\r\n\r\n await browser.restoreNetworkConditions(); // Restore network conditions\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\nCo-authored-by: Marco Antonio Ghiani <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"aa45152a4e787f36014675b864fcc0fce7bd6758"}},"sourceBranch":"main","suggestedTargetBranches":["7.17","8.9"],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/163633","number":163633,"mergeCommit":{"message":"[FTR] Implement browser network condition utils (#163633)\n\n## 📓 Summary\r\n\r\nThe PR implements some utilities into the `browser` service to allow\r\ncontrolling the network conditions during the execution of a functional\r\ntest.\r\n\r\n### `getNetworkConditions`\r\n\r\nReturns the current network simulation options. If none conditions are\r\npreviously set, it returns `undefined`\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n const networkConditions = await browser.getNetworkConditions(); // undefined\r\n\r\n await browser.setNetworkConditions('SLOW_3G');\r\n\r\n const networkConditions = await browser.getNetworkConditions();\r\n // {\r\n // offline: false,\r\n // latency: 2000,\r\n // download_throughput: 50000,\r\n // upload_throughput: 50000,\r\n // }\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### `setNetworkConditions`\r\n\r\nSet the desired network conditions.\r\nIt supports different presets that match the [network profiles provided\r\nby Chrome\r\ndebugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393):\r\n- `NO_THROTTLING`\r\n- `FAST_3G`\r\n- `SLOW_3G`\r\n- `OFFLINE`\r\n- `CLOUD_USER` (pre-existing)\r\nIt also accepts ad-hoc options to configure more specifically the\r\nnetwork conditions.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('NO_THROTTLING');\r\n await browser.setNetworkConditions('FAST_3G');\r\n await browser.setNetworkConditions('SLOW_3G');\r\n await browser.setNetworkConditions('OFFLINE');\r\n await browser.setNetworkConditions('CLOUD_USER');\r\n await browser.setNetworkConditions({\r\n offline: false,\r\n latency: 5, // Additional latency (ms).\r\n download_throughput: 500 * 1024, // Maximal aggregated download throughput.\r\n upload_throughput: 500 * 1024, // Maximal aggregated upload throughput.\r\n });\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### restoreNetworkConditions\r\n\r\nRestore the original network conditions, setting to `NO_THROTTLING`.\r\nThe native implementation of `deleteNetworkConditions` exposed by\r\nselenium is unofficial and didn't consistently work, the recommended\r\napproach by the google dev tools team is to restore the connection\r\nsetting the no throttling profile.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions\r\n \r\n // Do your assertions\r\n\r\n await browser.restoreNetworkConditions(); // Restore network conditions\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\nCo-authored-by: Marco Antonio Ghiani <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"aa45152a4e787f36014675b864fcc0fce7bd6758"}},{"branch":"7.17","label":"v7.17.13","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.9","label":"v8.9.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Marco Antonio Ghiani <[email protected]>
Thank you, it is better to backport for services consistency. We still be running CI tests on 7.17.x for some time and by backporting changes we keep it easier to make any framework changes we might have to do in the future. |
* main: (64 commits) [ML] Transforms: Fix privileges check. (elastic#163687) [Log Explorer] Add test suite for Dataset Selector (elastic#163079) [Security Solution][Endpoint] Add API checks to Endpoint Policy create/update for checking `endpointPolicyProtections` is enabled (elastic#163429) [Security Solution] Fix flaky test: x-pack/test/detection_engine_api_integration/security_and_spaces/update_prebuilt_rules_package/update_prebuilt_rules_package·ts - update_prebuilt_rules_package should allow user to install prebuilt rules from scratch, then install new rules and upgrade existing rules from the new package (elastic#163241) [Security Solution] expandable flyout - replace feature flag with advanced settings toggle (elastic#161614) [DOCS] Adds the release notes for the 8.9.1 release. (elastic#163578) [FTR] Implement browser network condition utils (elastic#163633) [Security Solution] Unskip rules table auto-refresh Cypress tests (elastic#163451) [Security Solution] Re-enable fixed rule snoozing Cypress test (elastic#160037) [Flaky Test elastic#111821] Mock `moment` to avoid midnight TZ issues (elastic#163157) Document interactive setup (elastic#163619) [Lens] Align decoration color with text color for layer actions (elastic#163630) [Lens] Relax counter field checks for saved visualizations with unsupported operations (elastic#163515) [Security Solution][Endpoint] Removes pMap and uses a for loop instead (elastic#163509) [Enterprise Search] Update Workplace Search connectors doclink (elastic#163676) Update APM (main) (elastic#163623) [Serverless] Partially fix lens/maps/visualize breadcrumbs missing title (elastic#163476) [Flaky elastic#118272] Unskip tests (elastic#163319) [APM] Make service group saved objects exportable (elastic#163569) [Observability AI Assistant] Action menu item (elastic#163463) ...
…3711) # Backport This will backport the following commits from `main` to `7.17`: - [[FTR] Implement browser network condition utils (#163633)](#163633) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Marco Antonio Ghiani","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-11T12:24:06Z","message":"[FTR] Implement browser network condition utils (#163633)\n\n## 📓 Summary\r\n\r\nThe PR implements some utilities into the `browser` service to allow\r\ncontrolling the network conditions during the execution of a functional\r\ntest.\r\n\r\n### `getNetworkConditions`\r\n\r\nReturns the current network simulation options. If none conditions are\r\npreviously set, it returns `undefined`\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n const networkConditions = await browser.getNetworkConditions(); // undefined\r\n\r\n await browser.setNetworkConditions('SLOW_3G');\r\n\r\n const networkConditions = await browser.getNetworkConditions();\r\n // {\r\n // offline: false,\r\n // latency: 2000,\r\n // download_throughput: 50000,\r\n // upload_throughput: 50000,\r\n // }\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### `setNetworkConditions`\r\n\r\nSet the desired network conditions.\r\nIt supports different presets that match the [network profiles provided\r\nby Chrome\r\ndebugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393):\r\n- `NO_THROTTLING`\r\n- `FAST_3G`\r\n- `SLOW_3G`\r\n- `OFFLINE`\r\n- `CLOUD_USER` (pre-existing)\r\nIt also accepts ad-hoc options to configure more specifically the\r\nnetwork conditions.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('NO_THROTTLING');\r\n await browser.setNetworkConditions('FAST_3G');\r\n await browser.setNetworkConditions('SLOW_3G');\r\n await browser.setNetworkConditions('OFFLINE');\r\n await browser.setNetworkConditions('CLOUD_USER');\r\n await browser.setNetworkConditions({\r\n offline: false,\r\n latency: 5, // Additional latency (ms).\r\n download_throughput: 500 * 1024, // Maximal aggregated download throughput.\r\n upload_throughput: 500 * 1024, // Maximal aggregated upload throughput.\r\n });\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### restoreNetworkConditions\r\n\r\nRestore the original network conditions, setting to `NO_THROTTLING`.\r\nThe native implementation of `deleteNetworkConditions` exposed by\r\nselenium is unofficial and didn't consistently work, the recommended\r\napproach by the google dev tools team is to restore the connection\r\nsetting the no throttling profile.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions\r\n \r\n // Do your assertions\r\n\r\n await browser.restoreNetworkConditions(); // Restore network conditions\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\nCo-authored-by: Marco Antonio Ghiani <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"aa45152a4e787f36014675b864fcc0fce7bd6758","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.10.0","v7.17.13","v8.9.2"],"number":163633,"url":"https://github.com/elastic/kibana/pull/163633","mergeCommit":{"message":"[FTR] Implement browser network condition utils (#163633)\n\n## 📓 Summary\r\n\r\nThe PR implements some utilities into the `browser` service to allow\r\ncontrolling the network conditions during the execution of a functional\r\ntest.\r\n\r\n### `getNetworkConditions`\r\n\r\nReturns the current network simulation options. If none conditions are\r\npreviously set, it returns `undefined`\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n const networkConditions = await browser.getNetworkConditions(); // undefined\r\n\r\n await browser.setNetworkConditions('SLOW_3G');\r\n\r\n const networkConditions = await browser.getNetworkConditions();\r\n // {\r\n // offline: false,\r\n // latency: 2000,\r\n // download_throughput: 50000,\r\n // upload_throughput: 50000,\r\n // }\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### `setNetworkConditions`\r\n\r\nSet the desired network conditions.\r\nIt supports different presets that match the [network profiles provided\r\nby Chrome\r\ndebugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393):\r\n- `NO_THROTTLING`\r\n- `FAST_3G`\r\n- `SLOW_3G`\r\n- `OFFLINE`\r\n- `CLOUD_USER` (pre-existing)\r\nIt also accepts ad-hoc options to configure more specifically the\r\nnetwork conditions.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('NO_THROTTLING');\r\n await browser.setNetworkConditions('FAST_3G');\r\n await browser.setNetworkConditions('SLOW_3G');\r\n await browser.setNetworkConditions('OFFLINE');\r\n await browser.setNetworkConditions('CLOUD_USER');\r\n await browser.setNetworkConditions({\r\n offline: false,\r\n latency: 5, // Additional latency (ms).\r\n download_throughput: 500 * 1024, // Maximal aggregated download throughput.\r\n upload_throughput: 500 * 1024, // Maximal aggregated upload throughput.\r\n });\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### restoreNetworkConditions\r\n\r\nRestore the original network conditions, setting to `NO_THROTTLING`.\r\nThe native implementation of `deleteNetworkConditions` exposed by\r\nselenium is unofficial and didn't consistently work, the recommended\r\napproach by the google dev tools team is to restore the connection\r\nsetting the no throttling profile.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions\r\n \r\n // Do your assertions\r\n\r\n await browser.restoreNetworkConditions(); // Restore network conditions\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\nCo-authored-by: Marco Antonio Ghiani <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"aa45152a4e787f36014675b864fcc0fce7bd6758"}},"sourceBranch":"main","suggestedTargetBranches":["7.17"],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/163633","number":163633,"mergeCommit":{"message":"[FTR] Implement browser network condition utils (#163633)\n\n## 📓 Summary\r\n\r\nThe PR implements some utilities into the `browser` service to allow\r\ncontrolling the network conditions during the execution of a functional\r\ntest.\r\n\r\n### `getNetworkConditions`\r\n\r\nReturns the current network simulation options. If none conditions are\r\npreviously set, it returns `undefined`\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n const networkConditions = await browser.getNetworkConditions(); // undefined\r\n\r\n await browser.setNetworkConditions('SLOW_3G');\r\n\r\n const networkConditions = await browser.getNetworkConditions();\r\n // {\r\n // offline: false,\r\n // latency: 2000,\r\n // download_throughput: 50000,\r\n // upload_throughput: 50000,\r\n // }\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### `setNetworkConditions`\r\n\r\nSet the desired network conditions.\r\nIt supports different presets that match the [network profiles provided\r\nby Chrome\r\ndebugger](https://github.com/ChromeDevTools/devtools-frontend/blob/da276a3faec9769cb55e442f0db77ebdce5cd178/front_end/core/sdk/NetworkManager.ts#L363-L393):\r\n- `NO_THROTTLING`\r\n- `FAST_3G`\r\n- `SLOW_3G`\r\n- `OFFLINE`\r\n- `CLOUD_USER` (pre-existing)\r\nIt also accepts ad-hoc options to configure more specifically the\r\nnetwork conditions.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('NO_THROTTLING');\r\n await browser.setNetworkConditions('FAST_3G');\r\n await browser.setNetworkConditions('SLOW_3G');\r\n await browser.setNetworkConditions('OFFLINE');\r\n await browser.setNetworkConditions('CLOUD_USER');\r\n await browser.setNetworkConditions({\r\n offline: false,\r\n latency: 5, // Additional latency (ms).\r\n download_throughput: 500 * 1024, // Maximal aggregated download throughput.\r\n upload_throughput: 500 * 1024, // Maximal aggregated upload throughput.\r\n });\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\n### restoreNetworkConditions\r\n\r\nRestore the original network conditions, setting to `NO_THROTTLING`.\r\nThe native implementation of `deleteNetworkConditions` exposed by\r\nselenium is unofficial and didn't consistently work, the recommended\r\napproach by the google dev tools team is to restore the connection\r\nsetting the no throttling profile.\r\n\r\n**N.B.**: _if the testing environment is not a Chromium browser, it\r\nthrows an error that can be easily caught to manually skip the test or\r\nhandle a fallback scenario._\r\n\r\n```ts\r\nit('should display a loading skeleton while loading', async function () {\r\n // Skip the test in case network condition utils are not available\r\n try {\r\n await browser.setNetworkConditions('SLOW_3G'); // Slow down network conditions\r\n \r\n // Do your assertions\r\n\r\n await browser.restoreNetworkConditions(); // Restore network conditions\r\n } catch (error) {\r\n this.skip();\r\n }\r\n});\r\n```\r\n\r\nCo-authored-by: Marco Antonio Ghiani <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"aa45152a4e787f36014675b864fcc0fce7bd6758"}},{"branch":"7.17","label":"v7.17.13","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.9","label":"v8.9.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/163703","number":163703,"state":"OPEN"}]}] BACKPORT--> --------- Co-authored-by: Marco Antonio Ghiani <[email protected]>
This pr didn't make it into the build candidate for v8.9.1. Updating the labels. |
📓 Summary
The PR implements some utilities into the
browser
service to allow controlling the network conditions during the execution of a functional test.getNetworkConditions
Returns the current network simulation options. If none conditions are previously set, it returns
undefined
N.B.: if the testing environment is not a Chromium browser, it throws an error that can be easily caught to manually skip the test or handle a fallback scenario.
setNetworkConditions
Set the desired network conditions.
It supports different presets that match the network profiles provided by Chrome debugger:
NO_THROTTLING
FAST_3G
SLOW_3G
OFFLINE
CLOUD_USER
(pre-existing)It also accepts ad-hoc options to configure more specifically the network conditions.
N.B.: if the testing environment is not a Chromium browser, it throws an error that can be easily caught to manually skip the test or handle a fallback scenario.
restoreNetworkConditions
Restore the original network conditions, setting to
NO_THROTTLING
.The native implementation of
deleteNetworkConditions
exposed by selenium is unofficial and didn't consistently work, the recommended approach by the google dev tools team is to restore the connection setting the no throttling profile.N.B.: if the testing environment is not a Chromium browser, it throws an error that can be easily caught to manually skip the test or handle a fallback scenario.