4

Is it possible for an MSBuild script to pass an argument to the Selenium test runner that can then be used by a Selenium-IDE test script? I was hoping I could do something like...

java -jar selenium-server.jar -htmlSuite *firefox $(SeleniumTestBaseUrl) myTestSuite.html -myVariable $(environmentSpecificVar)

...and then use it from within my Selenium-IDE script like...

waitForTextPresent    The passed in variable is ${myVariable}

Theres no problem passing in an environment specific url (thats what the SeleniumTestBaseUrl is) but I'm having trouble passing anything else environment specific into my Selenium-IDE scripts.

Thanks!

1
  • I've adopted the exceptionally nasty policiy of XmlPoke'ing the appropriate variable into the script, as nothing else seems to work. Commented Apr 26, 2011 at 11:00

4 Answers 4

2

The following command will allow you to retrieve some environment variables from within Selenium IDE. This also works in Selenium RC if you are using *firefox as your browser.

Command: storeEval
Target: Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USERNAME');
Value: username

Reference: Finding the currently logged in user from a Firefox extension

Sign up to request clarification or add additional context in comments.

Comments

2

The key is the Selenium Parameter -userExtensions

First, let the script create a temporary js-file (in this case getting a Jenkins parameter):

echo "var myvariable='$myJenkinsVariable'" > user-extensions.js

Then passing the user variable to Selenium like in this example:

java -jar /var/lib/selenium/selenium.jar -htmlSuite *firefox http://flowcom.se "build/suite.html" "build/report/report.html" -userExtensions "user-extensions.js"

In my testfile it is then possible to get the variable via storeEval:

<tr>
    <td>storeEval</td>
    <td>myvariable</td>
    <td>myvariable</td>
</tr>
<tr>
    <td>echo</td>
    <td>${myvariable}</td>
    <td></td>
</tr>

Comments

1

Try to set it as environment variable:

 set myVariable=$(environmentSpecificVar) && java -jar selenium-server.jar -htmlSuite *firefox $(SeleniumTestBaseUrl) myTestSuite.html 

See detailes here.

1 Comment

Setting the environment variable seems to work but I am unable to use it in my script - I've not found a selenium command to capture an environment variable.
1

Since you are running a java command, you should try setting a specific property at the command line using the -D flag:

java -jar selenium-server.jar ... -DpropertyFoo=valueBar

To call that in MSBuild, you would simply set a property and wrap the above command in an Exec task:

<Exec command="java -jar selenium-server.jar ... -DpropertyFoo=$(propertyFoo)" />

I'm not too familiar with Selenium IDE scripts so I don't know if you'll be able to access properties that way, but this is what I do when invoking ant tasks from my MSBuild scripts.

1 Comment

Thanks, setting the environment var works but doesn't seem to be accesible via Selenium.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.