Just getting started with TestNG, and also with Selenium. When I
enable a groups block in my suite file, my test dies in my code on the
first line of the (only) test. When I disable the groups block, the
test is run and completes successfully. I'm using TestNG 5.10 (also
tried 5.8 and whatever comes bundled with IntelliJ IDEA 8.1.3) with
latest Java 5. I first noticed the problem in the IDEA environment,
but I've since reproduced it outside of IDEA.
Thanks for letting me know what I'm doing wrong.
-Murph
I provide the test suite file, the stack output, and the test source
code below.
TEST SUITE FILE
<!DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd">
<suite name="Custom suite" parallel="none" verbose="10">
<parameter name="selenium.url" value="
http://localhost:8080/">
</parameter>
<parameter name="selenium.browser" value="*safari">
</parameter>
<parameter name="verbose" value="10">
</parameter>
<test verbose="10" name="cnv" annotations="JDK">
<!-- comment out the <groups> block, and this suite/test works -->
<groups>
<run>
<include name="selenium"/>
</run>
</groups>
<classes>
<class name="test.TestCase1"/>
</classes>
</test>
</suite>
STACK OUTPUT
java.lang.NullPointerException
at test.TestCase1.testTestCase1(TestCase1.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodHelper.invokeMethod
(MethodHelper.java:607)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:
669)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:
956)
at org.testng.internal.TestMethodWorker.invokeTestMethods
(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run
(TestMethodWorker.java:110)
at org.testng.TestRunner.runWorkers(TestRunner.java:759)
at org.testng.TestRunner.privateRun(TestRunner.java:592)
at org.testng.TestRunner.run(TestRunner.java:486)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:
327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:867)
at org.testng.TestNG.runSuitesLocally(TestNG.java:832)
at org.testng.TestNG.run(TestNG.java:748)
at org.testng.TestNG.privateMain(TestNG.java:904)
at org.testng.TestNG.main(TestNG.java:877)
TEST SOURCE CODE
package test;
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;
public class TestCase1 extends SeleneseTestNgHelper {
@Test(groups = { "selenium" })
public void testTestCase1() throws Exception {
selenium.open("/Search");
selenium.waitForPageToLoad("30000");
selenium.type("ui=searchPage::position()",
"chr1:742429-758311");
selenium.click("ui=searchPage::submitButton()");
selenium.waitForPageToLoad("30000");
//selenium.captureEntirePageScreenshot("/tmp/snap.png", "");
// See if the Sample column is present
String maybeSample = selenium.getText("xpath=//table
[@id='resultlist']/thead/tr[2]/th[3]/span");
assertTrue(selenium.isTextPresent("regexp:1 to [1-9][0-9]* of
[1-9][0-9]* non-unique CNVs (from [0-9]+ samples* )*from the
Normals_CHOP source located at chr1:742429-758311"));
if (maybeSample.equals("Sample")) {
//id('resultlist')/thead/tr[2]/th[11]/span
assertTrue(Pattern.compile("[1-9][0-9]*").matcher
(selenium.getTable("resultlist.2.11")).find());
} else {
assertTrue(Pattern.compile("[1-9][0-9]*").matcher
(selenium.getTable("resultlist.2.10")).find());
}
selenium.click("ui=allPages::searchTab()");
selenium.waitForPageToLoad("30000");
selenium.type("ui=searchPage::position()",
"chr1:5547116-5548075");
selenium.click("ui=searchPage::submitButton()");
selenium.waitForPageToLoad("30000");
maybeSample = selenium.getText("xpath=//table
[@id='resultlist']/thead/tr[2]/th[3]/span");
if (maybeSample.equals("Sample")) {
assertEquals(selenium.getTable("resultlist.2.11"),
"<D0>");
} else {
assertEquals(selenium.getTable("resultlist.2.10"),
"<D0>");
}
}
}
VERBOSE TEST CONSOLE OUTPUT
*** CONSOLE LOG ***
[Parser] Running:
/Users/schnebtron/Library/Caches/IntelliJIDEA8x/temp-testng-
customsuite.xml
[TestRunner] Running the tests in 'cnv' with parallel mode:none
[RunInfo] Adding method selector:
org.testng.internal.XmlMethodSelector@bc92535 priority: 10
[TestClass] Creating TestClass for [ClassImpl test.TestCase1]
[TestClass] Adding method test.TestCase1.testTestCase1() on TestClass
class test.TestCase1
[XmlMethodSelector] Including group : selenium
[XmlMethodSelector] Excluding method
com.thoughtworks.selenium.attachScreenshotListener()
[XmlMethodSelector] Excluding method com.thoughtworks.selenium.setUp()
[XmlMethodSelector] Excluding method
com.thoughtworks.selenium.getSelenium()
[XmlMethodSelector] Excluding method
com.thoughtworks.selenium.setTestContext()
[XmlMethodSelector] Excluding method
com.thoughtworks.selenium.checkForVerificationErrors()
[XmlMethodSelector] Including method test.testTestCase1()
[SuiteRunner] Created 1 TestRunners
[TestRunner] Running test cnv on 1 classes, included groups:
[selenium ] excluded groups:[]
[TestClass]
======
TESTCLASS: test.TestCase1
[TestClass] Test : test.TestCase1.testTestCase1()
[TestClass] AfterMethod :
com.thoughtworks.selenium.SeleneseTestNgHelper.selectDefaultWindow()
[TestClass]
======
[TestRunner] Found 1 applicable methods
[TestRunner] WILL BE RUN IN RANDOM ORDER:
[TestRunner] test.TestCase1.testTestCase1()
[TestRunner] on instances
[TestRunner] test.TestCase1@5557c2bd
[TestRunner] ===
[Invoker 1875244867] Keeping method
com.thoughtworks.selenium.SeleneseTestNgHelper.selectDefaultWindow()
for class [TestClass class test.TestCase1]
[Invoker 1875244867] Invoking test.TestCase1.testTestCase1
[Invoker 1875244867] Keeping method
com.thoughtworks.selenium.SeleneseTestNgHelper.selectDefaultWindow()
for class [TestClass class test.TestCase1]
[Invoker 1875244867] Invoking @AfterMethod
com.thoughtworks.selenium.SeleneseTestNgHelper.selectDefaultWindow()
[Invoker 1875244867] Invoking @AfterTest
com.thoughtworks.selenium.SeleneseTestNgHelper.tearDown()
*********** INVOKED METHODS
test.TestCase1.testTestCase1() 1431814845
***********
Creating /Users/schnebtron/tmp/test-output/Custom suite/cnv.html
Creating /Users/schnebtron/tmp/test-output/Custom suite/cnv.xml
FAILED: testTestCase1
java.lang.NullPointerException
at test.TestCase1.testTestCase1(TestCase1.java:12)
... Removed 22 stack frames
===============================================
cnv
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Custom suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================