0

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

Maddy
  • 29
  • 6
  • 1
    Cross-posted: https://sqa.stackexchange.com/questions/44195/can-anyone-please-provide-or-guide-me-on-javascript-code-for-winium-implementati/44200#44200 – Niels van Reijmersdal Apr 09 '20 at 11:26
  • Taken down the duplicate form stack exchange.. Thanks for your suggestion. But I am looking for APIs from winium JS binding and their implementation. Looking into other bindings might result into beating around the bushes for equivalent JS syntax... However I'll consider your suggestion and look for either developing JS binding or combining WD (selenium-webdriver) and winium to see if it works. Thanks . – Maddy Apr 09 '20 at 19:12

1 Answers1

2

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));
  }
Maddy
  • 29
  • 6
  • I ran your code but getting below error - (node:10572) UnhandledPromiseRejectionWarning: UnsupportedOperationError: 'css selector' is not valid or implemented searching strategy. @maddy – Raj Kumar Dec 12 '20 at 17:17
  • 1
    Well I've already included this error and it's solution in my accepted answer. Please go through it one more time. – Maddy Dec 13 '20 at 18:38
  • Can you help me to switch to child window from parent vice versa? @maddy – Raj Kumar Dec 17 '20 at 12:01
  • Well sure @raj ! More than happy to help. Just share the code that you have been trying with...... If u are able to launch a window over winium rest is all just plain old syntax of selenium. But let's see what's troubling you. – Maddy Dec 18 '20 at 17:28