WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Run WinAppDriver tests from Jenkins

Open pzelazo opened this issue 6 years ago • 8 comments

Hi

I have a tests in winAppDriver + Nunit on the one virtual machine and Jenkins installed on another virtual machine.

How can I run the test cases written in winAppDriver from Jenkins? Is there any tutorial totally step by step?

pzelazo avatar Jun 09 '20 12:06 pzelazo

We have Azure tasks for starting and stopping WinAppDriver in Azure DevOps and this works perfectly for us.

For Jenkins, I think you can try solution suggested in below link.

https://github.com/Microsoft/WinAppDriver/issues/367

VijayHugar avatar Jun 10 '20 08:06 VijayHugar

That's very good if it works perfectly but what if I can't do anything out of my company servers because of the security reasons? Can I use some CI on virtual machine of my company to execute WinAppDriver tests?

pzelazo avatar Jun 10 '20 09:06 pzelazo

Yes, you can use. If you are planning to execute through CI, make sure you run target machine interactively through agent as automation involves UI interaction.

VijayHugar avatar Jun 10 '20 11:06 VijayHugar

So again - do you have any tutorial how to set up WinAppDriver test cases on Jenkins and run CI? I am fresh in this case.

pzelazo avatar Jun 10 '20 12:06 pzelazo

I have no idea about Jenking, I use Azure DevOps. However, setup should be same across any DevOpens and you can find details of steps that I mentioned in the below issue.

https://github.com/microsoft/WinAppDriver/issues/1179#issuecomment-636881885

VijayHugar avatar Jun 11 '20 08:06 VijayHugar

@pzelazo Can you please close this issue if your concern is resolved ?

VijayHugar avatar Jun 12 '20 10:06 VijayHugar

@VijayHugar this case is NOT resolved. I don't know how to set up WinAppDriver on Jenkins. I understand that the most important here is to just close the ticket and don't care about problems.

As you wish I will close this ticket.

pzelazo avatar Jun 12 '20 11:06 pzelazo

I am able to run WinAppDriver tests using Jenkins and without RDP connection as follows:

Pre-Requisite

  1. 2 windows VMs with 1 user account (administrator)
  2. Follow below configuration

================================== Configuration in Jenkins and at VMs

  1. My setup has 2 VMs (Virtual Machines) with only 1 administrator as user
  2. Configured 2 VMs as nodes in jenkins (a.k.a Jenkins slave machines). My Jenkins master is running on Ubuntu VM.
  3. Once configuration of 2 VMs done, Login to VMs, login to jenkins in VMs, go to Manage Jenkins -> Manage nodes -> <your_VM_Node> and install Jenkins as Service.
  4. 2 VMs now shows running status in Jenkins nodes.
  5. Running Jenkins as service on slave machine doesn't help you in executing tests. Hence create a task schedule
  6. cd to jenkins directory on slave machine and as shown in jenkins UI page execute the following commands in command prompt (in my case i had directory at C:\Jenkins) C:\Jenkins>echo d88dae2224304e85ef14f0ec23657834256685c5a7e1a52f5dbc8bacbaab53 > secret-file C:\Jenkins>java -jar agent.jar -jnlpUrl http://<Jenkins_IP/URL>:8080/computer/<node_name>/slave-agent.jnlp -secret @secret-file
  7. Repeat the above step 6) in another VM
  8. Follow the link https://expert-advice.org/windows-server/how-to-set-up-auto-login-windows-server-2012-and-2016/ to set up automatic windows logon
  9. Create a bat script and place it in C:\Jenkins directory on VM cd
    cd C:\Program Files (x86)\Java\jre1.8.0_91\bin java.exe -jar C:\Jenkins\agent.jar -jnlpUrl http://<Jenkins_IP/URL>:8080/computer/<node_name>/slave-agent.jnlp -secret @C:\Jenkins\secret-file
  10. Create task scheduler as follows in both VMs Open "Task Scheduler" on your windows machine Start -> Run: task Scheduler Create a basic task (Menu: Action -> Create Basic Task) First page of the wizard: Name: Jenkins Slave Description (optional) Click Next Next page of the wizard When do you want the task to start: select "When the computer starts" Click Next Next page of the wizard What action do you want the task to perform: select "Start a program" Click Next Next page of the wizard Program/Script: enter full path of batch script created as in step 9) Click Next Next page of the wizard Click the check box "Open the Properties dialog for this task when I click Finish Click Finish Update the task's properties On the General tab Select the user to run the task as Select "Run only when the user is logged on" and "Start at logon" On the settings tab Uncheck "Stop the task if it runs longer than" Check "Run the task as soon as possible after a scheduled start is missed" Check "If the task failed, restart every: 10 minutes", and "Attempt to restart up to: 3 times" Click OK Start the scheduled task and again check that Jenkins can connect Go back to the node's web page in Jenkins. If everything works then page should say "Connected via JNLP agent"
  11. Restart VMs and check Automatic Windows Logon and task scheduler job runs automatically. See both nodes are online after restart.
  12. Create a batch script and place it in C:\Users\Administrator\Desktop\new.bat as follows: @echo off set "name=Administrator" for /f "tokens=3" %%a in ('qwinsta "%name%"^|findstr /r /b /i ".*rdp"') do ( tsdiscon %%a )
  13. Now below is the pipeline and freestyle projects created in jenkins

=========================== Before start of jenkins job

  1. 1 VM is dedicated for running windows GUI tests (WinAppDriver tests)
  2. 2nd VM is for remote desktop connection to 1st VM.
  3. Launch 2nd VM via RDP and from this VM RDP to 1st VM.
  4. Now, trigger Jenkins pipeline job which will disconnect the RDP sessions to both VMs and will trigger tests
  5. By this way you can run WinAppDriver tests without RDP connection

============ Pipeline job

def agent1 = 'windows-slave' // 1st VM def agent2 = 'windows-slave2' // 2nd VM

node (agent1) { bat label: '', script: 'C:\Users\Administrator\Desktop\new.bat' } node(agent2) { echo "${agent2} online" bat label: '', script: 'C:\Users\Administrator\Desktop\new.bat' bat 'cmdkey /generic:TERMSRV/ /user:Administrator /pass:' bat 'mstsc /v: /f' //sleep(time: 1, unit: 'MINUTES') } node(agent1) { echo "${agent1} online" } build job: 'WinAppDriver-Test', quietPeriod: 30

============================================= Freestyle project (named: 'WinAppDriver-Test')

MSBuild (Using MSBuild Plugin) VSTEST (Using VSTEST plugin)

Gurumatam avatar Jul 31 '20 12:07 Gurumatam