I am trying to run multiple tests I've written in Java using testNG unit testing and selenium UI testing frameworks. I have a configuration file setup so to make it convenient to run multiple tests.
When I add in @BeforeTest and @AfterTest annotations to separate methods I create due to certain lines of common code to multiple tests, my tests all fail because the @BeforeTest failed to initialize. I get a java.lang.NullPointerException at almost all the locations in my code.
When I put in this setup and cleanup code into my multiple @Test methods, it works just fine.
Here is how I'm doing it
I have 2 java classes:
CaliforniaBenefitsTest.java
TestConfig.java
Both belonging to the same package:
com.company.qa.states.benefits
Here is my XML file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="1" verbose="4" name="Config">
<parameter name="configFile" value="config.properties" />
<parameter name="testConfigFile" value="testConfig.properties" />
<parameter name="proxy" value="notrequired" />
<test name = "Tests1">
<groups>
<run>
<include name="prerequisite" />
<include name="runnable" />
</run>
</groups>
<classes>
<class name = "com.company.qa.states.benefits.CaliforniaBenefitsTest"/>
</classes>
</test>
<test name="Tests2">
<groups>
<run>
<include name="prerequisite" />
<include name="runnable" />
</run>
</groups>
<classes>
<class name = "com.company.qa.states.benefits.TestConfig"/>
</classes>
</test>
</suite>
What am I doing wrong? How can I fix my XML file or @BeforeTest and @AfterTest methods. Please tell me how to fix this problem, driving me insane. If I didn't include certain information please ask me, and I will provide this information.