1

I am trying to give some keypresses from Jenkins and possibly type something unto the notepad. the program works fine when I ran it from cmd manually. but it does not work when I run it using Jenkins. Why is this happening? is it even possible to give key presses from Jenkins?

Here's the code which I'm trying to run in Jenkins

var ks = require('node-key-sender');

function test() {
    ks.startBatch()
        .batchTypeKey('a', 500)
        .batchTypeKey('b', 500)
        .batchTypeKey('c', 500)
        .batchTypeKey('d', 500)
        .batchTypeKey('e', 500)
        .batchTypeKey('f', 500)
        .batchTypeKey('g', 500)
        .batchTypeKey('h', 7000)
        .batchTypeKey('i', 2000)
        .batchTypeKey('j', 500)
        .batchTypeKey('k', 500)
        .batchTypeKey('l', 500)
        .batchTypeKey('y', 500)
        .batchTypeKey('z', 500)  
        .sendBatch();
}


setTimeout(()=>{
    console.log("starting");
    test();
},1000)

note- The code does seem to run and output the line "starting". Irrespective of the place from which I ran it. ie. cmd/Jenkins. but it does not give keypresses when I run it using Jenkins.

kevin godfrey
  • 153
  • 1
  • 11
  • 2
    Jenkins runs on Windows as a service using the `SYSTEM` account in an environment where there is no graphical user interface available at all. So if there is started a Windows GUI application like `Notepad` during the execution of a Jenkins job, the executable is started and running in background, but without any graphical user interface which means it is not possible to send keys to main application window of the started GUI application because of there is no application window in this use case. So your approach will never work. – Mofi Jul 20 '21 at 07:33
  • 2
    Look on the Stack Overflow search results [\[jenkins\] interact GUI application](https://stackoverflow.com/search?q=%5Bjenkins%5D+interact+GUI+application) or [\[jenkins\] automate GUI application](https://stackoverflow.com/search?q=%5Bjenkins%5D+automate+GUI+application) or [\[jenkins\] test GUI application](https://stackoverflow.com/search?q=%5Bjenkins%5D+test+GUI+application). – Mofi Jul 20 '21 at 07:39
  • @Mofi What if I run Jenkins using the .war file instead of running it as windows as a service. will I be able to interact with GUI then? or is it like, it doesn't matter how I run it? – kevin godfrey Jul 20 '21 at 08:31
  • The `SYSTEM` account is used mainly for Windows services as on using this account, there is no user interface available at all making the running processes very secure. The communication with processes started in environment of `SYSTEM` account is only possible via streams (pipes). It does not matter how the GUI application is started on being started in environment of `SYSTEM` account. There are posted answers on how to use a GUI application in a Jenkins job by using a slave which is running only on user logged in and then using the account of this user, i.e. run the job in user environment. – Mofi Jul 20 '21 at 12:26
  • See for example [Jenkins on Windows and GUI Tests without RDC](https://stackoverflow.com/questions/10177708) with answers with multiple solutions. I recommend to first read all of them and then decide which one to try first as the question and the answers are several years old. There are most likely even better solutions posted somewhere in world wide web. Please search for them by yourself. – Mofi Jul 20 '21 at 12:31
  • @Mofi Ok thanks will do – kevin godfrey Jul 20 '21 at 12:36

0 Answers0