Skip to content

Commit c2995d8

Browse files
authored
update feature/chrome (#1863)
* update feature/chrome * update feature/chrome link from en page * add missing zh pages under cdp
1 parent fc556b5 commit c2995d8

File tree

2 files changed

+133
-58
lines changed

2 files changed

+133
-58
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: "Chrome DevTools Protocol"
3+
linkTitle: "CDP"
4+
weight: 10
5+
description: >
6+
Examples of working with Chrome DevTools Protocol in Selenium.
7+
CDP support is temporary until WebDriver BiDi has been implemented.
8+
aliases: [
9+
"/documentation/en/support_packages/chrome_devtools/",
10+
"/documentation/support_packages/chrome_devtools/",
11+
"/documentation/webdriver/bidirectional/chrome_devtools/",
12+
"documentation/webdriver/bidirectional/chrome_devtools/cdp_endpoint/",
13+
"documentation/webdriver/bidirectional/chrome_devtools/bidi_api/",
14+
"documentation/webdriver/bidirectional/chrome_devtools/cdp_api/",
15+
]
16+
---
17+
18+
Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that
19+
developers can use to debug web apps and explore the performance of their pages. Google Chrome's
20+
DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short).
21+
As the name suggests, this is not designed for testing, nor to have a stable API, so functionality
22+
is highly dependent on the version of the browser.
23+
24+
Selenium is working to implement a standards-based, cross-browser, stable alternative to CDP called
25+
[WebDriver BiDi]. Until the support for this new protocol has finished, Selenium plans to provide access
26+
to CDP features where applicable.
27+
28+
### Using Chrome DevTools Protocol with Selenium
29+
30+
Chrome and Edge have a method to send basic CDP commands.
31+
This does not work for features that require bidirectional communication, and you need to know what domains to enable when
32+
and the exact names and types of domains/methods/parameters.
33+
34+
{{< tabpane text=true >}}
35+
{{% tab header="Java" %}}
36+
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidi/cdp/CdpTest.java#L22-L27" >}}
37+
{{% /tab %}}
38+
{{% tab header="Python" %}}
39+
{{< gh-codeblock path="/examples/python/tests/bidi/cdp/test_cdp.py#L2-L7" >}}
40+
{{% /tab %}}
41+
{{% tab header="CSharp" %}}
42+
{{< gh-codeblock path="/examples/dotnet/SeleniumDocs/BiDi/CDP/CDPTest.cs#L14-L21" >}}
43+
{{% /tab %}}
44+
{{% tab header="Ruby" %}}
45+
{{< gh-codeblock path="/examples/ruby/spec/bidi/cdp/cdp_spec.rb#L9-L13" >}}
46+
{{% /tab %}}
47+
{{% tab header="JavaScript" %}}
48+
{{< badge-code >}}
49+
{{% /tab %}}
50+
{{% tab header="Kotlin" %}}
51+
{{< badge-code >}}
52+
{{% /tab %}}
53+
{{< /tabpane >}}
54+
55+
56+
To make working with CDP easier, and to provide access to the more advanced features, Selenium bindings
57+
automatically generate classes and methods for the most common domains.
58+
CDP methods and implementations can change from version to version, though, so you want to keep the
59+
version of Chrome and the version of DevTools matching. Selenium supports the 3 most
60+
recent versions of Chrome at any given time,
61+
and tries to time releases to ensure that access to the latest versions are available.
62+
63+
This limitation provides additional challenges for several bindings, where dynamically
64+
generated CDP support requires users to regularly update their code to reference the proper version of CDP.
65+
In some cases an idealized implementation has been created that should work for any version of CDP without the
66+
user needing to change their code, but that is not always available.
67+
68+
Examples of how to use CDP in your Selenium tests can be found on the following pages, but
69+
we want to call out a couple commonly cited examples that are of limited practical value.
70+
* **Geo Location** — almost all sites use the IP address to determine physical location,
71+
so setting an emulated geolocation rarely has the desired effect.
72+
* **Overriding Device Metrics** — Chrome provides a great API for setting [Mobile Emulation](https://chromedriver.chromium.org/mobile-emulation)
73+
in the Options classes, which is generally superior to attempting to do this with CDP.

website_and_docs/content/documentation/webdriver/browsers/chrome.zh-cn.md

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: "Chrome specific functionality"
2+
title: "Chrome 特定功能"
33
linkTitle: "Chrome"
44
weight: 4
55
description: >-
6-
These are capabilities and features specific to Google Chrome browsers.
6+
特定于 Google Chrome 浏览器的功能和特性.
77
aliases: [
88
"/zh-cn/documentation/capabilities/chromium"
99
]
@@ -44,14 +44,14 @@ Chrome浏览器的特有功能可以在谷歌的页面找到: [Capabilities & Ch
4444

4545
### 参数
4646

47-
The `args` parameter is for a list of command line switches to be used when starting the browser.
48-
There are two excellent resources for investigating these arguments:
47+
`args` 参数用于启动浏览器时要使用的命令行开关列表.
48+
有两个很好的资源可以用于研究这些参数:
4949
* [Chrome Flags for Tooling](https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md)
5050
* [List of Chromium Command Line Switches](https://peter.sh/experiments/chromium-command-line-switches/)
5151

52-
Commonly used args include `--start-maximized`, `--headless=new` and `--user-data-dir=...`
52+
常用的参数包括 `--start-maximized`, `--headless=new` 以及 `--user-data-dir=...`
5353

54-
Add an argument to options:
54+
向选项添加参数:
5555

5656
{{< tabpane text=true >}}
5757
{{< tab header="Java" >}}
@@ -103,9 +103,9 @@ Add an argument to options:
103103

104104
### 添加扩展程序
105105

106-
`extensions` 参数接受crx文件. As for unpacked directories,
107-
please use the `load-extension` argument instead, as mentioned in
108-
[this post](https://chromedriver.chromium.org/extensions).
106+
`extensions` 参数接受crx文件. 至于解压的目录,
107+
请使用 `load-extension` 参数代替,
108+
正如 [这篇文章](https://chromedriver.chromium.org/extensions) 所示.
109109

110110
添加一个扩展程序到选项中:
111111

@@ -161,9 +161,8 @@ please use the `load-extension` argument instead, as mentioned in
161161

162162
Chrome 添加了各种参数,如果你不希望添加某些参数,可以将其传入 `excludeSwitches`.
163163
一个常见的例子是重新打开弹出窗口阻止程序.
164-
A full list of default arguments
165-
can be parsed from the
166-
[Chromium Source Code](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/chromedriver/chrome_launcher.cc)
164+
默认参数的完整列表可以参考
165+
[Chromium 源码](https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/chromedriver/chrome_launcher.cc)
167166

168167
设置排除参数至选项中:
169168

@@ -189,26 +188,28 @@ can be parsed from the
189188
{{< /tabpane >}}
190189

191190

192-
## Service
191+
## 服务
193192

194-
Examples for creating a default Service object, and for setting driver location and port
195-
can be found on the [Driver Service]({{< ref "../drivers/service.md" >}}) page.
193+
创建默认 Service 对象的示例,
194+
以及用于设置驱动程序位置和端口
195+
可以参考 [驱动服务]({{< ref "../drivers/service.md" >}}) 页面.
196196

197-
### Log output
197+
### 日志输出
198198

199-
Getting driver logs can be helpful for debugging issues. The Service class lets you
200-
direct where the logs will go. Logging output is ignored unless the user directs it somewhere.
199+
获取驱动程序日志有助于调试问题.
200+
使用 Service 类, 可以指明日志的路径.
201+
除非用户将其定向到某个位置, 否则将忽略日志记录输出.
201202

202-
#### File output
203+
#### 文件输出
203204

204-
To change the logging output to save to a specific file:
205+
更改日志记录输出以保存到特定文件:
205206

206207
{{< tabpane text=true >}}
207208
{{% tab header="Java" %}}
208209
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L100-L101" >}}
209-
**Note**: Java also allows setting file output by System Property:\
210-
Property key: `ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY`\
211-
Property value: String representing path to log file
210+
**注意**: Java 还允许通过系统属性设置文件输出:\
211+
属性键: `ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY`\
212+
属性值: 表示日志文件路径的字符串
212213
{{% /tab %}}
213214
{{< tab header="Python" >}}
214215
{{< badge-version version="4.11" >}}
@@ -229,17 +230,17 @@ Property value: String representing path to log file
229230
{{< /tab >}}
230231
{{< /tabpane >}}
231232

232-
#### Console output
233+
#### 命令行输出
233234

234-
To change the logging output to display in the console as STDOUT:
235+
更改日志记录输出以在控制台中显示为标准输出:
235236

236237
{{< tabpane text=true >}}
237238
{{% tab header="Java" %}}
238239
{{< badge-version version="4.10" >}}
239240
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L114-L115" >}}
240-
**Note**: Java also allows setting console output by System Property;\
241-
Property key: `ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY`\
242-
Property value: `DriverService.LOG_STDOUT` or `DriverService.LOG_STDERR`
241+
**注意**: Java 还允许通过系统属性设置控制台输出;\
242+
属性键: `ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY`\
243+
属性值: `DriverService.LOG_STDOUT` `DriverService.LOG_STDERR`
243244
{{% /tab %}}
244245
{{< tab header="Python" >}}
245246
{{< badge-version version="4.11" >}}
@@ -261,18 +262,18 @@ Property value: `DriverService.LOG_STDOUT` or `DriverService.LOG_STDERR`
261262
{{< /tab >}}
262263
{{< /tabpane >}}
263264

264-
### Log level
265-
There are 6 available log levels: `ALL`, `DEBUG`, `INFO`, `WARNING`, `SEVERE`, and `OFF`.
266-
Note that `--verbose` is equivalent to `--log-level=ALL` and `--silent` is equivalent to `--log-level=OFF`,
267-
so this example is just setting the log level generically:
265+
### 日志级别
266+
共有六种日志级别: `ALL`, `DEBUG`, `INFO`, `WARNING`, `SEVERE`, 以及 `OFF`.
267+
注意 `--verbose` 等效于 `--log-level=ALL` 以及 `--silent` 等效于 `--log-level=OFF`,
268+
因此, 此示例只是通用地设置日志级别:
268269

269270
{{< tabpane text=true >}}
270271
{{% tab header="Java" %}}
271272
{{< badge-version version="4.8" >}}
272273
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L129-L130" >}}
273-
**Note**: Java also allows setting log level by System Property:\
274-
Property key: `ChromeDriverService.CHROME_DRIVER_LOG_LEVEL_PROPERTY`\
275-
Property value: String representation of `ChromiumDriverLogLevel` enum
274+
**注意**: Java 还允许通过系统属性设置日志级别:\
275+
属性键: `ChromeDriverService.CHROME_DRIVER_LOG_LEVEL_PROPERTY`\
276+
属性值: `ChromiumDriverLogLevel` 枚举的字面值
276277
{{% /tab %}}
277278
{{< tab header="Python" >}}
278279
{{< badge-version version="4.11" >}}
@@ -293,21 +294,22 @@ Property value: String representation of `ChromiumDriverLogLevel` enum
293294
{{< /tab >}}
294295
{{< /tabpane >}}
295296

296-
### Log file features
297-
There are 2 features that are only available when logging to a file:
298-
* append log
299-
* readable timestamps
297+
### 日志文件功能
298+
有 2 个功能仅在写入文件时可用:
299+
* 追加日志
300+
* 可读时间戳
300301

301-
To use them, you need to also explicitly specify the log path and log level.
302-
The log output will be managed by the driver, not the process, so minor differences may be seen.
302+
要使用它们, 您还需要显式指定日志路径和日志级别.
303+
日志输出将由驱动程序管理,
304+
而不是由进程管理, 因此可能会看到细微的差异.
303305

304306
{{< tabpane text=true >}}
305307
{{% tab header="Java" %}}
306308
{{< badge-version version="4.8" >}}
307309
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L147-L148" >}}
308-
**Note**: Java also allows toggling these features by System Property:\
309-
Property keys: `ChromeDriverService.CHROME_DRIVER_APPEND_LOG_PROPERTY` and `ChromeDriverService.CHROME_DRIVER_READABLE_TIMESTAMP`\
310-
Property value: `"true"` or `"false"`
310+
**注意**: Java 还允许通过系统属性切换这些功能:\
311+
属性键: `ChromeDriverService.CHROME_DRIVER_APPEND_LOG_PROPERTY` 以及 `ChromeDriverService.CHROME_DRIVER_READABLE_TIMESTAMP`\
312+
属性值: `"true"` `"false"`
311313
{{% /tab %}}
312314
{{< tab header="Python" >}}
313315
{{< gh-codeblock path="examples/python/tests/browsers/test_chrome.py#L104" >}}
@@ -327,19 +329,19 @@ Property value: `"true"` or `"false"`
327329
{{< /tab >}}
328330
{{< /tabpane >}}
329331

330-
### Disabling build check
332+
### 禁用构建检查
331333

332-
Chromedriver and Chrome browser versions should match, and if they don't the driver will error.
333-
If you disable the build check, you can force the driver to be used with any version of Chrome.
334-
Note that this is an unsupported feature, and bugs will not be investigated.
334+
Chromedriver Chrome 浏览器版本应该匹配, 如果它们不匹配, 驱动程序将出错.
335+
如果您停用构建检查功能, 则可以强制将驱动程序与任何版本的 Chrome 一起使用.
336+
请注意, 这是一项不受支持的功能, 并且不会调查 bug.
335337

336338
{{< tabpane text=true >}}
337339
{{% tab header="Java" %}}
338340
{{< badge-version version="4.8" >}}
339341
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/browsers/ChromeTest.java#L166-L167" >}}
340-
**Note**: Java also allows disabling build checks by System Property:\
341-
Property key: `ChromeDriverService.CHROME_DRIVER_DISABLE_BUILD_CHECK`\
342-
Property value: `"true"` or `"false"`
342+
**注意**: Java 还允许通过系统属性禁用构建检查:\
343+
属性键: `ChromeDriverService.CHROME_DRIVER_DISABLE_BUILD_CHECK`\
344+
属性值: `"true"` `"false"`
343345
{{% /tab %}}
344346
{{< tab header="Python" >}}
345347
{{< badge-version version="4.11" >}}
@@ -361,7 +363,7 @@ Property value: `"true"` or `"false"`
361363
{{< /tabpane >}}
362364

363365

364-
## Special Features
366+
## 特殊功能
365367

366368
### Casting
367369

@@ -392,9 +394,9 @@ Property value: `"true"` or `"false"`
392394

393395
您可以模拟各种网络条件.
394396

395-
The following examples are for local webdrivers. For remote webdrivers,
396-
please refer to the
397-
[Remote WebDriver]({{< ref "../drivers/remote_webdriver" >}}) page.
397+
以下示例适用于本地 webdrivers. 针对远程 webdrivers,
398+
请参考
399+
[Remote WebDriver]({{< ref "../drivers/remote_webdriver" >}}) 页面.
398400

399401
{{< tabpane text=true >}}
400402
{{< tab header="Java" >}}
@@ -417,7 +419,7 @@ please refer to the
417419
{{< /tab >}}
418420
{{< /tabpane >}}
419421

420-
### Logs
422+
### 日志
421423

422424
{{< tabpane text=true >}}
423425
{{< tab header="Java" >}}
@@ -440,7 +442,7 @@ please refer to the
440442
{{< /tab >}}
441443
{{< /tabpane >}}
442444

443-
### Permissions
445+
### 权限
444446

445447
{{< tabpane text=true >}}
446448
{{< tab header="Java" >}}
@@ -465,4 +467,4 @@ please refer to the
465467

466468
### DevTools
467469

468-
See the [Chrome DevTools] section for more information about using Chrome DevTools
470+
详见 [Chrome DevTools]({{< ref "../bidi/cdp/" >}}) 部分以获取有关使用Chrome DevTools的更多信息

0 commit comments

Comments
 (0)