How to use DataDrivenAnnotations class of net.serenitybdd.junit.runners package

Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.DataDrivenAnnotations

Source:WhenFindingTestDataInADataDrivenTest.java Github

copy

Full Screen

...41 final static class CSVDataDrivenTestScenario {}42 @Test43 public void the_parameterized_data_method_is_annotated_by_the_TestData_annotation() throws Exception {44 TestClass testClass = new TestClass(DataDrivenTestScenario.class);45 FrameworkMethod method = DataDrivenAnnotations.forClass(testClass).getTestDataMethod();46 assertThat(method.getName(), is("testData"));47 }48 @Test49 public void the_parameterized_data_method_returns_the_set_of_test_data() throws Throwable {50 TestClass testClass = new TestClass(DataDrivenTestScenario.class);51 DataTable testDataTable = DataDrivenAnnotations.forClass(testClass).getParametersTableFromTestDataAnnotation();52 assertThat(testDataTable.getRows().size(), is(3));53 }54 @Test55 public void testData_without_parameter_names_defines_default_parameter_names() throws Throwable {56 TestClass testClass = new TestClass(DataDrivenTestScenario.class);57 DataTable testDataTable = DataDrivenAnnotations.forClass(testClass).getParametersTableFromTestDataAnnotation();58 List<String> parameterNames = testDataTable.getHeaders();59 assertThat(parameterNames.size(), is(2));60 int i = 0;61 for (String parameterName : parameterNames) {62 assertThat(parameterName, is("Parameter " + (i+1)) );63 i++;64 }65 }66 @Test67 public void testData_with_parameter_names_uses_defined_parameter_names() throws Throwable {68 TestClass testClass = new TestClass(DataDrivenTestScenarioWithParamNames.class);69 DataTable testDataTable = DataDrivenAnnotations.forClass(testClass).getParametersTableFromTestDataAnnotation();70 List<String> parameterNames = testDataTable.getHeaders();71 assertThat(parameterNames.size(), is(2));72 assertThat(parameterNames.get(0), is("param-A"));73 assertThat(parameterNames.get(1), is("param-B"));74 }75 @Test76 public void should_be_able_to_count_the_number_of_data_entries() throws Throwable {77 TestClass testClass = new TestClass(CSVDataDrivenTestScenario.class);78 int dataEntries = DataDrivenAnnotations.forClass(testClass).countDataEntries();79 assertThat(dataEntries, is(12));80 }81 @Test82 public void should_be_able_to_get_data_Table_from_csv() throws Throwable {83 TestClass testClass = new TestClass(CSVDataDrivenTestScenario.class);84 DataTable testDataTable = DataDrivenAnnotations.forClass(testClass).getParametersTableFromTestDataSource();85 List<String> parameterNames = testDataTable.getHeaders();86 assertThat(parameterNames.size(), is(3));87 assertThat(parameterNames.get(0), is("NAME"));88 assertThat(parameterNames.get(1), is("AGE"));89 assertThat(parameterNames.get(2), is("ADDRESS"));90 }91 @Test92 public void should_be_able_to_count_the_number_of_data_entries_using_a_class_directory() throws Throwable {93 int dataEntries = DataDrivenAnnotations.forClass(CSVDataDrivenTestScenario.class).countDataEntries();94 assertThat(dataEntries, is(12));95 }96 @Test97 public void should_recognize_a_test_case_with_valid_test_data() {98 TestClass testClass = new TestClass(DataDrivenTestScenario.class);99 assertThat(DataDrivenAnnotations.forClass(testClass).hasTestDataDefined(), is(true));100 }101 final static class DataDrivenTestScenarioWithNoData {}102 @Test103 public void should_recognize_a_test_case_without_valid_test_data() {104 TestClass testClass = new TestClass(DataDrivenTestScenarioWithNoData.class);105 assertThat(DataDrivenAnnotations.forClass(testClass).hasTestDataDefined(), is(false));106 }107 @Test108 public void should_recognize_a_test_case_with_a_valid_test_data_source() {109 TestClass testClass = new TestClass(CSVDataDrivenTestScenario.class);110 assertThat(DataDrivenAnnotations.forClass(testClass).hasTestDataSourceDefined(), is(true));111 }112 @Test113 public void should_recognize_a_test_case_without_a_valid_test_data_source() {114 TestClass testClass = new TestClass(DataDrivenTestScenarioWithNoData.class);115 assertThat(DataDrivenAnnotations.forClass(testClass).hasTestDataSourceDefined(), is(false));116 }117 @Test118 public void should_load_test_class_instances_using_a_provided_test_data_source() throws IOException {119 TestClass testClass = new TestClass(CSVDataDrivenTestScenario.class);120 List<PersonTestScenario> testScenarios121 = DataDrivenAnnotations.forClass(testClass).getDataAsInstancesOf(PersonTestScenario.class);122 assertThat(testScenarios.size(), is(12));123 MatcherAssert.assertThat(testScenarios.get(0).getName(), is("Joe Smith"));124 MatcherAssert.assertThat(testScenarios.get(1).getName(), is("Jack Black"));125 }126 static class DataDrivenTestScenarioWithPrivateTestData {127 @TestData128 static Collection testData() {129 return Arrays.asList(new Object[][]{130 {"a", 1},131 {"b", 2},132 {"c", 3}133 });134 }135 }136 @Test(expected = IllegalArgumentException.class)137 public void the_parameterized_data_method_must_be_public() throws Exception {138 TestClass testClass = new TestClass(DataDrivenTestScenarioWithPrivateTestData.class);139 FrameworkMethod method = DataDrivenAnnotations.forClass(testClass).getTestDataMethod();140 assertThat(method.getName(), is("testData"));141 }142 static class DataDrivenTestScenarioWithNonStaticTestData {143 @TestData144 public Collection testData() {145 return Arrays.asList(new Object[][]{146 {"a", 1},147 {"b", 2},148 {"c", 3}149 });150 }151 }152 @Test(expected = IllegalArgumentException.class)153 public void the_parameterized_data_method_must_be_static() throws Exception {154 TestClass testClass = new TestClass(DataDrivenTestScenarioWithNonStaticTestData.class);155 FrameworkMethod method = DataDrivenAnnotations.forClass(testClass).getTestDataMethod();156 assertThat(method.getName(), is("testData"));157 }158 public class SimpleDataDrivenScenario {159 private String name;160 private String address;161 private String phone;162 }163 public class AnnotatedDataDrivenScenario {164 private String name;165 private String address;166 private String phone;167 @Qualifier168 public String getQualifier() {169 return name;170 }171 public String getName() {172 return name;173 }174 public void setName(String name) {175 this.name = name;176 }177 public String getAddress() {178 return address;179 }180 public void setAddress(String address) {181 this.address = address;182 }183 public String getPhone() {184 return phone;185 }186 public void setPhone(String phone) {187 this.phone = phone;188 }189 }190 @Test191 public void should_use_the_Qualifier_method_as_a_qualifier_if_present() {192 AnnotatedDataDrivenScenario testCase = new AnnotatedDataDrivenScenario();193 testCase.setName("Joe");194 String qualifier = QualifierFinder.forTestCase(testCase).getQualifier();195 assertThat(qualifier, is("Joe"));196 }197 public static class DataDrivenScenarioWithStaticQualifier {198 @Qualifier199 public static String qualifier() {200 return "QUALIFIER";201 }202 }203 @Test(expected = IllegalArgumentException.class)204 public void the_qualifier_method_must_not_be_static() {205 DataDrivenScenarioWithStaticQualifier testCase = new DataDrivenScenarioWithStaticQualifier();206 QualifierFinder.forTestCase(testCase).getQualifier();207 }208 public static class DataDrivenScenarioWithNonPublicQualifier {209 @Qualifier210 protected String qualifier() {211 return "QUALIFIER";212 }213 }214 @Test(expected = IllegalArgumentException.class)215 public void the_qualifier_method_must_be_public() {216 DataDrivenScenarioWithNonPublicQualifier testCase = new DataDrivenScenarioWithNonPublicQualifier();217 QualifierFinder.forTestCase(testCase).getQualifier();218 }219 public static class DataDrivenScenarioWithWronlyTypedQualifier {220 @Qualifier221 public int qualifier() {222 return 0;223 }224 }225 @Test(expected = IllegalArgumentException.class)226 public void the_qualifier_method_must_return_a_string() {227 DataDrivenScenarioWithWronlyTypedQualifier testCase = new DataDrivenScenarioWithWronlyTypedQualifier();228 QualifierFinder.forTestCase(testCase).getQualifier();229 }230 @UseTestDataFrom(value="test-data/simple-semicolon-data.csv", separator=';')231 final static class CSVDataDrivenTestScenarioUsingSemiColons {}232 @Test233 public void should_load_test_class_instances_using_semicolons() throws IOException {234 TestClass testClass = new TestClass(CSVDataDrivenTestScenarioUsingSemiColons.class);235 List<PersonTestScenario> testScenarios236 = DataDrivenAnnotations.forClass(testClass).getDataAsInstancesOf(PersonTestScenario.class);237 assertThat(testScenarios.size(), is(2));238 MatcherAssert.assertThat(testScenarios.get(0).getName(), is("Joe Smith"));239 MatcherAssert.assertThat(testScenarios.get(0).getAddress(), is("10 Main Street, Smithville"));240 MatcherAssert.assertThat(testScenarios.get(1).getName(), is("Jack Black"));241 MatcherAssert.assertThat(testScenarios.get(1).getAddress(), is("1 Main Street, Smithville"));242 }243 @UseTestDataFrom(value="test-data/simple-semicolon-data.csv,test-data/simple-semicolon-data.csv", separator=';')244 final static class CSVDataDrivenTestScenarioFromSeveralSourcesUsingSemiColons {}245 @Test246 public void should_load_test_class_instances_from_several_sources_using_semicolons() throws IOException {247 TestClass testClass = new TestClass(CSVDataDrivenTestScenarioFromSeveralSourcesUsingSemiColons.class);248 List<PersonTestScenario> testScenarios249 = DataDrivenAnnotations.forClass(testClass).getDataAsInstancesOf(PersonTestScenario.class);250 assertThat(testScenarios.size(), is(4));251 MatcherAssert.assertThat(testScenarios.get(0).getName(), is("Joe Smith"));252 MatcherAssert.assertThat(testScenarios.get(0).getAddress(), is("10 Main Street, Smithville"));253 MatcherAssert.assertThat(testScenarios.get(1).getName(), is("Jack Black"));254 MatcherAssert.assertThat(testScenarios.get(1).getAddress(), is("1 Main Street, Smithville"));255 MatcherAssert.assertThat(testScenarios.get(2).getName(), is("Joe Smith"));256 MatcherAssert.assertThat(testScenarios.get(2).getAddress(), is("10 Main Street, Smithville"));257 MatcherAssert.assertThat(testScenarios.get(3).getName(), is("Jack Black"));258 MatcherAssert.assertThat(testScenarios.get(3).getAddress(), is("1 Main Street, Smithville"));259 }260 @Test261 public void should_be_able_to_get_data_Table_from_a_semicolon_delimited_csv() throws Throwable {262 TestClass testClass = new TestClass(CSVDataDrivenTestScenarioUsingSemiColons.class);263 DataTable testDataTable = DataDrivenAnnotations.forClass(testClass).getParametersTableFromTestDataSource();264 List<String> parameterNames = testDataTable.getHeaders();265 assertThat(parameterNames.size(), is(3));266 assertThat(parameterNames.get(0), is("NAME"));267 assertThat(parameterNames.get(1), is("AGE"));268 assertThat(parameterNames.get(2), is("ADDRESS"));269 }270 @UseTestDataFrom(value="$DATADIR/simple-semicolon-data.csv", separator=';')271 final static class CSVDataDrivenTestScenarioFromSpecifiedDataDirectory {}272 @Test273 public void should_load_test_data_from_a_specified_directory() throws IOException {274 EnvironmentVariables environmentVariables = new MockEnvironmentVariables();275 environmentVariables.setProperty("thucydides.data.dir","test-data");276 TestClass testClass = new TestClass(CSVDataDrivenTestScenarioFromSpecifiedDataDirectory.class);277 List<PersonTestScenario> testScenarios278 = DataDrivenAnnotations.forClass(testClass)279 .usingEnvironmentVariables(environmentVariables)280 .getDataAsInstancesOf(PersonTestScenario.class);281 assertThat(testScenarios.size(), is(2));282 MatcherAssert.assertThat(testScenarios.get(0).getName(), is("Joe Smith"));283 MatcherAssert.assertThat(testScenarios.get(0).getAddress(), is("10 Main Street, Smithville"));284 MatcherAssert.assertThat(testScenarios.get(1).getName(), is("Jack Black"));285 MatcherAssert.assertThat(testScenarios.get(1).getAddress(), is("1 Main Street, Smithville"));286 }287 @UseTestDataFrom(value="does-not-exist/simple-semicolon-data.csv,test-data/simple-semicolon-data.csv", separator=';')288 final static class CSVDataDrivenTestScenarioFromSeveralPossibleSources{}289 @Test290 public void should_load_test_data_from_several_possible_sources() throws IOException {291 TestClass testClass = new TestClass(CSVDataDrivenTestScenarioFromSeveralPossibleSources.class);292 List<PersonTestScenario> testScenarios293 = DataDrivenAnnotations.forClass(testClass)294 .getDataAsInstancesOf(PersonTestScenario.class);295 assertThat(testScenarios.size(), is(2));296 MatcherAssert.assertThat(testScenarios.get(0).getName(), is("Joe Smith"));297 MatcherAssert.assertThat(testScenarios.get(0).getAddress(), is("10 Main Street, Smithville"));298 MatcherAssert.assertThat(testScenarios.get(1).getName(), is("Jack Black"));299 MatcherAssert.assertThat(testScenarios.get(1).getAddress(), is("1 Main Street, Smithville"));300 }301 @UseTestDataFrom(value="does-not-exist/simple-semicolon-data.csv,still-does-not-exist/simple-semicolon-data.csv", separator=';')302 final static class CSVDataDrivenTestScenarioFromSeveralPossibleSourcesWithNoValidSource{}303 @Test(expected = IllegalArgumentException.class)304 public void should_load_test_data_from_several_possible_sources_with_no_valid_source() throws IOException {305 TestClass testClass = new TestClass(CSVDataDrivenTestScenarioFromSeveralPossibleSourcesWithNoValidSource.class);306 List<PersonTestScenario> testScenarios307 = DataDrivenAnnotations.forClass(testClass)308 .getDataAsInstancesOf(PersonTestScenario.class);309 }310}...

