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 en开发者_StackOverflow中文版vironment specific url (thats what the SeleniumTestBaseUrl is) but I'm having trouble passing anything else environment specific into my Selenium-IDE scripts.
Thanks!
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
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>
Try to set it as environment variable:
set myVariable=$(environmentSpecificVar) && java -jar selenium-server.jar -htmlSuite *firefox $(SeleniumTestBaseUrl) myTestSuite.html
See detailes here.
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.
精彩评论