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>