使用 selenium grid 和 junit 在多个浏览器上运行测试

发布于 2024-09-12 08:26:33 字数 402 浏览 5 评论 0原文

我正在尝试设置自动硒测试,但不知道如何在多个浏览器中运行测试。根据在线阅读的内容,我已经启动了 selenium 网格并在多个浏览器上运行,并且它成功地执行了我的测试。

我试图弄清楚如何设置我的 junit 测试,以便它可以依次运行或并行运行所有浏览器。这是我的代码:

selenium = new DefaultSelenium("grid.host.here", "4444", "*firefox", "http://host.com");

使用此代码,它只运行 firefox,我如何告诉它运行 firefox、iexplore 和 safari,而不创建对象的新实例?我见过 PHP 和 Python 中的示例,您可以传递一组浏览器,然后它一个接一个地运行它们。找不到有关 Java 的任何内容。

I am trying to set up automated selenium testing but don't know how to run tests in multiple browsers. Based on reading stuff online I have selenium grid up and running with multiple browsers and it successfully executes my tests.

I am trying to figure out how to setup my junit tests so that it runs all the browsers one after another or in parallel is possible. Here is my code:

selenium = new DefaultSelenium("grid.host.here", "4444", "*firefox", "http://host.com");

With this code it only runs firefox, how do I tell it to run firefox, iexplore and safari without creating new instantes of the object? I have seen examples in PHP and Python where you can pass an array of browsers and it runs them one after another. Couldn't find anything for Java.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2024-09-19 08:26:33

您需要创建多个 DefaultSelenium 对象。它负责维护浏览器会话(即与网格 RC 的连接)。 Selenium Grid 附带了使用 TestNG 执行此操作的示例。如果您需要使用 jUnit,我见过人们使用并行 jUnit 取得了成功。

从本质上来说,并没有什么神奇之处。你有N个RC工人,所以你的测试需要建立N个连接才能充分利用你的工人。如果您尝试连接 N + 1,客户端将简单地阻塞,直到 RC 可用。只要确保调整你的网格设置来处理这个问题即可。客户端有可能在 RC 可用之前超时,这可能会造成棘手的情况。

You need to create multiple DefaultSelenium objects. It's what maintains the browser session (i.e., the connection to the grid RC). Selenium Grid ships with examples of doing this with TestNG. If you need to use jUnit, I've seen people succeed with parallel-junit.

At the core of it, there's no magic going on. You have N RC workers, so your tests need to establish N connections to fully utilize your workers. If you try to connect N + 1, the client will simply block until an RC becomes available. Just be sure to tune your grid setup to handle that. It's possible the client times out before the RC becomes available, which can create a tricky situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文