使用 spectron 测试电子应用程序重新启动时丢失 webdriverio 会话

Losing webdriverio session when testing electron app restart using spectron

我正在对我的电子应用程序使用 spectron 到 运行 集成测试。除了尝试测试应用程序设置在应用程序重新启动之间是否正确保留之外,一切都运行良好。

在 运行ning 测试时,我的应用程序会为每个测试启动新的临时 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

正确的做法是什么?我也尝试过停止 Application 实例并启动一个具有类似结果的新实例。

这似乎有效

// 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

以下片段集有效,

import test from 'ava'
import util from '../util'

test(async t => {
  // This runs after each test and other test hooks, even if they failed
  let app = util.createApp()
  app = await util.waitForLoad(app, t)
  await app.restart()
  await app.client.waitUntilWindowLoaded()
  // app = await util.waitForLoad(app, t)
})

"spectron": "^3.5.0"

合作