webdriverjs properties

WebDriverJS Properties File

Reading Time 2 minute

The concept of Properties is a great way to control test configuration. WebDriverJs Properties can help to scale automated tests.

When writing scripts using WebDriverJS, it is important to consider the scale of the test. Being able to change the parameters of multiple tests with a single change can helps scale tests.

WebDriverJS Properties without Properties

Let’s take a simple script. See below:

script.js

var webdriver = require('selenium-webdriver’);
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
driver.get('http://www.thetestroom.com');

The script above is very simple. It opens a Chrome browser and navigates to www.TheTestRoom.com. Assume for a moment that the URL for TheTestRoom changes to something else. If the URL changed, we would have to update the script. Updating a single script is not a problem, in fact it is very straight forward. However, what if we have 1000’s of scripts, all which used the URL. With our current approach we would have to update each script individually.

Introducing Properties

Now let’s take a look at the same file, this time however the URL is coming from a properties file.

script.js

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
var prop = require('./proptest');
driver.get(prop.TTL);

properties.js

module.exports = {
    TTL: 'http://www.thetestroom.com'
};

The same URL is now being set in a properties file. The properties file is exported via module.exports. This allows us to use the concept of creating variables in one file and consuming it in many other places.

If the URL changes, we only need to update the properties file ie. in one place. With this approach, we do not need to care about how many files are using the URL. This is because a single change would effect all files automatically.

Conclusion

To wrap this up, what advantage does this actually bring?

Well:
* A single change will effect all files
* Test files becomes easier to manage
* There should not be an instance of ‘accidentally forgetting to update a URL’
* Increase variable names readability

You can apply the same mechanics to help configure what environments to run against, when to run, test priority changes, test suites etc.

Mo

I am a passionate tester, father, husband and gamer. I love to write blogs about Software Testing and generally contribute back to the Software Testing world.

More Posts - Twitter - Facebook

Published by

Mo

I am a passionate tester, father, husband and gamer. I love to write blogs about Software Testing and generally contribute back to the Software Testing world.

Leave a Reply