webdriverio-boneyard / wdio-cucumber-framework

A WebdriverIO v4 plugin. Adapter for Cucumber testing framework.
MIT License
77 stars 61 forks source link

Generating new session doesn't run methods that generate capabilities during initialization #67

Closed thompsd3 closed 7 years ago

thompsd3 commented 7 years ago

Wanted to test out webdriverio for a project I'm working on because I've found it very easy to use myself as well as potentially easier to maintain on a cross functional team of developers. What I have is an application that is a wrapper around a browser and some tests I'm trying to convert to use webdriverio. I've gotten most of the POC work done and last thing is to work out is concurrency.

In the application, I have a cache that dictates which instance to use. By default the same instance is reused, however, within the capabilities, we run a method to generate a unique cache id in the capabilities similar to below.

capabilities: [{
        // maxInstances can get overwritten per capability. So if you have an in-house Selenium
        // grid with only 5 firefox instances available you can make sure that not more than
        // 5 instances get started at a time.
        //
        browserName: 'chrome',
        chromeOptions : {
            args: [ "cache_id=" + (global.cache = desktopCache.cacheId()), "log-file=/project/logs/${global.cache}-core.log" ]
        }
    }]

The above code only runs desktopCache.generateCacheId() for the first test and the subsequent sessions all use the same id that was generated the first time rather than using a unique id for each. Should I not expect my method to be ran each time a session is generated? If not, is it possible to do this? Reason is because we need a unique cache id set for each test (similar to how we have maxInstances which allow chrome to generate unique sessions.

christian-bromann commented 7 years ago

Should I not expect my method to be ran each time a session is generated?

No, the config is read once you start the test.

If not, is it possible to do this?

Just set a random number for each capability. Or use the beforeSession hook to set this unique cache id for each test individually.

Join our Gitter for these kind of questions. This is not necessary an issue.

thompsd3 commented 7 years ago

@christian-bromann thanks for the suggestion to "use the beforeSession hook to set this unique cache id for each test individually". That is what worked for us. And I will be sure to appropriately direct my questions in the future.