运行 Selenium Server &ChromeDriver 作为 Windows 服务 [英] Running Selenium Server & ChromeDriver as a Windows Service

查看:23
本文介绍了运行 Selenium Server &ChromeDriver 作为 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了执行从前到后的 Web UI 测试,我们使用 Selenium 和 ChromeDriver 来自动化页面加载/交互,作为我们测试包的一部分.

So that we may perform front-to-back web UI testing, we are using Selenium and ChromeDriver to automate page loads / interaction as part of our testing pack.

这在开发人员测试期间(在开发人员的本地机器上)表现如预期,但作为我们持续集成构建的一部分,我们正在努力执行这些检查.

This is behaving as expected during developer testing (on a developer's local machine), but we are struggling to perform these checks as part of our continuous integration build.

我们的服务器工厂基于 *NIX,我们所有的 CI 基础架构都在这些机器上运行.为了我们可以在 Windows 下测试 Chrome(我们的交付机制),我们配置了一个 Selenium Grid.当 CI 测试运行时,它们会访问网格,以便找到要在其上运行测试的 Windows 节点.

Our server plant is *NIX based, and all of our CI infrastructure runs on these machines. So that we may test Chrome under Windows (our delivery mechanism), we have configured a Selenium Grid. When the CI tests run, they access the grid, in order to locate a Windows node to run the tests on.

我们有一个专门用于运行这些测试的 Windows 桌面.这包含我们的标准企业版 Windows 7.这台机器将根据 IT 部门的更新政策定期重启.

We have had a Windows desktop provisioned solely for the purpose of running these test. This contains our standard enterprise build of Windows 7. This machine will be periodically rebooted in-line with the IT department's update policy.

为了确保 Selenium 服务器始终运行,我们将 Selenium 服务器(以节点"模式运行)添加为 Windows 服务.selenium 服务器配置为启动 ChromeDriver 以调用模拟的用户交互.

In an effort to ensure the Selenium server is always running, we have added the Selenium Server (running in "node" mode) as a Windows service. The selenium Server is configured to start-up ChromeDriver to invoke the simulated user-interaction.

但是,当从 CI 运行测试时,它们会因超时而失败.我们的工作原理是,运行服务的系统用户不能创建交互式窗口.网络搜索提到了会话 0"问题,但几乎没有关于如何前进的建设性建议.

However, when running the tests from CI they fail due to timeout. Our working theory is, the system user that is running the service cannot create interactive windows. A web search has raised reference to the "Session 0" problem, but with little to no constructive advice on how to move forward.

从交互式会话手动启动 Selenium Server 进程不是一个可行的解决方案,因为这会导致脆弱的测试 - 由于基础设施问题而不是真正的测试回归而失败.

Starting the Selenium Server process manually from an interactive session is not a viable solution, as this is leading to brittle tests - which are failing due to an infrastructure problem, rather than a genuine test regression.

我们如何在系统重新启动时通过 Windows 服务启动 Selenium Server 实例,以便能够启动 Chrome 实例?

How can we have an instance of Selenium Server started via a Windows Service whenever the system reboots, that is capable of launching Chrome instances?

推荐答案

使用 NSSM 可以轻松完成.服务安装如下所示:

It could be easily done with NSSM. Installation of services looks like these:

nssm install seleniumhub java -jar C:seleniumselenium-server-standalone-2.45.0.jar -role hub -hubConfig C:seleniumhub.json
nssm install seleniumnode java -jar C:seleniumselenium-server-standalone-2.45.0.jar -role node -nodeConfig C:selenium
ode.json

它提供了在需要时轻松删除服务的方法:

It provides easily way to remove service if needed:

nssm remove seleniumnode confirm

将 nssm 的目标添加到您的 PATH 变量并以管理员身份从控制台运行

Add destination to nssm to your PATH variable and run from console as admin

更新 2021 年 4 月

UPDATE April 2021

超过 3 年不支持 NSSM.所以请考虑其他选项,例如 winsw 或任何其他选项.WinSW 的工作与 NSSM 相同,并允许将运行配置保存在 xml 中.

NSSM is not supported for more than 3 years. So please consider other options like winsw or any other. WinSW does the same job as NSSM and allows to keep run configuration in xml.

这篇关于运行 Selenium Server &ChromeDriver 作为 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