I am testing a web app with testng and selenium. The tests mainly consist in opening several pages of the app, and do some activities specific for each page. So I have an abstract base class which performs the "open page" test, and that defines an abstract method which is used as data provider for that test. Then there are several extending classes which provide implementation for the data provider, and which have several different tests apart from that of the base class. I have a testsuite.xml where all the classes are included, which is what I run from my eclipse.
The problem is that when I launch the test execution, testng runs the test in the base class for all objects, but skips systematically every other tests in the extending classes. Does anyone know why? Any information will be very appreciated...
To complete information, here are some of the classes and the xml 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 extending 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, the 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 is no exception nor any reason on the output to skip those tests. I am not really sure about the output you mention, so I will paste here the content of the generated "myWebAppTest.xml" with the results of the tests:
<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>
TestNG will print the first line of code and skip the rest as soon as it reaches to SkipExecution code. It is conditional skip. The code checks whether the DataAvailable parameter is True or False. If it is False, it throws the SkipException and skips the test.
Based on requirement, a user can skip a complete test without executing it at all or skip a test based on a specific condition. If the condition meets at the time of execution, it skips the remaining code in the test.
Ignore means do not run it at all, and skip with the combinations of Listeners can be use for listening dependent methods and/or test. So let assume you have dependency between two tests and /or methods, test 2 can be performed only if test 1 pass. Skip will hapen for test 2 if test 1 fails.
Use the parameter enabled=false at @Test. By default, this parameter is set as True. Use throw new SkipException(String message) to skip a test.
It could be error thrown in DataProvider method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With