Is it actually feasible to automate and interact with web elements in a NW.js exe app? I have created a JavaScript script to open and test it

A test case for nw.js can be found in the official NW.js documentation. The original test case is written in Python, but I attempted to recreate it in JavaScript. However, I encountered an error that made it difficult to interact with elements in the nw.exe application, which is similar to a browser.


    const {Builder, By} = require('selenium-webdriver');
    
    let driver = new Builder()
      .forBrowser('chrome')
      .build();

    try {
      await driver.get('src/views/index.html');

      // Attempting to find and interact with the input box element
      await driver.findElement(By.id("input")).sendKeys("San Francisco");
    } finally {
      await driver.sleep(1000);
      await driver.quit();
    }
  

When running the script above, I encountered the following error:


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

Any help would be greatly appreciated!

Answer №1

Include the nwapp parameter in the chrome.Options while specifying the path to the NW.js binary file. Ensure that the chromedriver binary is located in the same directory as well. Additionally, I have created a corresponding package.json and index.html.

In this scenario, assuming test.js, index.html, and package.json exist within 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.: Explore these examples demonstrating the use of the ServiceBuilder API for testing purposes in Python and JavaScript:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for preventing users from entering special characters into input fields

How can I prevent users from entering the # character into an HTML input field? I attempted to use the pattern attribute, but it does not seem to be effective. I included this pattern in my input element: pattern="[^-#]+" I expected that this would disa ...

I am requesting for the average to be adjusted based on the user's choice between Hindi or English percentage scale

Currently, the average is being calculated in the HTML code. When a user input is changed, the average breaks. What can be done to update the average for each individual person? Controller var app = angular.module('myApp', []); app.controller( ...

Is there a way for me to attach a link to a picture displayed in a lightbox that directs to an external ".html" file?

I have a platform where users can view images in a gallery and when they click on an image, it opens up in a lightbox. I am trying to add a feature where the opened image can be clicked again to redirect the user to an external page. I attempted to nest t ...

Is there a way to retrieve metadata from a web URL, like how Facebook automatically displays information when we share a URL in a status update?

Is there a way to fetch metadata such as title, logo, and description from a website URL using AngularJS or JavaScript? I am looking for a solution similar to Facebook's status update feature that automatically loads metadata when you paste a website ...

PHP is failing to send a JSON response, but no errors are being logged in the PHP error log or displayed in the

Hey there, I'm feeling a bit frustrated and really not a fan of Javascript at all. Can someone please help me figure out why this isn't working? It's frustrating because everything seems fine when I return a simple string instead of trying t ...

Leveraging Selenium for targeting a particular <li></li> dataset

As I dive into the world of Selenium with Python, please bear with me if my question is not articulated perfectly. View Inspect Element Image I have managed to retrieve json data from a real-time data stream. However, when dealing with a different device ...

Unable to Access RadioButton for Search Functionality with Jquery Ajax

When attempting to perform a search using two radio buttons, a text box, and a button with jQuery AJAX, I encountered an issue. No matter which radio button is selected, the value of the option is always TaskName when sending the searchByOption to the cont ...

"Is it possible to conditionally render a component depending on the state in

One of the challenges I'm facing is customizing a filter icon from MaterialUI. My goal is to change its color to black when a checkmark is checked, and adjust its position accordingly. Additionally, when a box is checked, it should fill in setFilters. ...

The Unicode range [uXXXX] in Regex is not recognized during the AJAX request

I am currently facing an issue with removing control characters (e.g. \u0005) from the ajax response string. I have implemented a regular expression for this purpose: msg = msg.replace(/[\x00-\x1F\x7F-\x9F]/g, ''); Inter ...

The bootstrap card layout breaks with Google Maps in Chrome and is not functioning properly

I have encountered an issue with the bootstrap card layout and Google Maps integration. When I move the Google Map to a card in a right column, it does not display properly. However, placing it in the first column works perfectly fine. This problem seems t ...

Changing the color of dots in a React Material-UI timeline

Hey there, I'm trying to change the default color of the MUI TimelineDot component. I attempted to do so by adding this code: <TimelineDot sx={{ '& .MuiTimelineDot-root': { backgroundColor: '#00FF00' }, }} /> Unfortunate ...

Customize the MUI (JoyUI) Autocomplete feature in React using react-hook-form to display a unique value instead of the label

Currently, I am in the process of creating a form that includes JoyUI (material) autocomplete and react-hook-form functionality. The array of objects I am using for my options looks like this: [ { label: "Todo", param: "TODO" }, ...

How can you load elements via AJAX?

Using AJAX, I successfully load content from a PHP page. Now, my challenge is to access and interact with the dynamically loaded elements (such as buttons, forms, or divs). The code snippet that is causing issues: jQuery(document).ready(function() { $( ...

Utilizing numerous await statements within a single asynchronous function

My async function has 3 awaits, like this: const sequenceOfCalls = async(req, res, next) =>{ await mongoQuery(); await apiCall1(); await apiCall2(); } apiCall1 uses response of mongoQuery and apiCall2 uses response of apiCall1. The issue is ...

Problem with integrating Socket io

I am currently working on integrating a Socket Io chat feature into my website, where there are two types of users: admin and end users. I want to enable communication between users that the admin selects from the chat room. However, I am encountering diff ...

How can I correctly update values from a sibling component that has been imported in Vue.js 2.0?

My Vue 2.0 project follows the single-file component approach and consists of three components: App (parent), AppHeader, and FormModal. Both AppHeader and FormModal are direct children of App and siblings of each other. The main objective is to toggle the ...

What is the best method for developing a live text display switcher that works across different pages?

Hello everyone! I am currently in the process of creating a display toggler for my website. I have two separate pages, index.html and toggler.html. In index.html, the "TEXT" is displayed, while toggler.html contains the actual toggler or switch button. Whe ...

Adjust the default color for the icon in the v-text-field type=date using Vuetify

I need to filter records between two dates, displaying data retrieved from the backend. Instead of following the traditional method outlined in Vuetify's date pickers documentation or using the CodePen example: Vuetify v-text-field Date Picker on Cod ...

Having trouble resolving errors in Visual Studio Code after failing to properly close a parent function? Learn how to fix this issue

Here we have the code starting with the construct function followed by the parents function public construct() //child { super.construct; } protected construct() //parent { } The issue arises where I am not receiving an er ...

What is the best method for displaying plain text using the br tag?

My component looks like this: class News extends Component { state = { isSimple: this.props.isSimple } render() { return ( <div> <div className="extended">extended</div> simple text </div&g ...