Passing Data to Webdriver

Get help with testing, discuss unit testing strategies etc.
Post Reply
User avatar
bjones
Premium Member
Premium Member
Posts: 3
Joined: Thu Nov 01, 2018 8:22 pm

Passing Data to Webdriver

Post by bjones » Tue Jan 08, 2019 10:21 pm

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.

User avatar
nickolay
Core Developer
Core Developer
Posts: 3284
Joined: Mon May 16, 2011 10:48 am

Re: Passing Data to Webdriver

Post by nickolay » Wed Jan 09, 2019 10:17 am

Do you need to pass the data from the project file to individual test? You can use the "config" option for that:

Code: Select all

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:

Code: Select all

StartTest(function (t) {
    if (t.someProp == 'someValue') {
    }
})
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
bjones
Premium Member
Premium Member
Posts: 3
Joined: Thu Nov 01, 2018 8:22 pm

Re: Passing Data to Webdriver

Post by bjones » Thu Jan 10, 2019 1:04 am

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

Code: Select all

./webdriver https://url/to/siesta.html --browserstack ... --config-file=config.json
Where config.json is

Code: Select all

{
"someProp": "someValue"
}
in a test, would it be possible to access properties from the config-file like someProp like in your previous example?

Code: Select all

StartTest(function (t) {
    if (t.someProp == 'someValue') {
    }
})

User avatar
nickolay
Core Developer
Core Developer
Posts: 3284
Joined: Mon May 16, 2011 10:48 am

Re: Passing Data to Webdriver

Post by nickolay » Thu Jan 10, 2019 10:41 am

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

Code: Select all

{
    // 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.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

Post Reply