Reputation: 815
Before i ask my question let me say, i've read through these related questions:
Here is what i'm looking to accomplish:
ant -Dhost="ip addy" -Dbrowser="chrome"
System.getProperty("key");
and use those values set to determine what Driver is loaded. here is what i have right now:
from build.xml
<!-- language: lang-xml -->
<!-- TARGET: Run JUNIT Tests depends on remove and compile-->
<target name="junit" depends="remove,compile">
<!-- remove junit dir -->
<delete dir="${junit.output.dir}"/>
<!-- make junit dir -->
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes">
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
<sysproperty key="host" value="${arg1}"/>
<sysproperty key="browser" value="${arg2}"/>
<test name="${test.dir}.TestMyTest" todir="${junit.output.dir}"/>
//.......
java code in setup():
if (System.getProperty("browser").equals("firefox")) {
log.logInfo("Firefox driver initialized");
driver = new FirefoxDriver();
} else if (System.getProperty("browser").equals("ie") //....
When i execute ant -Dhost=ip -Dbrowser=firefox
i am getting NPE's. I assume it has to do with my build script and setting those properties. I am under the impression i set this wrong.
[junit] Testcase: testMyTest took 0.001 sec
[junit] Caused an ERROR
[junit] null
[junit] java.lang.NullPointerException
[junit] at tests.TestMyTest.setUp(Unknown Source)
[junit]
My assumption here is System.getProperty("browser")
is return null. Any assistance would be much appreciated!
Thanks!!!!!
Upvotes: 0
Views: 3808
Reputation: 815
Figured out my own coding mistake along with the help from @Chad Nouis it is now resolved.
Properties sys = new Properties();
should have been:
Properties sys = System.getProperties();
Chad Thanks again for your help!
Upvotes: 0
Reputation: 7041
There are no properties named arg1
and arg2
. Instead, refer to the user properties by name:
<!-- Verify the properties exist. -->
<fail unless="host"/>
<fail unless="browser"/>
<junit fork="yes">
<!-- ... -->
<sysproperty key="host" value="${host}"/>
<sysproperty key="browser" value="${browser}"/>
<!-- ... -->
</junit>
Upvotes: 1