codemuke
codemuke

Reputation: 11

How to open NW.js exe app and test it? is it really possible to automate and access the web elements? I wrote a script in JavaScript

test case for nw.js official docs nw.js test

the above test case for nw.js is in python. I wrote the same in JavaScript.I face error and it's very hard for me access nw.exe app web elements. nw.exe is similar like browser only but i find it very hard to establish connection between selenium webdriver and nw.exe app.

require('chromedriver');


const {Builder, By, Key} = require('selenium-webdriver');

const chrome = require('selenium-webdriver/chrome');


let options = new chrome.Options();

options.setChromeBinaryPath('dist/src/nw.exe'); // mentioning the PATH to NW.exe


async function openNwExe(){

    let driver = new Builder()

    .forBrowser('chrome')  

    .setChromeOptions(options)

    .build();   


    await driver.get('src/views/index.html'); //to open the front page of the app    

    

    try{

        //trying find the input box element and sending the key values

        await driver.findElement(By.id("input")).sendKeys("San Francisco");              

    }    

    finally{

        // Close the WebDriver session and exit the NW.js application

        await driver.sleep(1000);

        await driver.quit();

      }

}

openNwExe(); //function call

I get the following error if i run the above script

C:\Users\..\node_modules\selenium-webdriver\lib\error.js:524

    let err = new ctor(data.message)              ^


SessionNotCreatedError: session not created: Chrome failed to start: exited normally.

  (session not created: DevToolsActivePort file doesn't exist)

  (The process started from chrome location C:\Users\..\src\src.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

    at Object.throwDecodedError (C:\Users\..\node_modules\selenium-webdriver\lib\error.js:524:15)

    at parseHttpResponse (C:\Users\..\node_modules\selenium-webdriver\lib\http.js:601:13)

    at Executor.execute (C:\Users\..\node_modules\selenium-webdriver\lib\http.js:529:28) 

    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {

  remoteStacktrace: '\tGetHandleVerifier [0x00007FF6F8F27892+54818]\n' +

    '\t(No symbol) [0x00007FF6F8E96AC2]\n' +

    '\t(No symbol) [0x00007FF6F8D4DA3B]\n' +

    '\t(No symbol) [0x00007FF6F8D7C202]\n' +

    '\t(No symbol) [0x00007FF6F8D7802E]\n' +

    '\t(No symbol) [0x00007FF6F8DB67FB]\n' +

    '\t(No symbol) [0x00007FF6F8DAE883]\n' +

    '\t(No symbol) [0x00007FF6F8D83691]\n' +

    '\t(No symbol) [0x00007FF6F8D848D4]\n' +

    '\tGetHandleVerifier [0x00007FF6F928B992+3610402]\n' +

    '\tGetHandleVerifier [0x00007FF6F92E1860+3962352]\n' +

    '\tGetHandleVerifier [0x00007FF6F92D9D4F+3930847]\n' +

    '\tGetHandleVerifier [0x00007FF6F8FC3646+693206]\n' +

    '\t(No symbol) [0x00007FF6F8EA1628]\n' +

    '\t(No symbol) [0x00007FF6F8E9D934]\n' +

    '\t(No symbol) [0x00007FF6F8E9DA62]\n' +

    '\t(No symbol) [0x00007FF6F8E8E113]\n' +

    '\tBaseThreadInitThunk [0x00007FF97A62257D+29]\n' +

    '\tRtlUserThreadStart [0x00007FF97B94AA78+40]\n'

}


Appreciate any help!

Upvotes: 0

Views: 214

Answers (1)

Ayush C.
Ayush C.

Reputation: 54

Add the nwapp argument to chrome.Options. When specifying the path to NW.js binary, make sure the chromedriver binary is in the same directory. I've also added a corresponding package.json and index.html.

In this example, I am assuming test.js, index.html and package.json are in the same directory:

/path/to/nw-test/index.html
/path/to/nw-test/package.json
/path/to/nw-test/test.py

test.js

const {Builder, By} = require('selenium-webdriver');

const chrome = require('selenium-webdriver/chrome');

options.addArguments([
    "nwapp=/path/to/nw/project"
]);

options.setChromeBinaryPath('/path/to/nw.exe');

async function openNwExe(){

    let driver = new Builder()

    .forBrowser('chrome')  

    .setChromeOptions(options)

    .build();

    try{

        await driver.findElement(By.id("input")).sendKeys("San Francisco");              

    }    

    finally{

        await driver.sleep(3000);

        await driver.quit();

      }

}

openNwExe(); //function call

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>NW.js Selenium Example</title>
    </head>

    <body>
        <input id="input" value=""/>
    </body>
</html>

package.json

{
    "name": "nw-selenium-javascript-example",
    "main": "index.html"
}

p.s.: Here are examples of how to use the ServiceBuilder API (an alternative method of testing) in Python and javaScript:

Upvotes: 0

Related Questions