mocha.js - 使用 spectron 访问多个渲染器

标签 mocha.js electron webdriver-io ava spectron

我正在开发一个 Electron 应用程序。主进程打开第一个渲染器 (browserWindow)。当用户单击按钮时,此渲染器会向主进程发送一条 IPC 消息。收到此消息后,主进程将打开第二个不同的渲染器。这两个渲染器同时存在。该应用程序运行良好。

然后,使用 Spectron 测试这个应用程序,如何访问两个渲染器?问题是 app.rendererProcess 总是返回第一个渲染器。

这是与 app.client 相同的问题,它始终包含第一个渲染器的 WebdriverIO browser 对象,而不是第二个渲染器。

有没有办法在测试中列出 Spectron 应用程序的所有进程?是否可以访问第二个渲染器的 browser 对象?

使用 AVA:

test.(async t => {
    // the application is open before the test
    // at this point, the first renderer is open

    // click on the button to open the second renderer
    await t.context.app.client.click('#bt_openSecondRenderer');

    // wait for the second renderer to open

    // error: this element doesn't exist
    await t.context.app.client.click('elt_of_the_scnd_renderer');
});

我正在使用 AVA,但我认为这不是问题所在。因此,如果有人知道如何使它与 Mocha 或其他任何东西一起使用,那将非常有帮助。

谢谢!

最佳答案

遵循 Tim answer 给出的理念,我们可以使用 WebDriverIO 来聚焦所需的窗口,而不是使用 BrowserWindow:

test.(async t => {
    // here, t.context.app.client handles the first window
    await t.context.app.client.windowByIndex(1).then(() => {
        // here, t.context.app.client handles the second window
    });
});

关于mocha.js - 使用 spectron 访问多个渲染器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52130941/

相关文章:

javascript - 我需要导入/需要一个 Node 模块 - 但它包含一个大于 4kb 的 wasm 文件。我的应用程序是一个 Electron 应用程序。我怎样才能使这项工作?

reactjs - 无法为 Electron 构建 .exe

node.js - webContents.send 和 ipcRenderer.on 不工作

javascript - mocha测试中的Mongodb访问

javascript - 在客户端 Mocha 单元测试期间使用外部类

javascript - npm chai 检查返回的对象是否有属性

javascript - 测试时,Sinon 不会干扰我的实习生功能。 (ExpressJS)

Node.js mocha 进程 (_mocha) 不会在 CTRL-C 时退出

automation - WebDriverIO : scrollIntoView action scrolls element outside Viewport?

javascript - Webdriverio如何执行TAB键操作