You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It has been inspired in the power of CDP to interact with the browser like you would do using chrome dev tools but programmatically, **this library is independent of any test automation framework** since it talks directly with chrome using `--remote-debugging-port` commonly 9222 port. There are situations when we need to emulate or collect information from the browser during the execution of e2e tests. This lib intends to be an utility for testing purposes without the need to program each functionality.
11
+
It has been inspired in the power of CDP to interact with the browser like you would do using chrome dev tools but programmatically, **this library is independent of any test automation framework** since it talks directly with chrome using `--remote-debugging-port` commonly 9222 port. There are situations when we need to emulate or collect information from the browser during the execution of e2e tests. This lib intends to be an utility for testing purposes without the need to program each functionality.
12
12
13
13
More inpiration has been based on existing tools that are using this protocol like [puppeteer](https://github.com/puppeteer/puppeteer), see https://puppeteer.github.io/puppeteer/docs/puppeteer.tracing
14
14
15
15
## Important
16
16
17
-
It is not a replacement of any actual tool or library, instead it is just a wrapper with common utilities for Test Automation or Performance testing. For example Selenium 4 introduces a new powerful API which grants access to Chrome DevTools directly from your automated tests just accessing it by `driver.getDevTools();`, this is another way to use CDP programmatically in your scripts. It can be used also by importing directly `chrome-remote-interface` like this project is referencing in its package.json.
17
+
It is not a replacement of any actual tool or library, instead it is just a wrapper with common utilities for Test Automation or Performance testing. For example Selenium 4 introduces a new powerful API which grants access to Chrome DevTools directly from your automated tests just accessing it by `driver.getDevTools();`, this is another way to use CDP programmatically in your scripts. It can be used also by importing directly `chrome-remote-interface` like this project is referencing in its package.json.
18
18
19
19
You are very welcome if you feel that can contribute with more utilities to take advantaje of this great API.
20
20
21
21
## Usage
22
22
23
23
### Config (Only required for Tracing domain)
24
24
25
-
Create a config folder and place your cdp.config.json file there. It will contain configurations needed for tracing such as including or excluding categories and more. See the following example of how it will look like:
25
+
Create a config folder and place your cdp.config.json file there. It will contain configurations needed for tracing such as including or excluding categories and more. See the following example of how it will look like:
26
26
27
27
For more information about how to use traceConfig, see [TraceConfig](https://chromedevtools.github.io/devtools-protocol/tot/Tracing/#type-TraceConfig)
28
28
29
29
```json
30
-
31
30
{
32
-
"tracing": {
33
-
"traceConfig": {
34
-
"includedCategories": [
35
-
"-*",
36
-
"devtools.timeline",
37
-
"v8.execute",
38
-
"disabled-by-default-devtools.timeline",
39
-
"disabled-by-default-devtools.timeline.frame",
40
-
"toplevel",
41
-
"blink.console",
42
-
"blink.user_timing",
43
-
"latencyInfo",
44
-
"disabled-by-default-devtools.timeline",
45
-
"disabled-by-default-devtools.timeline.frame",
46
-
"disabled-by-default-devtools.timeline.stack",
47
-
"disabled-by-default-devtools.screenshot",
48
-
"disabled-by-default-v8.cpu_profiler"
49
-
],
50
-
"excludedCategories": [
51
-
"-*"
52
-
]
53
-
}
54
-
},
55
-
"cdpPort": 9222,
56
-
"maxTimeout": 50000
31
+
"tracing": {
32
+
"traceConfig": {
33
+
"includedCategories": [
34
+
"-*",
35
+
"devtools.timeline",
36
+
"v8.execute",
37
+
"disabled-by-default-devtools.timeline",
38
+
"disabled-by-default-devtools.timeline.frame",
39
+
"toplevel",
40
+
"blink.console",
41
+
"blink.user_timing",
42
+
"latencyInfo",
43
+
"disabled-by-default-devtools.timeline",
44
+
"disabled-by-default-devtools.timeline.frame",
45
+
"disabled-by-default-devtools.timeline.stack",
46
+
"disabled-by-default-devtools.screenshot",
47
+
"disabled-by-default-v8.cpu_profiler"
48
+
],
49
+
"excludedCategories": ["-*"]
50
+
}
51
+
},
52
+
"cdpPort": 9222,
53
+
"maxTimeout": 50000
57
54
}
58
-
59
55
```
60
56
61
-
62
57
### Tracing
63
58
64
59
The following example shows how to use the Tracing class with Selenium Webdriver.
@@ -67,129 +62,180 @@ The following example shows how to use the Tracing class with Selenium Webdriver
The following example shows how to use the Network class with Selenium Webdriver. Notice that it is possible to convert HAR object returned by `stopTrace` into a
105
+
more readable object. The obtained requests can be sent to a database to visualize them in a reporting tool like Grafana.
106
+
107
+
For more information about how to send metrics to a database, please check the documentation [Capturing requests](https://github.com/germanbisogno/cdp-utils/tree/main/src/performance#capturing-requests)
// Perform assertions or do whatever with perfStartResults or perfEndResults
186
+
constperfEndResults=awaitperformance.stopTrace();
143
187
144
-
// Close the CDP client connection
145
-
awaitcdpClient.close()
188
+
// Perform assertions or do whatever with perfStartResults or perfEndResults
146
189
147
-
awaitdriver.quit();
190
+
// Close the CDP client connection
191
+
awaitcdpClient.close();
192
+
193
+
awaitdriver.quit();
148
194
}
149
195
150
196
```
151
197
152
198
### Lighthouse
153
199
154
-
An example using the Lighthouse class with Selenium Webdriver. Notice that it combines lighthouse/puppeteer in order to initialize the workflow with the configuration required and navigate to the first page.
200
+
An example using the Lighthouse class with Selenium Webdriver. Notice that it combines lighthouse/puppeteer in order to initialize the workflow with the configuration required and navigate to the first page.
0 commit comments