UI issues while executing UFT test via Jenkins - jenkins

I am having Jenkins running as a service and have a job to execute UFT tests on a remote slave. As part of the pipeline I am required to un-install our product, restart the slave, install the product (latest version) and start the test execution.
Since UFT tests need a dedicated UI, I am trying to launch a mstsc connection to the test VM from a temp VM. But since Jenkins is running as a service the mstsc process runs as a background process on the temp VM. Due to this UFT tests don't get a dedicated UI and some of the tests fail.
Tried running Jenkins using the war file instead of service. But after 30-40 mins or so the master slave connection drops.
Any workaround / tweak would be appreciated.

you need to run your jenkins remote agent(war) as a normal Process and not as a service, otherwise, as you mentioned there is no Desktop for them.
My Proposal:
Make sure the jenkins remote agent is running as a normal OS process (on both VMs). You can have a Windows Scheduled Task that launches this Process on Logon and Checks every 5 minutes if it is still alive (if not restarts it)
After the Temporary VM (Let's call it a Gateway) woke up your Test VM, the Test VM should execute a tscon command which will redirect the currently active RDP Session to the console (the Physical Monitor - which on Virtual machines well it's virtual). This will help you having your UI Session alive until the next restart, without having to bother about the Gateway
tscon here. Example: tscon rdp-tcp#1 /dest:console This can be solved again with a Scheduled Task which is executed At Logon (waiting a few Seconds just to make sure)
Have Caffeine.exe or MouseJiggle.exe running in the background as Processes (also launched at Logon) on your Test Computers to make sure the SCreen is never Locked or any Screen Saver is activated. Both tools are free.
If your Jenkins Connection drops that is a different issue has nothing to do with UFT. In my case this combination works perfectly fine. It is also easy to automate the installation of these things. Windows Batch and Vbs can do all these things for you. (Putting the mentioned tools to your %PATH% and creating Scheduled Tasks Programmatically)
** Bonus Tipp: In order to avoid a taskkill java.exe command killing your remote agent, you can simply rename the java.exe of your jvm to jenkins_remote_agent.exe and use that as your jenkins remote agent executable

UFT requires an interactive session for some Win32 operations.
In the Tools ⇨ Options menu, select General ⇨ Run Sessions there you will find an option to Enable continued testing on locked/disconnected remote computers, this may help in your case too.

Related

Unable to open GUI Application through Jenkins

I'm new to Jenkins, I've created a Jenkins freestyle job used necessary plugins to invoke desktop application. When I execute the job with user credentials, I cannot see the application but application got up and logged on with user credentials. I'm doing GUI Automation which causes failures all the times when I try to run the job.
I created a batch file on HOST, calling the batch file through Jenkins. I have tried injecting the environment for job. I have enabled interactive services and Jenkins-slave on HOST machine. I tried to change NT/System user to Specific user. I enabled interactive services in both conditions. I'm not sure what I'm missing here. Do I need to install anything else, so far I have Jenkins-slave.exe on my HOST, I managed to generate executable Jar file using that.
Any help on this will be appreciated.
I'm calling the batch file, Jenkins cannot find the application opening apparently, it returning error as None type Object(Python) as described in screenshot.errors on Jenkins Job execution
I had a similar issue when I was trying to run Selenium UI Test on Windows Slave.
When the Slave is connected to Windows as a Service, then it does not bring up the application in foreground. It runs only in background even if you enable the service to interact with the desktop.
I had to change my browser to headless browser and then my test cases were passed in background mode.
My Old Question

How to reboot Jenkins node using shell in Groovy

I am writing a Groovy script to perform an automatic reboot of Windows servers. In the script, I am first taking the nodes offline, then checking to see if there are any builds, if there aren't, then perform a restart.
I wanted to use the safeRestart() method but it doesn't support the import statement I am using when looping through the nodes. I have seen an execute() method which basically executes a shell line of code in groovy.
How would I execute a restart of the Windows computers using execute()?
Not sure if this will answer your question directly, but will point in the right direction ...
You can leverage this S/O question: Run a remote command on all Jenkins slaves via Masters's script console or this Gist: run_command_on_all_slaves.groovy
btw: Jenkins API does seem to support running a script directly on the server (Computer).
Your actual command should be shutdown /r`
I don't believe you can do this unless the Node is on-line. Disconnecting the node stops the Jenkins slave process, then there's nothing running on the node, so not sure what control you'd have. Instead you want to block the queue and let the existing jobs finish:
Jenkins.instance.getNode('Node-Name').toComputer().setAcceptingTasks(false)
and check:
Jenkins.instance.getNode('Node-Name').toComputer().countBusy() == 0
Then run your (work on server) restart command
When the server is available again, launch the node and open the queue.
Jenkins.instance.getNode('Node-Name').getComputer().launch()
Jenkins.instance.getNode('Node-Name').getComputer().setAcceptingTasks(true)
Hope that helps.

Jenkins foreground task

I have two Jenkins machines.
Both run windows batch commands
When I start programs on one, they start in the background (Staging box).
When I start programs on the other, they start in the foreground, and you can see the window and watch the program as it's running (Production box).
I'm trying to test a program which only works in the foreground (it's a Cocos game executable and probably needs to be in the foreground to run properly).
I need to know what Jenkins-settings to change so that my staging-Jenkins box behaves the same as my Production-Jenkins box.
I have already tried:
The jenkins windows service is running as the currently logged in user.
Most other questions talk about forcing it to the background, which is the opposite of my problem.
Finally figured it out.
If you are running Jenkins as a Windows service, then the service is running in the background, and thus the programs started by Jenkins will also be run in the background.
If you run Jenkins in the foreground (Ie, typing "java -jar jenkins.war" in a console window), then programs started by Jenkins will also be in the foreground (since the foreground console window is the Jenkins process).
Jenkins-Slaves run as a service, but they run with a foreground window, so they show up in the foreground of the slave machine.
No need to run jenkins as jar. Rather one can configure the same system(master/ or some other system) as slave in Manage Jenkins -> Manage Nodes. Then connect the slave system with master.
In the jenkins job configuration, select node name in the job general configuration section mentioning the slave system where job will be running.
Then build the job. It worked for me.

How to support disconnections or reboots for Jenkins slaves on Windows?

I have many long running jobs that take almost a day to complete. Splitting is not possible. If the network fails then all progress is lost.
How can a slave survive disconnections?
EDIT 1
I have around 300 slaves running in Windows tied to one single Jenkins instance.
Slaves are connected using the manual method java - jar slave.jar -jlnpUrl <serverUrl> <slaveName>. I cannot run them as a regular Windows service because some tests manipulate GUI elements and require a real interactive session otherwise test fail.
EDIT 2
According to Jenkins Cookbook I should be using Cygwin + OpenSSH approach instead of custom script with JLNP-connector. Could this improve stability?
Jenkins was not originally designed for builds to survive across server or slave restarts. There is a CloudBees Long-Running Build plugin that supports long-running builds but, unfortunately, it is available only for enterprise users and still beta.
I didn't find any free alternative and would suggest you to try to improve your network stability and to split your long running jobs. At least you can divide your tests on logical groups (test suites).
Jenkins now has a workflow plugin. It claims to handle "server" restart and loss-of connectivity with slave.
From the link
A key feature of a workflow execution is that it's suspendable. That
is, while the workflow is running your script, you can shut down
Jenkins or lose a connectivity to a slave. When it comes back, Jenkins
will still remember what it was doing, and your workflow script
resumes execution as if it was never interrupted. A technique known as
the "continuation-passing style" execution plays a key role in
achieving this.
(not tested at all)
Edit: Copied from #Jesse Glick's comments :
Workflow is open source and available for anyone running Jenkins 1.580.1+ or later. CloudBees Jenkins Enterprise does include a checkpoint feature, but this is not necessary simply to have a build survive slave disconnections and Jenkins restarts: that is automatic

One execution per Windows VMware VM as Jenkins slaves?

I am trying to run some automated acceptance tests on a windows VM but am running into some problems.
Here is what I want, a job which runs on a freshly reverted VM all the time. This job will get an MSI installer from an upstream job, install it, and then run some automated tests on it, in this case using robotframework (but that doesn't really matter in this case)
I have setup the slave in the vSphere plugin to only have one executor and to disconnect after one execution. On disconnect is shutsdown and reverts. My hope was this meant that it would run one Jenkins job and then revert, the next job would get a fresh snapshot, and so would the next and so on.
The problem is if a job is in queue waiting for the VM slave, as soon as the first job finishes the next one starts, before the VM has shutdown and reverted. The signal to shutdown and revert has however been sent, so the next job is almost immedieatly failed as the VM shuts down.
Everything works fine as long as jobs needing the VM aren't queued while another is running, but if they are I run into this problem.
Can anyone suggest a way to fix this?
Am I better off using vSphere build steps rather than setting up a build slave in this fashion, if so how exactly do I go about getting the same workflow to work using buildsteps and (i assume) pipelined builds.
Thanks
You can set a 'Quiet period' - it's in Advanced Project Options when you create a build. You should set it at the parent job, and this is the time to wait before executing the dependent job
If you'll increase the wait time, the server will go down before the second job starts...
Turns out the version of the vSphere plugin I was using was outdated, this bug problem is fixed in the newer version

Resources