1

In my Selenium-TestNG-Maven automation framework, I am have properties file for storing 'application-url'. The Jenkins job is configured for this. I have to run this test suite on QA/Stage/Production server based on need. But not sure how can I dynamically provide or override the 'application-url' property used in the code. (Environment Injector plugin? How?)

As per code, Selenium WebDriver instance in created, then java code reads the properties file and same URL is used by Selenium instance to open a webpage.

Vijay
  • 23
  • 1
  • 6

2 Answers2

1

I dynamically provide URLs by using the choice parameter for my Jenkins job.

First select this project is parameter as pictured below:

Jenkins Configuration Parameter

Then select the Add Parameter > Choice Parameter as pictured below:

Choice Parameter

Then save.

Now when you are building you will be able to select the url to use for that particular build, like this:

Choice selection

And when you need to reference the url, you can pass it through to maven by using the $URL in the Maven Goals.

ADDED: Here is an example of how I am using the choice parameter in the Maven goals

Maven goals

I am passing the ${browserName} parameter that is defined using the Choice Parameter through maven which will be referenced using the system property "browser". So when I want to get the value in my code, I just use

System.getProperty("browser");

And I am able to access that passed parameter.

  • Thanks Jasmine for your reply. Could you please explain a bit more about how to use this choice parameter to pass to Maven Goals? Also, currently this URL is defined in one of the java properties file and read in code. I believe that also need some changes since Jenkins job is now passing the URL. – Vijay Feb 02 '17 at 19:55
0

You can configure your jenkins to pull the latest code from any of the repository (Github, SVN) and in the Execute Shell build step, you can write a shell script to achieve the same.

Paras
  • 3,197
  • 2
  • 20
  • 30