@@ -10,39 +10,36 @@ aliases: [
10
10
11
11
{{% pageinfo color="warning" %}}
12
12
<p class =" lead " >
13
- < i class = " fas fa-language display-4 " ></ i >
14
- Page being translated from English to Chinese.
15
- Do you speak Chinese? Help us to translate
16
- it by sending us pull requests!
13
+ 虽然Selenium 4提供了对Chrome DevTools Protocol (CDP) 的直接访问,
14
+ 但是仍非常鼓励您使用
15
+ [ WebDriver Bidi APIs ] ({{< ref "bidi_api.md" >}}
16
+ 代替.
17
17
</p >
18
18
{{% /pageinfo %}}
19
19
20
- {{% pageinfo color="warning" %}}
21
- <p class =" lead " >
22
- While Selenium 4 provides direct access to the Chrome DevTools Protocol (CDP), it is
23
- highly encouraged that you use the
24
- [WebDriver Bidi APIs]({{< ref "bidi_api.md" >}} instead.
25
- </p >
26
- {{% /pageinfo %}}
27
-
28
- Many browsers provide "DevTools" -- a set of tools that are integrated with the browser that
29
- developers can use to debug web apps and explore the performance of their pages. Google Chrome's
30
- DevTools make use of a protocol called the Chrome DevTools Protocol (or "CDP" for short).
31
- As the name suggests, this is not designed for testing, nor to have a stable API, so functionality
32
- is highly dependent on the version of the browser.
33
-
34
- WebDriver Bidi is the next generation of the W3C WebDriver protocol and aims to provide a stable API
35
- implemented by all browsers, but it's not yet complete. Until it is, Selenium provides access to
36
- the CDP for those browsers that implement it (such as Google Chrome, or Microsoft Edge, and
37
- Firefox), allowing you to enhance your tests in interesting ways. Some examples of what you can
38
- do with it are given below.
39
-
40
- ## Emulate Geo Location
41
-
42
- Some applications have different features and functionalities across different
43
- locations. Automating such applications is difficult because it is hard to emulate
44
- the geo-locations in the browser using Selenium. But with the help of Devtools,
45
- we can easily emulate them. Below code snippet demonstrates that.
20
+ 许多浏览器都提供"开发工具" -- 一组与浏览器集成的工具,
21
+ 开发人员可以用其调试web应用程序并探索其页面的性能.
22
+ 谷歌浏览器开发工具
23
+ 使用一种称为Chrome DevTools Protocol (简称"CDP") 的协议.
24
+ 顾名思义, 这不是为测试而设计的,
25
+ 而并没有一个稳定的API,
26
+ 所以它的功能高度依赖于浏览器的版本.
27
+
28
+ WebDriver Bidi是W3C WebDriver的下一代协议,
29
+ 旨在提供由所有浏览器实现稳定的API, 但尚未完成.
30
+ 在此之前, Selenium提供了通过CDP实现的方式
31
+ (诸如Google Chrome或Microsoft Edge, 以及Firefox),
32
+ 允许您以有趣的方式增强测试.
33
+ 下面给出了实际使用的例子.
34
+
35
+ ## 模拟地理位置
36
+
37
+ 一些应用程序在不同的位置具有不同的特性和功能.
38
+ 自动化此类应用程序很难,
39
+ 因为很难使用Selenium在浏览器中模拟地理位置.
40
+ 但是在Devtools的帮助下,
41
+ 我们可以轻易模拟他们.
42
+ 下面的代码片段演示了这一点.
46
43
47
44
{{< tabpane langEqualsHeader=true >}}
48
45
{{< tab header="Java" >}}
@@ -159,7 +156,7 @@ fun main() {
159
156
{{< /tab >}}
160
157
{{< /tabpane >}}
161
158
162
- ## Emulate Geo Location with the Remote WebDriver:
159
+ ## 通过远程WebDriver模拟地理位置
163
160
164
161
{{< tabpane langEqualsHeader=true >}}
165
162
{{< tab header="Java" >}}
@@ -316,12 +313,14 @@ fun main() {
316
313
{{< /tab >}}
317
314
{{< /tabpane >}}
318
315
319
- ## Override Device Mode
316
+ ## 覆盖设备模式
320
317
321
- Using Selenium's integration with CDP, one can override the current device
322
- mode and simulate a new mode. Width, height, mobile, and deviceScaleFactor
323
- are required parameters. Optional parameters include scale, screenWidth,
324
- screenHeight, positionX, positionY, dontSetVisible, screenOrientation, viewport, and displayFeature.
318
+ 使用Selenium与CDP的集成,
319
+ 可以覆盖当前设备模式并模拟新模式.
320
+ Width, height, mobile和deviceScaleFactor是必需的参数.
321
+ 可选参数包括scale, screenWidth,
322
+ screenHeight, positionX, positionY,
323
+ dontSetVisible, screenOrientation, viewport和displayFeature.
325
324
326
325
{{< tabpane langEqualsHeader=true >}}
327
326
{{< tab header="Java" >}}
0 commit comments