Selenium 4 新命令概览
在我们发布 Selenium 4 之前,我认为深入介绍一些新功能会很好。当然,我们涵盖的所有功能都在主要的 WebDriver 文档中,所以如果你不喜欢阅读博客文章,那么可以随意直接查看文档!
你可能很熟悉如何启动 Selenium 服务器:你只需执行类似 java -jar selenium-server-4.0.0.jar standalone
的命令就可以了!但在 Selenium 4 中,你可以使用此 jar 做更多的事情。
最不明显的是,服务器 jar 本身就是一个可执行文件。如果你使用 Linux 或 macOS,并且安装了 Java,你可以使 jar 可执行 (例如 chmod 755 selenium-server-4.0.0.jar
),将其重命名为类似 selenium
的名称,并将其放在你的 $PATH
中。这样,你可以简单地运行 selenium
,而不是编写 java -jar ...
。
现在你已经完成了这些,如果你运行 selenium
命令并使用 selenium --help
,你将得到一个可执行的可用子命令的方便列表。有一些旧的常用命令,例如 standalone
(用于启动独立的 Selenium 服务器),以及 hub
和 node
(用于启动 Selenium Hub 和 Node 设置),但还有其他 Selenium 4 的新命令。
其中第一个是 info
。我们添加这个命令是为了在使用 Selenium 服务器时提供易于查找和访问的有关常见任务的文档。如果你单独运行 selenium info
,你将看到类似以下内容:
Info
====
You can find out more about topics concerning Selenium Grid by running the
"info" command followed by:
* config - Help on how to configure Selenium
* tracing - Help on how distributed tracing works with selenium
* security - Help on how how to secure communications to and within selenium
* sessionmap - Help on different types of sessionmap and how to start them.
Each topic will give you enough information to help you get started, and contains
some pointers on our site to provide more complete information.
要获取有关特定主题的更多信息,只需添加主题的名称,例如 selenium info security
。希望这将使处理 Selenium 不那么令人生畏,并为你提供一个开始使用围绕运行 Selenium Grid 的一些更复杂主题的好地方。
虽然 selenium
命令非常灵活,但它提供了令人望而生畏的命令行标志列表。你如何记住它们?你不需要记住它们!相反,让 selenium completion
为你减轻负担。如果你是 zsh 用户,那么只需 source <(selenium completion zsh)
,现在你就可以对子命令以及所有标志进行制表符补全,包括如何使用它们的示例。
最后,还有一些隐藏的标志。我们隐藏它们是因为它们可能有点令人困惑,难以使用或理解它们的含义,但是当调试 Grid 的配置方式时,有一个标志非常有用,那就是 --dump-config
标志。当使用诸如 standalone
或 hub
之类的服务器命令运行时,它会将 Grid 使用的配置选项作为 JSON blob 转储。这对于跟踪配置中的细微问题很有帮助,尤其是在使用环境变量进行配置时。