Search code examples
electronwebdriver-iospectron

Losing webdriverio session when testing electron app restart using spectron


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.


Solution

  • 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