代码之家  ›  专栏  ›  技术社区  ›  pagep YasserDaniyal

电子测试-WebdriverIO在devtools窗口和主应用程序窗口之间切换

  •  1
  • pagep YasserDaniyal  · 技术社区  · 8 年前

    我们需要测试 Electron 应用程序。 我们正在使用 Spectron 其使用ChromeDriver WebdriverIO (NodeJ的Selenium 2.0绑定)。

    问题: 我们的应用程序从打开的开发工具窗口开始,而不是显示主应用程序窗口。Webdriver连接到开发工具窗口而不是主窗口。我们无法切换到主窗口。

    示例代码:

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

    如何从开发工具切换到主窗口?

    1 回复  |  直到 8 年前
        1
  •  3
  •   pagep YasserDaniyal    8 年前

    你知道当你问一个问题然后马上找到答案时的那种感觉吗?

    解决方案是调用 windowByindex() 来自Spectron API。为此,您需要从Spectron调用API函数,而不是从 Webdriver .

    因此,我们问题的解决方案是:

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