electron - 使用 Spectron 测试 Electron 应用程序重新启动时丢失 webdriverio session

标签 electron webdriver-io spectron

我正在使用spectron针对我的 Electron 应用程序运行集成测试。除了尝试测试应用程序设置在应用程序重新启动之间是否正确保留之外,一切都工作正常。

运行测试时,我的应用程序会为每个测试启动新的临时 userData 目录,以确保测试是隔离的。这意味着持久性测试理想情况下需要在单个测试中进行,为了实现这一点,我必须在测试过程中重新启动应用程序。有一个 app.restart 方法,所以必须支持这个方法,对吧?

我正在使用以下 Spectron 测试代码:

// save some settings here

await app.restart();
await app.client.waitUntilWindowLoaded()

// do some more checking to ensure the app is fully loaded
// check the settings here

但是我收到以下错误:

Error: waitUntilWindowLoaded Promise was rejected with the following reason: 
Error: A session id is required for this command but wasn't found in the response payload

正确的做法是什么?我还尝试停止应用程序实例并启动一个新的应用程序实例,结果类似。

最佳答案

这似乎有效

// save some settings here

await app.stop();

app = new Application({ ... });
await app.start();
await app.client.waitUntilWindowLoaded();

// do some more checking to ensure the app is fully loaded
// check the settings here

关于electron - 使用 Spectron 测试 Electron 应用程序重新启动时丢失 webdriverio session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42597716/

相关文章:

electron - 如何从 Electron 中的main.js更改index.html中的值?

event-handling - 在Vue组件中监听Electron的ipcRenderer消息

intellij-idea - IntelliJ IDEA 2020 支持 webdriverio 选择器

linux - 无法在 Ubuntu 命令行中启动 WebdriverIO

json - Spectron 测试产生 JScript 语法错误

javascript - Electron BrowserView 未捕获鼠标事件

javascript - 使用 ' '或 “”或 `${ }`的JS函数不同输出的参数

javascript - 如何将webdriverio驱动传递到函数中进行模块化设计?

electron - 如何使用Spectron与 Electron 应用程序的控件进行交互

javascript - Spectron中的单击功能不会单击