You can create a new test case or suit by extending TestNGTestCase
. More specific flavor for web services is WSTestCase
and for web and mobile is WebDriverTestCase
. Now you can create test same as in TestNG. If you are new to TestNG, here is the documentation. You can utilize all features from the TestNG “as is” like groping, test-dependency, priority and annotations. QAF will enable additional features on top of it.
Meta-data
QAF allows you to add meta-data for test case.
- You can use
@MetaData
annotation or use your custom annotation to provide meta-data. - All annotations parameters will be collected as meta data. It includes annotations on test method and class annotations.
- Meta data provided at class level will be inherited by test meta-data.
meta-data can be used for test case selection by providing meta-data filter and in listeners. To enforce certain meta-data you can specify meta-data rules.
Data-driven tests
You can create and use TestNG data provider. QAF has test data filtering and intercepting capabilities along with inbuilt external data providers support.
BDD with Java
You also can employ BDD using runtime scenario. Using runtime scenario is preferred even if you are not following BDD because it will enable additional dry run mode support.
Examples
@MetaData("{'story':'testing for fun', 'module':'m1', 'storyId':'PRJ-111'}")
public class SampleTestSuite extends TestNGTestCase {
@MetaData("{'status':'InProgress', 'testCaseId':'TEST-1', 'issueId':'PRJ-112'}")
@Test
public void test1() {
//your code goes here
}
@MetaData("{'status':'InProgress', 'testCaseId':'TEST-2', 'issueId':'PRJ-113'}")
@Test
public void test2() {
//your code goes here
}
}
On extending WebDriverTestCase following object will be available to use in your test.
getTestBase()
- When extending
WebDriverTestCase
Get thread safe WebDriverTestBase Instance that provides webdriver object.
getDriver()
Provides a thread safe webdriver object same as getTestBase().getDriver().
context
Instance of ITestContext, test context which contains all the information for a given test run.
props
Instance of PropertyUtil, can be used to read property value from any of the properties file.
Below are example for web/mobile test case:
@MetaData("{'story':'testing for fun'}")
public class SampleTestSuite extends WebDriverTestCase {
@MetaData("{'author':'me'}")
@Test
public void test1() {
getDriver().get("/");
// QAFWebElement fname = getDriver().findElement("fname locator");
QAFWebElement fname = new QAFExtendedWebElement("fname locator");
fname.verifyText(StringMatcher.exactIgnoringCase("expected text"));
}
}
Using Test Page in Test case
@MetaData("{'story':'testing for fun'}")
public class SampleTestSuite extends WebDriverTestCase {
@MetaData("{'author':'me'}")
@Test
public void test1() {
MyTestPage page = new MyTestPage();
page.launchPage(null);
page.getFname().verifyText("expected text");
}
}