Full Screen

Full Screen

Source:SerenityParameterizedRunner.java Github

copy

Full Screen

...46 this.tagScanner = new TagScanner(configuration.getEnvironmentVariables());47 if (runTestsInParallelFor(klass)) {48 scheduleParallelTestRunsFor(klass);49 }50 DataDrivenAnnotations testClassAnnotations = getTestAnnotations();51 if (testClassAnnotations.hasTestDataDefined()) {52 runners = buildTestRunnersForEachDataSetUsing(webDriverFactory, batchManager);53 } else if (testClassAnnotations.hasTestDataSourceDefined()) {54 runners = buildTestRunnersFromADataSourceUsing(webDriverFactory, batchManager);55 }56 }57 private void scheduleParallelTestRunsFor(final Class<?> klass) {58 setScheduler(new ParameterizedRunnerScheduler(klass, getThreadCountFor(klass)));59 }60 public boolean runTestsInParallelFor(final Class<?> klass) {61 return (klass.getAnnotation(Concurrent.class) != null);62 }63 public int getThreadCountFor(final Class<?> klass) {64 Concurrent concurrent = klass.getAnnotation(Concurrent.class);65 String threadValue = getThreadParameter(concurrent);66 int threads = (AVAILABLE_PROCESSORS * 2);67 if (StringUtils.isNotEmpty(threadValue)) {68 if (StringUtils.isNumeric(threadValue)) {69 threads = Integer.parseInt(threadValue);70 } else if (threadValue.endsWith("x")) {71 threads = getRelativeThreadCount(threadValue);72 }73 }74 return threads;75 }76 private String getThreadParameter(Concurrent concurrent) {77 String systemPropertyThreadValue =78 configuration.getEnvironmentVariables().getProperty(ThucydidesJUnitSystemProperties.CONCURRENT_THREADS.getName());79 String annotatedThreadValue = concurrent.threads();80 return (StringUtils.isNotEmpty(systemPropertyThreadValue) ? systemPropertyThreadValue : annotatedThreadValue);81 }82 private int getRelativeThreadCount(final String threadValue) {83 try {84 String threadCount = threadValue.substring(0, threadValue.length() - 1);85 return Integer.parseInt(threadCount) * AVAILABLE_PROCESSORS;86 } catch (NumberFormatException cause) {87 throw new IllegalArgumentException("Illegal thread value: " + threadValue, cause);88 }89 }90 private List<Runner> buildTestRunnersForEachDataSetUsing(final WebDriverFactory webDriverFactory,91 final BatchManager batchManager) throws Throwable {92 if (shouldSkipTest(getTestAnnotations().getTestMethod())) {93 return new ArrayList<>();94 }95 List<Runner> runners = new ArrayList<>();96 DataTable parametersTable = getTestAnnotations().getParametersTableFromTestDataAnnotation();97 for (int i = 0; i < parametersTable.getRows().size(); i++) {98 Class<?> testClass = getTestClass().getJavaClass();99 SerenityRunner runner = new TestClassRunnerForParameters(testClass,100 configuration,101 webDriverFactory,102 batchManager,103 parametersTable,104 i);105 runner.useQualifier(from(parametersTable.getRows().get(i).getValues()));106 runners.add(runner);107 }108 return runners;109 }110 private List<Runner> buildTestRunnersFromADataSourceUsing(final WebDriverFactory webDriverFactory,111 final BatchManager batchManager) throws Throwable {112 if (shouldSkipTest(getTestAnnotations().getTestMethod())) {113 return new ArrayList<>();114 }115 List<Runner> runners = new ArrayList<>();116 List<?> testCases = getTestAnnotations().getDataAsInstancesOf(getTestClass().getJavaClass());117 DataTable parametersTable = getTestAnnotations().getParametersTableFromTestDataSource();118 for (int i = 0; i < testCases.size(); i++) {119 Object testCase = testCases.get(i);120 SerenityRunner runner = new TestClassRunnerForInstanciatedTestCase(testCase,121 configuration,122 webDriverFactory,123 batchManager,124 parametersTable,125 i);126 runner.useQualifier(getQualifierFor(testCase));127 runners.add(runner);128 }129 return runners;130 }131 private boolean shouldSkipTest(FrameworkMethod method) {132 return !tagScanner.shouldRunMethod(getTestClass().getJavaClass(), method.getName());133 }134 private String getQualifierFor(final Object testCase) {135 return QualifierFinder.forTestCase(testCase).getQualifier();136 }137 private DataDrivenAnnotations getTestAnnotations() {138 return DataDrivenAnnotations.forClass(getTestClass());139 }140 private String from(final Collection testData) {141 StringBuffer testDataQualifier = new StringBuffer();142 boolean firstEntry = true;143 for (Object testDataValue : testData) {144 if (!firstEntry) {145 testDataQualifier.append("/");146 }147 testDataQualifier.append(testDataValue);148 firstEntry = false;149 }150 return testDataQualifier.toString();151 }152 /**...

Full Screen

Full Screen

Source:DataDrivenAnnotations.java Github

copy

Full Screen

...19import java.util.Arrays;20import java.util.List;21import java.util.Map;22import java.util.regex.Pattern;23public class DataDrivenAnnotations {24 private final EnvironmentVariables environmentVariables;25 private final Pattern DATASOURCE_PATH_SEPARATORS = Pattern.compile("[;,]");26 public static DataDrivenAnnotations forClass(final Class testClass) {27 return new DataDrivenAnnotations(testClass);28 }29 public static DataDrivenAnnotations forClass(final TestClass testClass) {30 return new DataDrivenAnnotations(testClass);31 }32 private final TestClass testClass;33 DataDrivenAnnotations(final Class testClass) {34 this(new TestClass(testClass));35 }36 DataDrivenAnnotations(final TestClass testClass) {37 this(testClass, Injectors.getInjector().getProvider(EnvironmentVariables.class).get());38 }39 DataDrivenAnnotations(final TestClass testClass, EnvironmentVariables environmentVariables) {40 this.testClass = testClass;41 this.environmentVariables = environmentVariables;42 }43 DataDrivenAnnotations usingEnvironmentVariables(EnvironmentVariables environmentVariables) {44 return new DataDrivenAnnotations(this.testClass, environmentVariables);45 }46 public DataTable getParametersTableFromTestDataSource() throws Throwable {47 TestDataSource testDataSource = new CSVTestDataSource(findTestDataSource(), findTestDataSeparator());48 List<Map<String, String>> testData = testDataSource.getData();49 List<String> headers = testDataSource.getHeaders();50 return DataTable.withHeaders(headers)51 .andMappedRows(testData)52 .build();53 }54 public List<FrameworkMethod> getTestMethods() {55 List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Test.class);56 if (methods.isEmpty()) {57 throw new IllegalStateException("Parameterized test should have at least one @Test method");58 }...

Full Screen

Full Screen

Source:TestClassRunnerForParameters.java Github

copy

Full Screen

...50 } catch (ClassCastException cause) {51 throw new Exception(String.format(52 "%s.%s() must return a Collection of arrays.",53 getTestClass().getName(),54 DataDrivenAnnotations.forClass(getTestClass()).getTestDataMethod().getName()),55 cause);56 }57 }58 @Override59 protected String getName() {60 String firstParameter = parametersTable.getRows().get(parameterSetNumber).getValues().get(0).toString();61 return String.format("[%s]", firstParameter);62 }63 @Override64 protected String testName(final FrameworkMethod method) {65 return String.format("%s[%s]", method.getName(), parameterSetNumber);66 }67 @Override68 protected void validateConstructor(final List<Throwable> errors) {...

Full Screen

Full Screen

Source:DataDrivenTestFinder.java Github

copy

Full Screen

1package net.serenitybdd.junit.finder;2import net.serenitybdd.core.collect.NewList;3import net.serenitybdd.junit.runners.DataDrivenAnnotations;4import org.junit.runners.model.TestClass;5import java.io.IOException;6import java.util.ArrayList;7import java.util.List;8/**9 * Returns all of the Thucydides classes under the specified package.10 */11public class DataDrivenTestFinder extends TestFinder {12 public DataDrivenTestFinder(final String rootPackage) {13 super(rootPackage);14 }15 @Override16 public List<Class<?>> getClasses() {17 return sorted(new ArrayList(getDataDrivenTestClasses()));18 }19 @Override20 public int countTestMethods() {21 int totalTestMethods = 0;22 for(Class testClass : getDataDrivenTestClasses()) {23 try {24 totalTestMethods += DataDrivenAnnotations.forClass(new TestClass(testClass)).countDataEntries();25 } catch (IOException e) {26 throw new IllegalArgumentException("Failed to read test data for " + testClass);27 }28 }29 return totalTestMethods;30 }31}

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.junit.runners.DataDrivenAnnotations;2import org.junit.Test;3import org.junit.runner.RunWith;4import org.junit.runners.Parameterized;5@RunWith(Parameterized.class)6public class DataDrivenAnnotationsTest {7 @Parameterized.Parameters(name = "{0} - {1}")8 public static Iterable<Object[]> data() {9 return DataDrivenAnnotations.forClass(DataDrivenAnnotationsTest.class);10 }11 @Parameterized.Parameter(0)12 public String name;13 @Parameterized.Parameter(1)14 public String value;15 public void shouldDoSomething() {16 System.out.println("Name: " + name + ", Value: " + value);17 }18}19import net.serenitybdd.junit.runners.DataDrivenAnnotations;20import org.junit.Test;21import org.junit.runner.RunWith;22import org.junit.runners.Parameterized;23@RunWith(Parameterized.class)24public class DataDrivenAnnotationsTest {25 @Parameterized.Parameters(name = "{0} - {1}")26 public static Iterable<Object[]> data() {27 return DataDrivenAnnotations.forClass(DataDrivenAnnotationsTest.class);28 }29 @Parameterized.Parameter(0)30 public String name;31 @Parameterized.Parameter(1)32 public String value;33 public void shouldDoSomething() {34 System.out.println("Name: " + name + ", Value: " + value);35 }36}37import net.serenitybdd.junit.runners.DataDrivenAnnotations;38import org.junit.jupiter.params.ParameterizedTest;39import org.junit.jupiter.params.provider.MethodSource;40import java.util.stream.Stream;41public class DataDrivenAnnotationsTest {42 @ParameterizedTest(name = "{0} - {1}")43 @MethodSource("data")44 public void shouldDoSomething(String name, String value) {45 System.out.println("Name: " + name + ", Value: " + value);46 }47 private static Stream<Object[]> data() {48 return DataDrivenAnnotations.forClass(DataDrivenAnnotationsTest.class);49 }50}

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.junit.runners.DataDrivenAnnotations;2import net.thucydides.core.annotations.Steps;3import org.junit.Test;4import org.junit.runner.RunWith;5import net.serenitybdd.junit.runners.SerenityRunner;6@RunWith(SerenityRunner.class)7public class TestRunner {8 LoginSteps loginSteps;9 public void loginTest(String username, String password) {10 loginSteps.openLoginPage();11 loginSteps.login(username, password);12 loginSteps.verifyLogin();13 }14}15[{"username":"admin","password":"admin"},{"username":"user","password":"password"}]

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1@RunWith(DataDrivenAnnotations.class)2public class DataDrivenTest {3 WebDriver driver;4 Pages pages;5 LoginSteps loginSteps;6 SearchSteps searchSteps;7 AddToCartSteps addToCartSteps;8 CartSteps cartSteps;9 @DataPoints("data")10 public static List<String> data() {11 return Arrays.asList("Selenium", "Serenity", "BDD", "Cucumber");12 }13 @UseTestDataFrom("data")14 public void search_and_add_to_cart(String keyword) {15 loginSteps.login();16 searchSteps.search(keyword);17 addToCartSteps.add_to_cart();18 cartSteps.should_contain(keyword);19 }20}21@RunWith(DataDrivenAnnotations.class)22public class DataDrivenTest {23 WebDriver driver;24 Pages pages;25 LoginSteps loginSteps;26 SearchSteps searchSteps;27 AddToCartSteps addToCartSteps;28 CartSteps cartSteps;29 @DataPoints("data")30 public static List<String> data() {31 return Arrays.asList("Selenium", "Serenity", "BDD", "Cucumber");32 }33 @UseTestDataFrom("data")34 public void search_and_add_to_cart(String keyword) {35 loginSteps.login();36 searchSteps.search(keyword);37 addToCartSteps.add_to_cart();38 cartSteps.should_contain(keyword);39 }40}41@RunWith(Data

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1package com.serenitybdd.junit.runners;2import net.serenitybdd.junit.runners.SerenityRunner;3import net.thucydides.core.annotations.DataDrivenAnnotations;4import org.junit.runners.model.InitializationError;5public class DataDrivenSerenityRunner extends SerenityRunner {6 public DataDrivenSerenityRunner(Class<?> testClass) throws InitializationError {7 super(testClass);8 DataDrivenAnnotations.initialize(this);9 }10}11package com.serenitybdd.junit.runners;12import net.serenitybdd.junit.runners.SerenityRunner;13import net.thucydides.core.annotations.DataDrivenAnnotations;14import org.junit.runners.model.InitializationError;15public class DataDrivenSerenityRunner extends SerenityRunner {16 public DataDrivenSerenityRunner(Class<?> testClass) throws InitializationError {17 super(testClass);18 DataDrivenAnnotations.initialize(this);19 }20}21package com.serenitybdd.junit.runners;22import net.serenitybdd.junit.runners.SerenityRunner;23import net.thucydides.core.annotations.DataDrivenAnnotations;24import org.junit.runners.model.InitializationError;25public class DataDrivenSerenityRunner extends SerenityRunner {26 public DataDrivenSerenityRunner(Class<?> testClass) throws InitializationError {27 super(testClass);28 DataDrivenAnnotations.initialize(this);29 }30}31package com.serenitybdd.junit.runners;32import net.serenitybdd.junit.runners.SerenityRunner;33import net.thucydides.core.annotations.DataDrivenAnnotations;34import org.junit.runners.model.InitializationError;35public class DataDrivenSerenityRunner extends SerenityRunner {36 public DataDrivenSerenityRunner(Class<?> testClass) throws InitializationError {37 super(testClass);38 DataDrivenAnnotations.initialize(this);39 }40}41package com.serenitybdd.junit.runners;42import net.serenitybdd.junit.runners.SerenityRunner;43import net.thucydides.core.annotations.DataDrivenAnnotations;44import org.junit.runners.model.InitializationError;45public class DataDrivenSerenityRunner extends SerenityRunner {46 public DataDrivenSerenityRunner(Class<?> testClass) throws InitializationError {

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.junit.runners.SerenityRunner;2import net.serenitybdd.jbehave.DataDrivenStory;3import net.serenitybdd.jbehave.DataDrivenExamplesTableFactory;4@RunWith(SerenityRunner.class)5@UseExamplesTableFactory(DataDrivenExamplesTableFactory.class)6public class LoginTest extends DataDrivenStory {7}8package com.test;9import net.serenitybdd.jbehave.annotations.Metafilter;10import net.thucydides.core.annotations.Steps;11import com.test.steps.LoginSteps;12public class LoginTest extends DataDrivenStory {13 LoginSteps loginSteps;14 @Metafilter("+username")15 public void enterUsername(String username) {16 loginSteps.enterUsername(username);17 }18 @Metafilter("+password")19 public void enterPassword(String password) {20 loginSteps.enterPassword(password);21 }22 @Metafilter("+username")23 public void verifyUsername(String username) {24 loginSteps.verifyUsername(username);25 }26 @Metafilter("+password")27 public void verifyPassword(String password) {28 loginSteps.verifyPassword(password);29 }30}31package com.test.steps;32import net.thucydides.core.annotations.Step;33public class LoginSteps {34 public void enterUsername(String username) {35 }36 public void enterPassword(String password) {37 }38 public void verifyUsername(String username) {39 }40 public void verifyPassword(String password) {41 }42}

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1@RunWith(DataDrivenAnnotations.class)2public class TestRunner {3 @TestData({4 })5 public void testAdd(int a, int b, int c) {6 assertEquals(a + b, c);7 }8}

Full Screen

Full Screen

DataDrivenAnnotations

Using AI Code Generation

copy

Full Screen

1@RunWith(DataDrivenAnnotations.class)2public class DataDrivenTest {3 public static Collection<Object[]> testData(){4 return Arrays.asList(new Object[][]{5 {"1", "2", "3"},6 {"2", "3", "5"},7 {"3", "4", "7"},8 {"4", "5", "9"},9 });10 }11 public String firstNumber;12 @Parameter(1)13 public String secondNumber;14 @Parameter(2)15 public String result;16 public void testAddition(){17 System.out.println("First Number: " + firstNumber);18 System.out.println("Second Number: " + secondNumber);19 System.out.println("Result: " + result);20 }21}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Serenity JUnit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful