Search code examples
javascriptwindowsautomationwinium

JavaScript implementation of winium for windows application automation


I need to write windows app automation script using winium with JavaScript. I've done this using Java as lots of help and material is available for references. But I need to do the same in JavaScript and I don't know the equivalent APIs of winium in JavaScript binding.

Link of winium desktop

Winium Java implementation

Constraints below -

Tool of choice - winium

Language of choice - JavaScript

Application - any Windows app like. Notepad


Solution

  • Well here's how i was able to do it with JS (selenium + winium.desktop.driver). Hope this will be useful.

    1. Keep Winium.Desktop.Driver instance running on port (9999 default) and use the same address in the capability while building the service.
      1. Create selenium instance over the winium server using the builder API.
      2. Use default APIs from winium to interact with the windows application.

    Note : In case you get following error consider downgrading the selenium-webdriver to 2.45.0.

    Error - UnsupportedOperationError: 'css selector' is not valid or implemented searching strategy.

    Code snippet :

    "use strict"; 
    
      const {Builder, By, Key, until} = require('selenium-webdriver');
    
      (async function example() {
        let driver = await new Builder().usingServer('http://localhost:9999')
                                        .withCapabilities({
                                            "app": "C:\\WINDOWS\\system32\\notepad.exe",
                                            "platformName": "Windows",
                                            "deviceName": "WindowsPC"
                                         })
                                        .forBrowser('windows')
                                        .build();
    
        try {
    
           await sleep(2000).then(function(){});
           await driver.findElement(By.name('Text Editor')).sendKeys('123');
    
             }
     finally {
          console.log('Killed..');
          await driver.quit();
        }
      })();
    
      function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
      }