Pritum Patel
Pritum Patel

Reputation: 57

How to make setup URL variable in a Selenium RC project

I would like to find out how to make URL's variable in a Selenium project. I'm using Eclipse, Java, testNG.

We have live and test environments. Each has a different URL. The test automation suite has been coded for the test box.

What is the best way to change the URL to the live box, without having to manually change the whole project and then deploy?

Upvotes: 1

Views: 304

Answers (1)

Mairbek Khadikov
Mairbek Khadikov

Reputation: 8089

The simplest way to do this is to use system properties.

You can name the system properties as app.url and retrieve it in your test using System.getProperty(String key, String default). Default URL could be a test environment.

For production system property can be specified with the -Dapp.url=http://productionsite.com VM option.

As an alternative you can create a environment.properties file, specify app url as a property, and retrieve it in your tests. This file can be easily replaced for live environment.

Another way to do this is to use dependency injection. Frameworks like Guice can be easily integrated with TestNG.

Upvotes: 1

Related Questions