how do i pass program arguments in java for my Fitnesse Fixture?

自闭症网瘾萝莉.ら 提交于 2019-12-08 05:42:28

问题


I have a fixture that needs some System arguments to be passed into it.How can i do the same. ie java MyClass -Darg1=x -Darg2=y

how do i pass the -Darg values into my test.

@Dan. My Bad that I mentioned command line arguments.What I really intend to do is pass System properties as you pointed out.I have some settings like Region(NA/EMEA etc),Environment(SIT/UAT) etc based on which various urls etc differ.I have to compose tests in Fitnesse where I pass the values for the test screen from my decision table.But I want to be in a position to dictate that these tests should be run on so and so region/env combination.AT present I have a junit Test that triggers Selenium playback and I have control over its invocation from IDE/Maven by passing -Dregion etc.With Fitnesse I want to know how to pass these System arguments so that my Fixture when it gets invoked has access to these properties and it triggers playback of Selenium accordingly.


回答1:


To pass variables into FitNesse, you can set an environment variable. For example, start FitNesse from the command line like this:

set SUT=www.google.de
java -jar fitnesse.jar -p 8080

You can use environment variables in FitNesse like other variables - '${SUT}' in a FitNesse test table will be replaced with www.google.de in the above example.

Then to get the value of SUT into the test fixture, you can add a static class in the test fixture like this:

public class Environment {
    public static string SUT;
}

And somewhere in your FitNesse Setup code set the Environment SUT variable:

!|script|Environment|
|SUT|${SUT}|

Environment.SUT is then available throughout your Fixture code.


Update:

Also see Dan's comment on how use Java System variables by starting fitNesse with the -D parameter.



来源:https://stackoverflow.com/questions/9021071/how-do-i-pass-program-arguments-in-java-for-my-fitnesse-fixture

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!