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

查看:205
本文介绍了运行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 Server(以节点"模式运行)添加为Windows服务.硒服务器配置为启动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:\selenium\selenium-server-standalone-2.45.0.jar -role hub -hubConfig C:\selenium\hub.json
nssm install seleniumnode java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -nodeConfig C:\selenium\node.json

如果需要,它可以轻松地删除服务:

It provides easily way to remove service if needed:

nssm remove seleniumnode confirm

将nssm的目标位置添加到您的PATH变量,然后以admin身份从控制台运行

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

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

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