Our automation framework is written in Java and uses Testng. We use the @Test
annotation to mark out our tests and provide the groups and a description for the test which we write in Gherkin. We use the test report created by Serenity
I have been trying to create a static constant class that we can use to build a test description so that it handle HTML tags rather than putting this into the String
itself so its easier to read and so any HTML format that the test report uses can be done within this class rather than each
For example:
@Test( groups = { TestGroup.One, TestGroup.TWO }, description =
"<b>Given</b> I am in Scenario One</br>" +
"<b>When</b>I do something</br>" +
"<b>Then</b>I get a result")
protected void testScript() {
...
}
would actually look like:
@Test( groups = { TestGroup.One, TestGroup.TWO }, description =
TestDescription
.given("I am in Scenario One")
.when("I do something")
.then("I get a result");)
protected void testScript() {
...
}
The code I currently have:
public final class TestDescription {
private static String description = "";
public static String given(final String given) {
return "<b>Given</b>" + given + "</br>";
}
public static TestDescription when(final String when) {
description = description + "<b>When</b>" + when + "</br>";
return null;
}
public static TestDescription then(final String then) {
description = description + "<b>Then</b>" + then + "</br>";
return null;
}
public static TestDescription and(final String and) {
description = description + "<b>And</b>" + and + "</br>";
return null;
}
public static String build() {
return description;
}
}