TestNG skipping tests - why?

I am testing a web application with testng and selenium. Tests consist mainly of opening several pages of the application and perform some actions specific to each page. Therefore, I have an abstract base class that runs an β€œopen page” test and defines an abstract method that is used as the data provider for this test. Then there are several extension classes that provide the implementation of the data provider and which have several different tests, different from the base class class. I have testuite.xml where all classes are included, which I run from my eclipse.

The problem is that when you run the test, testng runs the test in the base class for all objects, but systematically skips all other tests in the expanding classes. Does anyone know why? Any information would be much appreciated ...

To get the full details, here are some of the classes and xml that I use:

Base class:

public abstract class BaseWebAppPageTest { @Test(dataProvider="getMenuLink") public void testOpen(String menulink){ GenericPageActions.openPage(TestingContext.getSelenium(), menulink); } protected abstract String[][] getMenuLink(); } 

And some extension classes:

TestLanguages:

 public class TestLanguages extends BaseWebAppPageTest{ @Test(dependsOnMethods={"testOpen"}, dataProvider="getCreateData") public void testCreateCorrect(String code, String description, String textDirection, String flag){ Selenium selenium = TestingContext.getSelenium(); LanguagesManagementActions.create(selenium, code, description, textDirection, flag); Assert.assertTrue(selenium.isTextPresent("Successfully created language")); } @Test(dependsOnMethods={"testCreateCorrect"}, dataProvider="getCreateData") public void testFilter(String code, String description, String textDirection, String flag){ Selenium selenium = TestingContext.getSelenium(); LanguagesManagementActions.filterTable(selenium, 2, code, 30000); Assert.assertTrue(selenium.getXpathCount("xpath=//span[.='"+code+"']").intValue() == 1); } @Test(dependsOnMethods={"testCreateCorrect"}, dataProvider="getCreateData") public void testModify(String code, String description, String textDirection, String flag){ Selenium selenium = TestingContext.getSelenium(); LanguagesManagementActions.modify(TestingContext.getSelenium(), code, description, textDirection, flag); Assert.assertTrue(selenium.isTextPresent("Successfully updated language")); } @Override @DataProvider protected String[][] getMenuLink() { return(TestingContext.getDataReader().getTableArray("openviewpage", "MULTILINGUAL_LANGUAGES")); } @DataProvider protected String[][] getCreateData() { return(TestingContext.getDataReader().getTableArray("multilingualcreate", "LANGUAGES")); } } 

TestTranslations:

 public class TestTranslations extends BaseWebAppPageTest{ @Test(dependsOnMethods={"testOpen"}, dataProvider="getCreateData") public void createCorrect(String code, String targetLanguage, String translation){ Selenium selenium = TestingContext.getSelenium(); TranslationsManagementActions.create(selenium, code, targetLanguage, translation); Assert.assertTrue(selenium.isTextPresent("Successfully created translation")); } @Test(dependsOnMethods={"createCorrect"}, dataProvider="getCreateData") public void update(String code, String targetLanguage, String translation){ Selenium selenium = TestingContext.getSelenium(); TranslationsManagementActions.update(selenium, code, targetLanguage, translation); Assert.assertTrue(selenium.isTextPresent("Successfully updated translation")); } @Test(dependsOnMethods={"createCorrect"}, dataProvider="getCreateData") public void filter(String code, String targetLanguage, String translation){ Selenium selenium = TestingContext.getSelenium(); TranslationsManagementActions.filterTable(selenium, 2, code, 30000); Assert.assertTrue(selenium.isElementPresent("xpath=//span[.='"+translation+"']")); } @Override @DataProvider protected String[][] getMenuLink() { return(TestingContext.getDataReader().getTableArray("openviewpage", "MULTILINGUAL_TRANSLATIONS")); } @DataProvider protected String[][] getCreateData() { return(TestingContext.getDataReader().getTableArray("multilingualcreate", "TRANSLATIONS")); } } 

