简体   繁体   English

将虚拟机上的Selenium测试的显示分辨率设置为Jenkins Slave

[英]Setting display resolution for Selenium tests on virtual machine as Jenkins Slave

I'm having trouble running some Selenium tests on a Jenkins Slave. 我在Jenkins Slave上运行一些Selenium测试时遇到了麻烦。 To be specific, the display resolution that is used to run the tests is too small, causing some of the tests to fail. 具体而言,用于运行测试的显示分辨率太小,导致某些测试失败。

To check the display resolution, we log the display height and width to the console, using: 要检查显示分辨率,我们使用以下命令将显示高度和宽度记录到控制台:

driver.manage().window().maximize();
System.out.println("Window height: " + driver.manage().window().getSize().getHeight());
System.out.println("Window width: " + driver.manage().window().getSize().getWidth());

This returns: 返回:

Window height: 784
Window width: 1040

which seems like a very strange resolution to me. 这对我来说似乎是一个非常奇怪的解决方案。 The desired resolution is 1920 x 1080. 所需的分辨率为1920 x 1080。

The server that is used as a slave is a virtual machine (Windows Server 2012 R2). 用作从属服务器的是虚拟机(Windows Server 2012 R2)。 The Jenkins Slave is Connected via JNLP agent. Jenkins Slave通过JNLP代理连接。 The slave has the service running with Log On As "Local System" with the "Allow service to interact with desktop" option enabled. 从站使用“登录为本地系统”运行服务,并启用“允许服务与桌面交互”选项。

So far we've tried a number of things like: 到目前为止,我们已经尝试了很多东西,比如:

  • Connecting to slave VM using RDP and disconnecting to leave session open with desired display resolution 使用RDP连接到从VM并断开连接,使会话以所需的显示分辨率打开
  • Using powershell to set the display resolution 使用powershell设置显示分辨率
  • Setting the default display resolution in the VM configuration 在VM配置中设置默认显示分辨率
  • Setting the window dimensions using Selenium 使用Selenium设置窗口尺寸
  • And more... 和更多...

All of these didn't resolve the issues. 所有这些都没有解决问题。 Suggestions are very welcome! 建议非常欢迎!

Finally managed to fix these issues after realizing that Jenkins does not necessarily need to run the slaves as a windows service. 在意识到Jenkins不一定需要将奴隶作为Windows服务运行之后,最终设法解决了这些问题。 To start the slave, the JNLP agent can be downloaded from Jenkins and copied to the server. 要启动从属服务器,可以从Jenkins下载JNLP代理并将其复制到服务器。 When running the JNLP file, you can select for the option to install the slave agent as a service. 运行JNLP文件时,可以选择将从属代理安装为服务的选项。

詹金斯奴隶代理人

Previously we had this option selected, that's why the slave was running as a service. 以前我们选择了这个选项,这就是奴隶作为服务运行的原因。 After stopping and removing the service, we ran the JNLP file again and made sure to not select the option. 停止并删除服务后,我们再次运行JNLP文件,并确保不选择该选项。

The solutions suggested that included disconnecting the remote desktop session and leaving the session open with a large resolution didn't work when running the slave as a service. 解决方案建议包括断开远程桌面会话并使用大分辨率打开会话在将从属服务器作为服务运行时不起作用。 They do work however when running the slave in the default way. 但是,当以默认方式运行从站时,它们可以正常工作。

Make sure that the remote desktop session is not ended after a certain period of time: 确保在一段时间后远程桌面会话未结束: 会话超时属性

Hope this helps someone! 希望这有助于某人!

Based on my experience with this you can't solve this problem programmatically. 根据我的经验,您无法以编程方式解决此问题。 Your tests will run on the resolution which was used last time when you physically accessed this VM's display. 您的测试将使用上次物理访问此VM显示时使用的分辨率运行。 For example, if I open VM on my big screen monitor and maximize it, tests will run on that resolution. 例如,如果我在大屏幕监视器上打开VM并最大化它,测试将在该分辨率上运行。 But if I open it on my laptop screen and close RDP connection, tests will run on that smaller screen size. 但是,如果我在笔记本电脑屏幕上打开它并关闭RDP连接,测试将在较小的屏幕尺寸上运行。 I know it sounds strange, but I really couldn't find better solution. 我知道这听起来很奇怪,但我真的找不到更好的解决方案。 :D So now I must be careful to maximize VM display on my bigger screen before I close VM. :D所以现在我必须小心在关闭VM之前在我的大屏幕上最大化VM显示。 You will probably dislike this answer, but remember it when you find yourself out of other solutions. 您可能不喜欢这个答案,但是当您发现自己脱离其他解决方案时,请记住它。 ;) ;)

I've been experienced the same issue. 我遇到过同样的问题。 My seleniumn tests run under jenkins slave installed as windows service, using "Local System" account with "Allow service to interact with desktop" option enabled in windows 7. Some test cases were always failed due to incorrect display resolution. 我的seleniumn测试在安装为Windows服务的jenkins slave下运行,在Windows 7中使用“允许服务与桌面交互”选项使用“本地系统”帐户。由于显示分辨率不正确,一些测试用例总是失败。

I logged in to the console of the windows VM (EXSI Server + VMware Fusion), changed the resolution to 1400x900, and restart the windwos VM. 我登录到Windows VM(EXSI Server + VMware Fusion)的控制台,将分辨率更改为1400x900,然后重新启动windwos VM。 Everything works well now. 现在一切都运作良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在jenkins slave机器上运行selenium脚本,但脚本在Master机器中 - How to run selenium scripts in jenkins slave machine but the scripts are in Master machine 硒测试在本地计算机上运行,​​但不通过詹金斯运行 - Selenium tests run on local machine but not through jenkins Jenkins 作业不会在从属虚拟机上执行,直到用户登录从属虚拟机 - Jenkins job does not execute on slave until user logs into the slave virtual machine 可以在Debian虚拟机上运行Selenium测试吗? - Can One Run Selenium Tests on Debian Virtual Machine? 由于虚拟机 memory,Selenium 测试在 Jenkins 上崩溃 - Selenium test's crashing on Jenkins because of virtual machine memory 最小化Internet Explorer 9或虚拟机时,硒测试不会运行 - Selenium tests does not run when Internet explorer 9 or Virtual machine is minimised 如何在虚拟机上通过 Jenkins 运行 Selenium 服务器(RC)? - How to run Selenium server (RC) via Jenkins on a virtual machine? 如何使用Jenkins将Selenium测试重定向到远程计算机 - How to redirect Selenium tests to remote machine using Jenkins 如何强制在 jenkins 从节点上运行的 Selenium 测试在前台运行? - How can I force Selenium tests running on a jenkins slave-node to run in the foreground? 虚拟机上的Selenium Webdriver - selenium webdriver on virtual machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM