Wednesday, July 13, 2016

Selenium Webdriver and SELENIUM_PLATFORM environment variable



I'm using the javascript flavor of selenium-webdriver and try to set capabilities like below:
    driver = new webdriver.Builder().
      withCapabilities({
        'browserName': process.env.SELENIUM_BROWSER,
        'platform': process.env.SELENIUM_PLATFORM,
        'version': 'latest'
      }).
      build();
And I run my script as:
SELENIUM_BROWSER=chrome SELENIUM_PLATFORM='OSX 10.11' npm test

Expected Behavior -

This is expected to to run my script on Mac/chrome.

Actual Behavior -

It runs it on Linux (which is the default platform when 'platform' capability is not set.)

Temporary Workaround

I worked around this issue by using another environment variable and using that in my test as below:
      driver = new webdriver.Builder().
      withCapabilities({
        'browserName': process.env.MYBROWSER,
        'platform': process.env.MYPLATFORM,
        'version': 'latest'
      }).
      build();
and while running my test:
   export MYPLATFORM="$SELENIUM_PLATFORM"
    export MYBROWSER="$SELENIUM_BROWSER"
    unset SELENIUM_PLATFORM
    unset SELENIUM_BROWSER
    npm test
Looks like the environment variables are not being handled properly by the webdriver.
This issue is being tracked here .