selenium2 run in Jenkins GUI testing not visible or browser not open but run in background浏览器后台运行不可见

简介:
http://wiki.hudson-ci.org/display/HUDSON/Tomcat
Tomcat from Windows
GUI Testing in Windows

Most Windows services -- including those run with the option "Allow service to interact with desktop" in Windows XP and Vista -- do not have access to many of the computer's resources, including the console display.  This may cause Automated GUI Tests to fail if you are running Apache Tomcat as a Windows Service and are doing any GUI testing. This is true at least for AWT and Abbot frameworks.  A typical error might look similar to this:

[junit] \# An unexpected error has been detected by HotSpot Virtual Machine:
[junit] \#
[junit] \# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d07baf4, pid=3260, tid=288
[junit] \#
[junit] \# Java VM: Java HotSpot(TM) Client VM (1.5.0_09-b03 mixed mode, sharing)
[junit] \# Problematic frame:
[junit] \# C [awt.dll+0xbaf4|awt.dll+0xbaf4]
[junit] \#

This limitation can be resolved by not running Tomcat as a Windows Service, but instead through a "Scheduled Task" as an Application that runs at logon. There are several options for doing this, an example would be  to run "$TOMCAT_HOME\bin\tomcat5.exe".  When setting up the scheduled task in Windows Vista consider choosing the check-box for "Run with highest privileges" from the general tab, as this removes the need to always provide administrator privileges and may resolve other issues as well.

*Note: This workaround/fix may or may not require an admin to be logged in during testing.  Running your tests while logged in as a standard user this is fine, but some modifications may need to be made for your individual configuration.

 

Running NetBeans application tests on Jenkins CI is quite easy. You just need to call the ‘test’ target in your NetBeans application’s build script (e.g. ANT build.xml) and Jenkins will do the rest. I initially setup Jenkins as a windows service to run my tests. This works fine for unit tests since they do not require a display to execute.

But recently I faced some issues when I wanted to run some functional (GUI) tests of a NetBeans platform app using a Jenkins job running on Windows. Since the Jenkins process could not access the windows display all the GUI tests were failing. On a linux box this issue is addressed by using X display such Xvnc (available as a Jenkins plugin), but of course I cannot use X display on windows!

