Electron 测试 - WebdriverIO 在开发工具 window 和主应用程序 window 之间切换

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

我们需要测试 Electron 应用程序。 我们正在使用 Spectron which is using ChromeDriver and WebdriverIO(NodeJS 的 Selenium 2.0 绑定)。

问题: 我们的应用程序以打开的开发工具 window 启动,而不是显示主应用程序 window。 Webdriver 连接到开发工具 window 而不是主要的 window。我们无法切换到主 window.

示例代码:

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()');
});

关于如何从开发工具切换到主工具的任何想法 window?

你知道提出问题后立即找到答案的那种感觉吗?

解决方法是调用windowByindex() from the Spectron API. You need to call the API functions from the Spectron for this, not the functions from the Webdriver.

所以我们的问题的解决方案是:

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