WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

WinAppDriver running in Jenkins

Open chrisumitratech opened this issue 7 years ago • 3 comments

Hi,

I am trying to run WinAppDriver tests using Jenkins instead of Azure DevOps. I have an Agent which is setup to run interactively but I get problems that the WinAppDriver stops unexpectedly, even when I run the agent process under an RDP session with me logged in.

I have seen this extension in Azure DevOps that ensures that the WinAppDriver is ready to start Testing.

https://marketplace.visualstudio.com/items?itemName=WinAppDriver.winappdriver-pipelines-task

Please can you tell me as much as possible what this does so I can execute the same via PowerShell or create a Windows Exe in Jenkins?

This will help a lot of the OSS projects that are trying to integrate WinAppDriver to their CI processes.

Thanks!

chrisumitratech avatar Sep 05 '19 09:09 chrisumitratech

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)

Enjoy testing!!!!!

Gurumatam avatar Jul 31 '20 12:07 Gurumatam

That is the best solution i saw. Also, there is ability to run all o master, but I didn't try. RDP allows to connect lo localhost just but connecting on 127.0.0.2. So most probably it can create interactive session even from jenkins service. But unfortunately autologon is forbidden for me and RDP has interactive logon message, which also not allow to start simple RDP. So I just connect from any place to agent via RDP, make session active until box restart and use it. To do that, you need next:

  1. Connect to agent via RDP
  2. Run next command in powershell:

$OutputVariable = (qwinsta | findstr ">") | Out-String $sessId = $OutputVariable.Split(" ").Where({ $_.Trim() })[2] tscon $sessId /dest:console

But in this case you cannot control screen resolution. So I change it also in powershell applying this script: https://stackoverflow.com/questions/37678996/setting-screen-resolution-on-windows-10/64404243#64404243

So if screen resolution is more important for you, your step 2 will be like <execute script from stackoverflow> $OutputVariable = (qwinsta | findstr ">") | Out-String $sessId = $OutputVariable.Split(" ").Where({ $_.Trim() })[2] tscon $sessId /dest:console ; Set-ScreenResolution -Width 1920 -Height 1080

Note that after tscon you will be disconnected, so you wont be able to check result of Set-ScreenResolution visually.

rburtnykx avatar Oct 27 '20 22:10 rburtnykx

We were able to configure WAD on JENKINS using instructions here : https://github.com/microsoft/WinAppDriver/pull/1368

smilinrobin avatar Nov 17 '20 08:11 smilinrobin