After googling around I came across a possible solution which was to enable the option “Allow service to interact with desktop” for my Jenkins service. But as promising as it seemed it did not work, my GUI tests continued to fail :(

Then I decided to stop and disable the Jenkins windows service and just ran it from the windows command prompt using the refreshingly simple command “java -jar jenkins.war”. Voila!!! It worked all my GUI tests were running without any problem and I can even see the GUIs opening and closing automagically on my windows desktop.

This solution was confirmed when I later stumbled upon the wiki here, which shows how to run GUI tests on ‘Hudson’ (Jenkins’ original name before Oracle knocked its head on a rock!) using a Tomcat container running on Windows. Although I didn’t use a servlet container such as Tomcat the solution applies to my situation as well.

So there you are, if you want to run GUI tests on Jenkins CI running onWindows do not configure it as a windows service instead run it from the command prompt or set it up as a scheduled task to run on windows logon using the command “java -jar jenkins.war”.

http://stackoverflow.com/questions/9618774/jenkins-selenium-gui-tests-are-not-visible-on-windows

When I run my selenium test (mvn test) from jenkins (windows) I see only the console output. I don't see the real browsers getting opened . How can I configure jenkins so that I can see the browsers running the test?

 

这个问题今天终于解决了:

1,对于selenium testing的GUI或者是browser不能看到,visible。但是可以看到的是在后台这个浏览器已经启动了,它实际上是后台运行的。

这个原因就是windows设置的服务安全问题,在slave机器上运行测试时候,千万不要把其中的Jenkins-slave设置为windows的服务,而是转到前台运行,意思就是,在slave机器上的JNLP不能以服务启动,只能是如下的运行方式:

image

这里注意了,千万不要点击“File”设置为服务启动,如果设置了后,即使你勾选了这个服务中的“Log on” Tab中的check "interact with desktop" , the desktop that is being referred to is invisble .,

it works after running the agent using JNLP

参考一:http://stackoverflow.com/questions/13639358/integration-of-selenium-webdriver-with-hudson-unable-to-open-the-browser

Hi All, Just to update: this problem is solved. below are the details: Put Internet driver in path Run Browser Hub for remote exectution java -Dwebdriver.server.session.timeout=0 -jar selenium-server-standalone-2.25.0.jar -role hub java -Dwebdriver.server.session.timeout=0 -jar selenium-server-standalone-2.25.0.jar -role node -hublocalhost:4444/grid/register Refer following links: code.google.com/p/selenium/wiki/Grid2code.google.com/p/selenium/wiki/RemoteWebDrivercode.google.com/p/selenium/wiki/WebDriverJs

 

参考二:https://gist.github.com/djangofan/5174433(已经写好了slave机器的配置信息)

hub设置脚本:

@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
TITLE WebDriver Grid Hub on 4444
 
ECHO *********************************************
ECHO *
ECHO * WebDriver grid Hub instance.
ECHO *
ECHO *  http://localhost:4444/grid/console
ECHO *
ECHO *********************************************
ECHO.
 
SET JAR=selenium-server-standalone-2.31.0.jar
SET "WGET=C:\Program Files (x86)\GnuWin32\bin\wget.exe"
 
IF NOT DEFINED JAVA_HOME (
  ECHO You must define a JAVA_HOME environment variable before you run this script.
  GOTO :ERROR
)
SET "PATH=%JAVA_HOME%\bin;%PATH%"
 
IF NOT EXIST %JAR% (
  ECHO Selenium standalone server .jar is missing.
  IF EXIST "%WGET%" (
    ECHO Hit any key to download Selenium standalone .jar file.
  PAUSE >nul
    "%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%JAR%
  ) ELSE (
    ECHO Wget.exe is missing. Install GNU Utils.
    GOTO :ERROR
  )
)
ECHO.
 
java.exe -jar %JAR% -role hub -hubConfig hubConfig.json -debug
IF NOT %ERRORLEVEL%==0 GOTO :ERROR
 
GOTO :END
:ERROR
ECHO There may have been an error.  Try running the script again.
pause
:END

 

grid node设置脚本:

@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
SET TITLETEXT=WebDriver Grid Node
TITLE %TITLETEXT%
 
SET CHROMEDRIVERZIP=chromedriver_win_26.0.1383.0.zip
SET CHROMEDRIVER=chromedriver.exe
SET JAR=selenium-server-standalone-2.31.0.jar
SET IEDRIVERZIP=IEDriverServer_Win32_2.31.0.zip
SET IEDRIVER=IEDriverServer.exe
SET "WGET=C:\Program Files (x86)\GnuWin32\bin\wget.exe"
 
ECHO *********************************************
ECHO *
ECHO * WebDriver Grid Node
ECHO * It requires that a WebDriver JSON Hub is already running, usually on port 4444.
ECHO * You can run more than one of these if each has its own JSON config file.
ECHO *
ECHO *********************************************
ECHO.
 
IF NOT DEFINED JAVA_HOME (
ECHO You must define a JAVA_HOME environment variable before you run this script.
GOTO :ERROR
)
SET "PATH=.;%JAVA_HOME%\bin;%PATH%"
 
IF NOT EXIST %JAR% (
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%JAR%
) ELSE (
ECHO Wget.exe is missing. Install GNU utils. & GOTO :ERROR
)
)
 
IF NOT EXIST %IEDRIVER% (
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%IEDRIVERZIP%
jar.exe xvf %IEDRIVERZIP%
DEL /Q %IEDRIVERZIP%
) ELSE (
ECHO Wget.exe is missing. & GOTO :ERROR
)
)
 
IF NOT EXIST %CHROMEDRIVER% (
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary --no-check-certificate https://chromedriver.googlecode.com/files/%CHROMEDRIVERZIP%
jar.exe xvf %CHROMEDRIVERZIP%
DEL /Q %CHROMEDRIVERZIP%
) ELSE (
ECHO Wget.exe is missing. & GOTO :ERROR
)
)
 
ECHO.
ECHO ======================
ECHO Grid Hub status : & netstat -an | FIND "4444"
ECHO ======================
ECHO.
 
TITLE %TITLETEXT%
java.exe -jar %JAR% -role node -nodeConfig node1Config.json -Dwebdriver.chrome.driver=%CHROMEDRIVER%
 
GOTO :END
:ERROR
pause
:END

Stop Hub 节点的脚本:

https://groups.google.com/forum/#!topic/selenium-users/_8A3q_ekw0g

尝试这下面的另外两种方法:

http://localhost:4444/selenium-server/driver?cmd=getLogMessages (Error 500 java.lang.NullPointerException)

http://localhost:4444/lifecycle-manager?action=shutdown (Does nothing)



本文转自hcy's workbench博客园博客,原文链接:http://www.cnblogs.com/alterhu/p/3210906.html ,如需转载请自行联系原作者。

