Electron testing - WebdriverIO switch between the devtools window and main app window

2k views Asked by At

We need to test Electron App. We are using Spectron which is using ChromeDriver and WebdriverIO (Selenium 2.0 bindings for NodeJS).

Problem: Our application starts with open dev tools window than main application window is shown. Webdriver connects to dev tools window instead of the main window. We are unable to switch to main window.

Example code:

var app = new Application({
    path: cfg.pathToElectron,
    args: [cfg.pathToSA]
});

app.start().then(function(){
    app.client // <- this is dev tools window instead of main window

    // this closes the dev tools which is ok but we need to switch to main window
    app.client.close();

    // things like this doesn't help 
    app.client.execute('xxx.getCurrentWindow().closeDevTools()');
});

Any ideas how to switch from dev tools to main window?

1

There are 1 answers

2
pagep On BEST ANSWER

You know that feeling when you ask a question and than immediately find the answer?

The solution is to call windowByindex() from the Spectron API. You need to call the API functions from the Spectron for this, not the functions from the Webdriver.

So solution to our problem is:

app.start().then(function(){
    app.client.windowByIndex(1);    
});