1

As per this https://github.com/webdriverio/webdriverio/issues/1500, webdriverio test runner will load the config file for each spec file, which prevents us from persisting/sharing data/status across these specs (and sessions).

I'm wondering how it could be worked around. I guess it should be do-able, because the test-runner itself knows which spec it's going to run every time it loads the config file although the config file actually contains all the spec files as below

 specs: [
        'test/spec/**'
    ],

Just don't know how.

The bottom line is that keep the data in a temp file on the disk. However, this is quite ugly.

Wenzhong Hu
  • 174
  • 1
  • 10
  • 1
    Tests should be `atomic` as much as possible. I also don't think you can control the test runner sequence, which might cause your dependency in tests to break your tests. With that being said, you can share data by having ENV variables like password or usernames. – Royg Dec 01 '19 at 08:13
  • No, I don't want to change the test runner sequence. Consider this, almost all app test scenarios require a user registered already while the registration could be time-consuming. So we want to reuse the user across feature files/sessions. However, because the test runner reloads the config file (and everything else thereafter), we could not persist/share the user information. This seems to be a JavaScript specific issue. For example, Java doesn't have this problem because usually a whole test run share the same JVM, so we could definitely persist the data within the test run. – Wenzhong Hu Dec 02 '19 at 09:24

1 Answers1

3

Unfortunately reason for that is every parallel thread in WebdriverIO is running in separate nodejs process, so they just don't have shared memory. Ways you can share data between workers:

  • HTTP
  • Sockets
  • File

I did something similar for ProtractorJS (some time ago): https://gist.github.com/Xotabu4/011d728752507f6a2d4775fd8659cfc4

And i also saw one service implemented exactly for webdriverio: https://webdriver.io/docs/shared-store-service.html

It also uses webserver under the hood.

Xotabu4
  • 3,063
  • 17
  • 29
  • 1
    Thanks. I think the best solution should be using webdriverio Shared Store Service https://webdriver.io/docs/shared-store-service.html. However, this is for v5 only while we are using v4. I ended up using local file to persist the status and it works fine. – Wenzhong Hu Dec 06 '19 at 05:44