.net Windows 上的 Jenkins 和没有 RDC 的 GUI 测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10177708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins on Windows and GUI Tests without RDC
提问by Mike Borozdin
We have a master-slave configuration for Jenkins. Our .NET project is built by a slave Jenkins instance running on Windows.
我们有 Jenkins 的主从配置。我们的 .NET 项目是由运行在 Windows 上的从属 Jenkins 实例构建的。
There are a bunch of GUI tests, however they only seem to run if there's a remote desktop connection (RDC) session open.
有很多 GUI 测试,但是它们似乎只有在远程桌面连接 (RDC) 会话打开时才能运行。
When trying to run the tests with no RDC, Jenkins doesn't show any progress in testing. Then, however, I connect to the Slave's desktop and can see the main window of the application launched, however the UI testing framework (White) cannot perform any actions.
当尝试在没有 RDC 的情况下运行测试时,Jenkins 没有显示任何测试进展。但是,我连接到 Slave 的桌面并可以看到启动的应用程序的主窗口,但是 UI 测试框架(白色)无法执行任何操作。
The Jenkins slave is launched via Java Web Start.
Jenkins slave 通过 Java Web Start 启动。
I read on several websites that unfortunately it is not possible to run GUI tests without RDC session.
我在几个网站上读到,不幸的是,没有 RDC 会话就无法运行 GUI 测试。
I just want to confirm that it is true and wonder if there is any workaround.
我只想确认这是真的,并想知道是否有任何解决方法。
采纳答案by Jason Swager
Your slave machines have to be at a desktop before the test can run properly. We had the same problem.
您的从机必须在桌面上才能正常运行测试。我们遇到了同样的问题。
Solution was to have the test machine start up and auto-logon to the desktop. To ensure that the test would ONLY start after the desktop was available, we added a scheduled task, set to run at user login, that would launch the Jenkins slave via Java Web Start. That way, Jenkins would only see the slave once the desktop was running. After that, everything worked fine.
解决方案是让测试机器启动并自动登录到桌面。为了确保测试仅在桌面可用后开始,我们添加了一个计划任务,设置为在用户登录时运行,它将通过 Java Web Start 启动 Jenkins 从站。这样,Jenkins 只会在桌面运行时看到从站。之后,一切正常。
回答by Andy Chen
I have a Jenkins cluster running different kinds of GUI testing, win32, swing, selenium. They are running thousands of tests in unattended manner 24x7. Here is my solution:
我有一个 Jenkins 集群运行不同类型的 GUI 测试,win32,swing,selenium。他们以 24x7 无人值守的方式运行数以千计的测试。这是我的解决方案:
How to keep GUI testing alive - RDC doesn't work, the GUI applications will only function well when the RDC session is active. I've tried different ways, so don't bother to try again. Your test would broke after the RDC window is minimized or disconnected. The solution so far is install VNC Server (I am using UltraVNC) as service and make sure it is started during log on. Also make sure you don't connect to your test machine with RDC, as RDC will break VNC session. If possible connect it with VNC client as well. But that is up to you. What I do is when I need to debug something on the machine, I RDC to it and restart it to make sure #2 and #3 are set.
Auto logon - there is a tool autologon.exe in SysInternalsSuite, run it on your slave
Auto register slave - What you need is Swarm Plugin - https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin. Write a simple batch and place a shortcuts in your startup folder. Everytime your machine autologon, it is automatically registered as slave.
如何使 GUI 测试保持活动状态 - RDC 不起作用,GUI 应用程序只有在 RDC 会话处于活动状态时才能正常运行。我已经尝试过不同的方法,所以不要再尝试了。在 RDC 窗口最小化或断开连接后,您的测试将中断。到目前为止的解决方案是安装 VNC 服务器(我使用的是 UltraVNC)作为服务,并确保它在登录期间启动。还要确保您没有使用 RDC 连接到您的测试机器,因为 RDC 会中断 VNC 会话。如果可能,也将其与 VNC 客户端连接。但这取决于你。我所做的是,当我需要在机器上调试某些东西时,我将 RDC 连接到它并重新启动它以确保设置了 #2 和 #3。
自动登录 - 在 SysInternalsSuite 中有一个工具 autologon.exe,在你的从机上运行它
自动注册从站 - 您需要的是 Swarm 插件 - https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin。编写一个简单的批处理并在您的启动文件夹中放置一个快捷方式。每次您的机器自动登录时,它都会自动注册为从机。
I actually combine #2 and #3 as a simple batch file:
我实际上将 #2 和 #3 组合为一个简单的批处理文件:
autologon.exe <user> <domain> <password>
REM Here to make sure the logonCount is properly generated
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 0xFFFF /f
start /min java -jar I:\CDC\jenkins\swarm-client-1.9-jar-with-dependencies.jar -executors 1 -fsroot c:\Jenkins -labels "Prod Win7 %ComputerName%" -master <Jenkins URL> -name farm-%ComputerName% -username <username> -password <password>
回答by maQ
There is another way of do it without windows auto logon (works for me on few machines).
1. Go to Computer Management -> Services and Applications -> Services -> Jenkins Slave -> Properties
2. In Log Ontab chose Local System accountand check Allow services to interact with desktop
3. Close this windows by clicking OK, and restart the Jenkins slaveservice
4. Go to directory where is your test app and chose Propertieson your app executable
5. On Securitytab click Edit...
6. In new window click Add..
7. In new window click Locations...and chose Local computer (top most option on list), click OK
8. Put LOCAL SERVICEto white area of the window and click Check Names, click OK
9. Allow Full controlfor that user, click OK, close all windows
That should be everything. Let me know if it works for you.
还有另一种没有 Windows 自动登录的方法(适用于我在几台机器上)。
1. 转到计算机管理 -> 服务和应用程序 -> 服务 -> Jenkins Slave -> 属性
2. 在登录选项卡中选择本地系统帐户并选中允许服务与桌面交互
3. 单击确定关闭此窗口,然后重新启动在詹金斯从服务
4.进入目录哪里是你的测试应用程序并选择属性对您的应用程序的可执行
5.在安全选项卡中单击编辑...
6.在新的窗口中点击添加..
7.在新的窗口中点击位置...并选择本地计算机(列表中最顶部的选项),单击确定
8. 将LOCAL SERVICE置于窗口的白色区域,然后单击检查名称,单击确定
9. 允许对该用户进行完全控制,单击确定,关闭所有windows
那应该就是一切。请让我知道这对你有没有用。
回答by jan
As the other answers already stated, one needs a configuration, where the windows machine auto logons to a real user, see other answers for details. However this was not enough for me, I needed to setup a UltraVNC Serveras running as service to solve the problems.
正如其他答案已经指出的那样,需要一个配置,Windows 机器自动登录到真实用户,有关详细信息,请参阅其他答案。然而这对我来说还不够,我需要设置一个 UltraVNC 服务器作为服务来解决问题。
On the site is mentioned, that a login via RDP is a problem for that trick, i.e. connect with VNC or reboot after RDP access.
在网站上提到,通过 RDP 登录是该技巧的一个问题,即与 VNC 连接或在 RDP 访问后重新启动。