And finally, TestSuite.xml:

  <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" > <suite name="WebAppSuiteTest" parallel="none"> <parameter name="selenium.host" value="localhost" /> <parameter name="selenium.port" value="5555" /> <parameter name="selenium.browser" value="*firefox3 C:\\Documents and Settings\\dgarcia\\Local Settings\\Application Data\\Mozilla Firefox\\firefox.exe" /> <parameter name="selenium.url" value="http://localhost:8080/standard-webapp-war/home.seam" /> <parameter name="selenium.timeout" value="1000000" /> <parameter name="test.data.filepath" value="src\\test\\resources\\datatest_.xls" /> <test name="standard" preserve-order="true" > <classes> <class name="com.standard.webapp.common.TestingContext" /> <class name="com.standard.webapp.login.TestLogin"/> <class name="com.standard.webapp.TestLanguages"/> <class name="com.standard.webapp.TestTranslations"/> </class> </classes> </test> </suite> 

there are no exceptions or any reason to skip these tests. I'm not quite sure of the output you mention, so I am pasting here the contents of the generated "myWebAppTest.xml" with the test results:

 <testsuite hostname="SP2L0044" name="com.sicpa.standard.dms.webapp.selenium.common.BaseWebAppPageTest" tests="14" failures="0" timestamp="4 Mar 2011 08:45:57 GMT" time="27.141" errors="0"> <testcase name="testLoginLoadHome" time="2.188" classname="com.sicpa.standard.dms.webapp.selenium.login.TestLogin"/> <testcase name="testCreateCorrect" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes"> <skipped/> </testcase> <testcase name="testFilter" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes"> <skipped/> </testcase> <testcase name="testUpdate" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes"> <skipped/> </testcase> <testcase name="testView" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes"> <skipped/> </testcase> <testcase name="testCreateCorrect" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages"> <skipped/> </testcase> <testcase name="testFilter" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages"> <skipped/> </testcase> <testcase name="testModify" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages"> <skipped/> </testcase> <testcase name="createCorrect" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations"> <skipped/> </testcase> <testcase name="filter" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations"> <skipped/> </testcase> <testcase name="update" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations"> <skipped/> </testcase> <testcase name="testOpen" time="2.297" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages"/> <testcase name="testOpen" time="12.61" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes"/> <testcase name="testOpen" time="9.469" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations"/> </testsuite> 
+8
selenium testng
source share
9 answers

There are various reasons why TestNG skips tests, the most common of which is that the method you depend on (for example, testOpen or createCorrect) somehow failed.

I suggest installing verbose level 10 and pasting the output here or into the testng-users mailing list.

If you use the XML definition, set the verbose level as follows: <suite name="sweet_suite" verbose="10"> . The level of detail can also be set via code configuration.

 TestNG tng = new TestNG(); XmlSuite suite = new XmlSuite(); suite.setVerbose(10); // other configuration, add tests to run List<XmlSuite> suites = new ArrayList<XmlSuite>(); suites.add( suite ); tng.setXmlSuites(suites); tng.run(); 
+11
source share

This may be an error caused by the DataProvider method.

+6
source share

If you want to run tests in extension classes regardless of whether the dependent methods passed / failed, you can always add 'AlwaysRun = true' for tests in expanding classes, for example:

 @Test(dependsOnMethods={"testOpen"}, dataProvider="getCreateData", alwaysRun = true) 
+3
source share

I had this problem in the past, and I found out that when I have 2 @BeforeMethod annotations, one inside test.class and one inside basetest.class. Both, by the way, were doing something else, yet a collision occurred - preventing the execution of tests and, ultimately, skipping. Bottom line: make sure you don't have a few @Before, @ After any kind.

+2
source share

The test is also skipped if you accept parameters in the testNG method, but they do not pass the test at run time. I recently ran into this problem, so just double check.

0
source share

There may be several reasons for this, but after looking at the code, I noticed one thing: just make sure that you configured the exe browser correctly, for example, to run your tests in Chrome, you will need chromedriver.exe in your path.

  System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+ "\\src\\main\\resources\\chromedriver.exe"); 
0
source share

I had the same problem, the test ignored. After switching to a stable version of TestNG, he launched a test.

0
source share

No matter how stupid it may seem, I forgot to add @dataProviderClass to my test. That's why my tests were skipped. But testng didn't explicitly tell me where the problem was. Always check these basics before trying to find other answers here.

0
source share

Basically, it skips those tests that depend on the result of other tests or have some timeout or due to configurations.

If you installed @afterMethods or @afterClass , it would be advisable to comment on them and restart the script.

What you can do is set priority with all your test, and if all of your tests depend on a specific test, save it in @beforeMethod or @beforeClass , which ever suits you.

-one
source share

All Articles