简体   繁体   English

将变量传递给Selenium-IDE脚本

[英]Pass variable to Selenium-IDE script

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? MSBuild脚本是否可以将参数传递给Selenium测试运行器,然后可以由Selenium-IDE测试脚本使用? 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... ...然后在我的Selenium-IDE脚本中使用它,如...

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. 传递一个特定于环境的URL(这就是SeleniumTestBaseUrl是什么)没有问题,但我在将任何其他环境特定的内容传递到我的Selenium-IDE脚本时遇到了麻烦。

Thanks! 谢谢!

The key is the Selenium Parameter -userExtensions 关键是Selenium参数-userExtensions

First, let the script create a temporary js-file (in this case getting a Jenkins parameter): 首先,让脚本创建一个临时的js文件(在这种情况下获取一个Jenkins参数):

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

Then passing the user variable to Selenium like in this example: 然后将用户变量传递给Selenium,如下例所示:

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: 在我的testfile中,然后可以通过storeEval获取变量:

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

The following command will allow you to retrieve some environment variables from within Selenium IDE. 以下命令将允许您从Selenium IDE中检索一些环境变量。 This also works in Selenium RC if you are using *firefox as your browser. 如果您使用* firefox作为浏览器,这也适用于Selenium RC。

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 参考: 从Firefox扩展中查找当前登录的用户

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命令,因此应尝试使用-D标志在命令行设置特定属性:

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: 要在MSBuild中调用它,您只需设置一个属性并将上述命令包装在Exec任务中:

<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. 我不太熟悉Selenium IDE脚本,所以我不知道你是否能够以这种方式访问​​属性,但这是我从MSBuild脚本调用ant任务时所做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM