NetBeans GUI tests on Jenkins + Windows (转)

from http://forgetfulprogrammer.wordpress.com/tag/interact-with-desktop/

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”.

 

=====================

Finally, I found the real explanation from here:

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_HOMEin omcat5.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.

原文地址:https://www.cnblogs.com/backpacker/p/3266441.html