Search code examples
mavenjenkinsjava-8exeautoit

Launch exe file from maven application running by Jenkins


I'm using Maven test application having Selenium for test automation, the application is running by Jenkins I have implemented an exe file containing AutoIt script automating the file select in windows explorer (without the presence of an input of file type in the tested application), the exe is working fine when executed manually (double click the exe), the expected behaviour is occurring

WinActivate("Open")
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1","C:\Users\Administrator\Pictures\test\test_file.png")
ControlClick("Open","","Button1")

I'm facing a problem when integrating the exe launch in maven test application, the exe seems executed but no effect is occurring on the targeted window, I have tried with Runtime.exec and ProcessBuilder :

Thread.sleep(2000);
// Attempt with Runtime.exec
Process process = Runtime.getRuntime().exec("C:\\Users\\Administrator\\Documents\\AutoIt\\FileUpload.exe");
process.waitFor();
int value = process.exitValue();
MyApp.logInfo(testContext, "Runtime.getRuntime: " + value);

// Attempt with ProcessBuilder
ProcessBuilder pb = new ProcessBuilder("C:\\Users\\Administrator\\Documents\\AutoIt\\FileUpload.exe", "file to start with vlc");
process = pb.start();
process.waitFor();
value = process.exitValue();
MyApp.logInfo(testContext, "ProcessBuilder: " + value);

The exit value of both java.lang.Process are 0 (normal termination), but the expected behaviour is not happening, is the problem on Jenkins that is running the whole process in a particular thread ?

Am I missing something ? Thanks a lot in advance


Solution

  • The problem was caused by Jenkins itself, it was installed as windows application (msi) which not allow the option "interact with desktop", even you enable it in the jenkins service "Allow service to interact with desktop" (not supported after windows 7)

    I have solved the problem by running Jenkins from WAR file:

    • Download a stable version from Jenkins

    • Run the WAR by bat file containing launch script, something similar to:

       TITLE [Jenkins]
       @echo Running Jenkins...
       SET JENKINS_HOME=C:\Users\admin\.jenkins
       java -Xrs -Xmx1024m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true -jar jenkins_2_355.war --httpPort=8080
       pause
      
    • After launch, open Jenkins at http://localhost:8080/

    • Set required tools & install required plugins

    • Maintain the existing Jenkins jobs: copy the content of jobs folder from old jenkins to the new one (requires Jenkins restart)