目录
相关文章
|
7月前
|
Web App开发 Java 测试技术
多任务一次搞定!selenium自动化复用浏览器技巧大揭秘
多任务一次搞定!selenium自动化复用浏览器技巧大揭秘
|
7月前
|
Web App开发 Java 测试技术
《手把手教你》系列基础篇之(四)-java+ selenium自动化测试- 启动三大浏览器(下)基于Maven(详细教程)
【2月更文挑战第13天】《手把手教你》系列基础篇之(四)-java+ selenium自动化测试- 启动三大浏览器(下)基于Maven(详细教程) 上一篇文章,宏哥已经在搭建的java项目环境中实践了,今天就在基于maven项目的环境中给小伙伴们 或者童鞋们演示一下。
149 1
|
7月前
|
Web App开发 Java 测试技术
《手把手教你》系列基础篇之(三)-java+ selenium自动化测试- 启动三大浏览器(上)(详细教程)
【2月更文挑战第12天】《手把手教你》系列基础篇之(三)-java+ selenium自动化测试- 启动三大浏览器(上)(详细教程) 前边宏哥已经将环境搭建好了,今天就在Java项目搭建环境中简单地实践一下: 启动三大浏览器。按市场份额来说,全球前三大浏览器是:IE.Firefox.Chrome。因此宏哥这里主要介绍一下如何启动这三大浏览器即可,其他浏览器类似的方法,照猫画虎就可以了。
136 1
|
1天前
|
人工智能 API 数据库
Browser Use:开源 AI 浏览器助手,自动完成网页交互任务,支持多标签页管理、视觉识别和内容提取等功能
Browser Use 是一款专为大语言模型设计的智能浏览器工具,支持多标签页管理、视觉识别、内容提取等功能,并能记录和重复执行特定动作,适用于多种应用场景。
58 0
Browser Use:开源 AI 浏览器助手,自动完成网页交互任务,支持多标签页管理、视觉识别和内容提取等功能
|
2月前
|
Web App开发 缓存 Linux
高效Selenium测试技巧:轻松控制已开启的浏览器
【10月更文挑战第13天】在进行Selenium测试时,通常会启动新浏览器实例,但有时需要控制已开启的浏览器,以节省时间并更真实地模拟用户行为。这可通过设置Chrome为可远程控制并使用`Remote WebDriver`连接实现。需在启动Chrome时添加`--remote-debugging-port`参数,并通过Python脚本中的`webdriver.Remote`连接至指定端口。此外,还可利用会话ID(Session ID)重新连接浏览器,提高测试灵活性。需要注意浏览器版本兼容性及元素定位稳定性等问题,确保测试准确性和一致性。
399 1
|
3月前
|
数据采集 Web App开发 测试技术
使用Selenium与WebDriver实现跨浏览器自动化数据抓取
在网络爬虫领域,Selenium与WebDriver是实现跨浏览器自动化数据抓取的利器。本文详细介绍了如何利用Selenium和WebDriver结合代理IP技术提升数据抓取的稳定性和效率。通过设置user-agent和cookie来模拟真实用户行为,避免被网站检测和阻止。文章提供了具体的代码示例,展示了如何配置代理IP、设置user-agent和cookie,并实现了跨浏览器的数据抓取。合理的参数配置能有效减少爬虫被封禁的风险,提高数据抓取效率。
449 6
使用Selenium与WebDriver实现跨浏览器自动化数据抓取
|
2月前
|
Web App开发
Selenium操作360浏览器
Selenium操作360浏览器
55 0
|
4月前
|
数据采集 Web App开发 测试技术
使用Selenium调试Edge浏览器的常见问题与解决方案
在互联网数据采集领域,Selenium常用于自动化网页爬取。针对使用Edge浏览器时遇到的启动远程调试失败、访问受限及代理IP设置等问题,本文提供了解决方案。通过特定命令启动Edge的远程调试模式,并利用Python脚本配合Selenium库,可实现代理IP、User-Agent的设定及Cookie管理等高级功能,有效提升爬虫稳定性和隐蔽性。遵循步骤配置后,即可顺畅执行自动化测试任务。
1017 1
使用Selenium调试Edge浏览器的常见问题与解决方案
|
3月前
|
JavaScript 前端开发 测试技术
Selenium2Library实现基于GUI的测试
Selenium2Library实现基于GUI的测试
43 0
|
5月前
|
数据采集 Web App开发 JavaScript
快速参考:用C# Selenium实现浏览器窗口缩放的步骤
在C#结合Selenium的网络爬虫应用中,掌握浏览器窗口缩放、代理IP、cookie与user-agent设置至关重要。本文详述了如何配置代理(如亿牛云加强版),自定义用户代理,启动ChromeDriver,并访问目标网站如抖音。通过执行JavaScript代码实现页面缩放至75%,并添加cookie增强匿名性。此策略有效规避反爬机制,提升数据抓取的准确度与范围。代码示例展示了整个流程,确保爬虫操作的灵活性与高效性。
129 3