views:

99

answers:

1

Multi-Test TestNG.xml file results in java.lang.NullPointerException

Hello Quality Team,

I need help getting TestNG to run multiple tests from one XML file. So far my efforts to do this result in a java.lang.NullPointerException OR the test(s) fake_execute="says it ran...but how can it have run if it didn't start selenium?"

One final note: All of the tests run SUCCESSFULLY when run using a stand-alone XML file

Below is my XML file

   <test name="Simple example">
       <groups>
       <run>
   <include name="groupA" />
   <include name="groupB" />
       </run>
   </groups>
   <classes>
      <class name="test.LoginPageTest"/>
      <class name="test.PurchaseItemTest"/>
     </classes>
   </test>
</suite>

When TestNG/Selenium throws the Null Pointer Error it is always failing on a selenium.open(URL), selenium.windowMaximize(), selenium.windowFocus().

I use a SeleneseTestNGHelper file that starts Selenium and handles some base-level selenium functionality.

Here is the command from the Test that my test is failing on

@Test (dataProvider = "Login_Test", groups = {"groupA"})
 public void testLoginPage(String string1, String string2) throws Exception { 
 // Super-size & Focus on Selenium Test Window
 //selenium.windowMaximize();
 //selenium.windowFocus();

        // Start your motors and get to testing
        try {  selenium.open("http://www.google.com");  }
        catch(Throwable e)
        {e.printStackTrace(); }
}

Here is the method called

 public void open(String string) {
  selenium.open(string);
  selenium.windowMaximize();
  selenium.windowFocus();
 }
+1  A: 

I don't see any code that actually initializes your selenium field, where is this happening?

Wherever it is, make sure it's initialized in a @BeforeMethod or @BeforeClass.

Also, here is some relevant documentation:

http://testng.org/doc/selenium.html

Cedric Beust
Cedric, I got it! Thank you soooo much for answering this question. I hope my question and your answer help others who stumble upon this issue. In my SeleneseTestNGHelper class my Setup and Teardown methods was set to @BeforeTest. I changed this to be @BeforeClass(alwaysRun = true). This allowed the tests to run and launch a browser, close a browser, launch new browser, close browser, etc. Thank you for your assistance
Georgina Halfkenny
Glad it helped. For what it's worth, you probably meant to use @BeforeMethod and not @BeforeTest (which means something different). But as you correctly found out, @BeforeClass is probably the best place to initialize your Selenium object.
Cedric Beust