【问题标题】:Electron testing - WebdriverIO switch between the devtools window and main app windowElectron 测试 - WebdriverIO 在 devtools 窗口和主应用程序窗口之间切换
【发布时间】:2017-01-06 11:57:59
【问题描述】:

我们需要测试Electron App。 我们使用的是 Spectron,它使用的是 ChromeDriver 和 WebdriverIO(用于 NodeJS 的 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()');
});

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

【问题讨论】:

    标签: javascript node.js selenium electron webdriver-io


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我对api与Spectron和WebdriverIO的区别感到很困惑,它们之间的共同点是什么?我什么时候应该使用哪个?
    • 如果你想控制特定于 Electron 的东西,你可以调用 Spectron API github.com/electron/spectron#application-api 但如果它是常规功能,就像应用程序在浏览器中运行一样,你可以调用 WebdriverIO。在 99% 的情况下,您将调用 Webdriver API。
    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 2019-12-02
    • 2021-03-31
    • 2018-01-31
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多