【问题标题】:Losing webdriverio session when testing electron app restart using spectron使用 Spectron 测试电子应用重新启动时丢失 webdriverio 会话
【发布时间】:2017-07-24 16:12:39
【问题描述】:

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

在运行测试时,我的应用会启动每个测试的新临时 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 实例并启动一个具有相似结果的新实例。

【问题讨论】:

  • 你在哪里持久化用户数据?在浏览器存储中,还是在本地文件系统中?
  • userData 是保存整个 Chromium 用户应用存储的电子路径。我正在使用电子app.setPath('userData', x) API 来设置它。一切都存储在那里 indexedDb、GPU 缓存等。我将其设置为 path.join(os.tmpdir(), 'spectron', randomString)
  • 嗯.. 我没有用它来持久化任何东西。我使用了电子配置,但也许您可以使用 app.setLoginItemSettings([options]) 中的 set/get 方法在 beforeEach 中的每个测试中提取您的设置?或者这个issue 可能有一些相关性。
  • 持久性工作正常。失败的是 Spectron 测试代码。
  • 我们也遇到了 app.restart() 的问题。我们有类似的情况。我们不使用临时文件夹,而是使用随机名称的普通文件夹。每次测试后,文件夹都会被删除(也就是 afterAll)。同样在所有测试之前,所有文件夹都被删除以确保。对于应用程序重新启动,我们使用的是 simlpe app.stop 、 app.start , app.start 函数的编写方式可以使应用程序正确启动,因此无论它之前是否运行过或者这是第一次启动都无关紧要日。有了这个,我们就没有任何问题了。

标签: electron webdriver-io spectron


【解决方案1】:

这似乎有效

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

【讨论】:

    【解决方案2】:

    以下片段有效,

    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"合作

    【讨论】:

      猜你喜欢
      • 2017-10-22
      • 2019-04-04
      • 2023-03-22
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      相关资源
      最近更新 更多