Losing webdriverio session when testing electron app restart using spectron
Asked Answered
A

2

7

I'm using spectron to run integration tests against my electron app. Everything is working fine apart from attempting to test that app settings are persisted properly between app restarts.

While running tests, my app starts up with new temporary userData directory for every test which ensures that the tests are isolated. This means the the persistence testing needs to ideally occur in a single test and to achieve this I have to restart the app in the middle of the test. There's an app.restart method so this has got to be supported right?

I'm using the following spectron test code:

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

However I'm getting the following error:

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

What's the correct way to do this? I've also tried stopping the Application instance and starting a new one with similar results.

Allege answered 4/3, 2017 at 15:27 Comment(5)
Where are you persisting userData? In the browserStorage, or in the local file system?Carbonization
userData is the electron path where the whole Chromium user app storage is saved. I'm using the electron app.setPath('userData', x) API to set this. Everything is stored there indexedDb, GPU cache, etc. I'm setting it to path.join(os.tmpdir(), 'spectron', randomString).Allege
Hm.. I haven't used that to persist anything. I have used electron-config, but perhaps you can use the set/get methods from app.setLoginItemSettings([options])to draw out your settings in each test in a beforeEach? Or maybe this issue has some relevance.Carbonization
The persistence is working fine. It's the spectron test code which is failing.Allege
We had problems with app.restart() too. We have similar scenario. We do not use temp folder but rather normal folder with random name. After each test the folder is removed (aka afterAll). Also before all tests all the folders are delete just to be sure. And for app restart we are using simlpe app.stop , app.start , the app.start functions are written in a way that the application starts correctly so it doesn't matter if it was running before or this is the first start of the day. With this we don't have any problems anymore.Marya
A
0

This appears to work

// 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
Allege answered 9/5, 2017 at 13:51 Comment(0)
H
0

Following snippsets works,

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)
})

works with, "spectron": "^3.5.0"

Hexapartite answered 7/8, 2017 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.