Page 1 of 1

Passing Data to Webdriver

Posted: Tue Jan 08, 2019 10:21 pm
by bjones
Is there a way to pass data to the webdriver so that it is accessible during a Siesta test? I'm trying to pass dynamically generated user credentials to Siesta when launching tests on BrowserStack.

It looks like the config-file launcher option can take a JSON object. How is this option used? Would data in this object be accessible in a siesta test? The help message for config-file says to reference the "Siesta automation" guide for details but I wasn't able to find it in the docs.

Re: Passing Data to Webdriver

Posted: Wed Jan 09, 2019 10:17 am
by nickolay
Do you need to pass the data from the project file to individual test? You can use the "config" option for that:
project.plan(
    {
        url         : '../react-google-fonts-space/tests/blackbox-app/compare.t.js',
        config      : {
            someProp    : 'someValue'
        }
    },
This option is applied directly to the top-level test instance:
StartTest(function (t) {
    if (t.someProp == 'someValue') {
    }
})

Re: Passing Data to Webdriver

Posted: Thu Jan 10, 2019 1:04 am
by bjones
This is helpful. I was not aware of the config option. Going one step further, is there a way to pass a config from outside the project file so that the config doesn't need to be hard-coded in the project file? I'm curious about how the --confile-file option for webdriver works.

If I launched siesta with the following command
./webdriver https://url/to/siesta.html --browserstack ... --config-file=config.json
Where config.json is
{
"someProp": "someValue"
}
in a test, would it be possible to access properties from the config-file like someProp like in your previous example?
StartTest(function (t) {
    if (t.someProp == 'someValue') {
    }
})

Re: Passing Data to Webdriver

Posted: Thu Jan 10, 2019 10:41 am
by nickolay
Yes, `config` option is not documented, because its not safe (can overwrite some property or method on the test), but may be we should document it (and perhaps use it as `t.config.someProp`)

It seems the --config-file option is not well-documented either. The file should be in JSON format, and it can contain default configuration options for the project and for the launcher (command line arguments). These options can be overridden in the project file (index.js).
{
    // default project-wide options
    project : {
        forceDOMVisible     : true
    },

    // default command-line arguments
    cmd     : {
        rerun-failed    : true
    }
}
What you can try, is to store the configs you need on the project. This way these configs can be specified in the config file (can also be set with `project.configure()`).

Then, in the test, you can access the project as `t.project.someProp`. This mechanism will change in the upcoming Siesta 6 release though, but we'll provide an alternative.