From e3da38c4bc092877b3fc3135fb7aaed1582e644f Mon Sep 17 00:00:00 2001 From: John Ferguson Smart Date: Sun, 20 Oct 2024 15:52:25 +0100 Subject: [PATCH] Added Cucumber and JUnit 5 tests to the smoketests --- .../runners/SerenityParameterizedRunner.java | 2 + serenity-smoketests/pom.xml | 5 +- .../todos/screenplay/tasks/CompleteItems.java | 20 +++ .../LearnAboutTheApplication.java | 2 +- .../AddDifferentSortsOfTodos.java | 62 --------- .../CompleteATodo.java | 4 +- .../ToggleAllTodos.java | 2 +- .../TodosBelongToAUser.java | 16 --- .../ClearCompletedTodos.java | 2 +- .../DeleteTodos.java | 2 +- .../FilteringTodos.java | 2 +- .../LearnAboutTheApplication.java | 21 ++- .../completing_todos/CompleteATodo.java | 33 ++--- .../maintain_my_todo_list/FilteringTodos.java | 121 ++++++++++-------- .../features/record_todos/AddNewTodos.java | 16 +-- .../features/cucumber/add_new_items.feature | 29 +++++ .../features/todomvc/add_new_items.feature | 7 - .../src/test/resources/serenity.conf | 2 +- 18 files changed, 161 insertions(+), 187 deletions(-) create mode 100644 serenity-smoketests/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItems.java rename serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/{accessing_the_application => accessing_application}/LearnAboutTheApplication.java (98%) delete mode 100644 serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/AddDifferentSortsOfTodos.java rename serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/{completing_todos => completing_the_todos}/CompleteATodo.java (96%) rename serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/{completing_todos => completing_the_todos}/ToggleAllTodos.java (99%) delete mode 100644 serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/TodosBelongToAUser.java rename serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/{maintain_my_todo_list => maintain_the_todo_list}/ClearCompletedTodos.java (98%) rename serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/{maintain_my_todo_list => maintain_the_todo_list}/DeleteTodos.java (98%) rename serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/{maintain_my_todo_list => maintain_the_todo_list}/FilteringTodos.java (99%) create mode 100644 serenity-smoketests/src/test/resources/features/cucumber/add_new_items.feature delete mode 100644 serenity-smoketests/src/test/resources/features/todomvc/add_new_items.feature diff --git a/serenity-junit/src/main/java/net/serenitybdd/junit/runners/SerenityParameterizedRunner.java b/serenity-junit/src/main/java/net/serenitybdd/junit/runners/SerenityParameterizedRunner.java index bea308ec1..fc51265c5 100644 --- a/serenity-junit/src/main/java/net/serenitybdd/junit/runners/SerenityParameterizedRunner.java +++ b/serenity-junit/src/main/java/net/serenitybdd/junit/runners/SerenityParameterizedRunner.java @@ -30,7 +30,9 @@ /** * Run a Serenity test suite using a set of data. * Similar to the JUnit parameterized tests, but better ;-). + * @Deprecated we recommend moving to JUnit 5 which supports data-driven tests natively. */ +@Deprecated public class SerenityParameterizedRunner extends Suite implements Taggable { private static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors(); diff --git a/serenity-smoketests/pom.xml b/serenity-smoketests/pom.xml index 574cfa777..88c193d9c 100644 --- a/serenity-smoketests/pom.xml +++ b/serenity-smoketests/pom.xml @@ -21,7 +21,7 @@ 5.11.2 - 1.11.1 + 1.11.2 @@ -148,6 +148,9 @@ 11 11 + + -parameters + diff --git a/serenity-smoketests/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItems.java b/serenity-smoketests/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItems.java new file mode 100644 index 000000000..ed72a5a89 --- /dev/null +++ b/serenity-smoketests/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItems.java @@ -0,0 +1,20 @@ +package net.serenitybdd.demos.todos.screenplay.tasks; + +import net.serenitybdd.demos.todos.screenplay.user_interface.TodoListItem; +import net.serenitybdd.screenplay.Performable; +import net.serenitybdd.screenplay.Task; +import net.serenitybdd.screenplay.actions.Click; + +import java.util.List; + +public class CompleteItems { + public static Performable called(List itemNames) { + return Task.where("{0} completes the items called: " + itemNames, + actor -> { + itemNames.forEach(itemName -> actor.attemptsTo( + Click.on(TodoListItem.COMPLETE_ITEM.of(itemName)) + )); + } + ); + } +} \ No newline at end of file diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/LearnAboutTheApplication.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_application/LearnAboutTheApplication.java similarity index 98% rename from serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/LearnAboutTheApplication.java rename to serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_application/LearnAboutTheApplication.java index 9ad2d63c2..68a0c98e8 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/LearnAboutTheApplication.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_application/LearnAboutTheApplication.java @@ -1,4 +1,4 @@ -package net.serenitybdd.demos.todos.pageobjects.features.accessing_the_application; +package net.serenitybdd.demos.todos.pageobjects.features.accessing_application; import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; import net.serenitybdd.junit.runners.SerenityRunner; diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/AddDifferentSortsOfTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/AddDifferentSortsOfTodos.java deleted file mode 100644 index 0f2a24339..000000000 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/accessing_the_application/AddDifferentSortsOfTodos.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.serenitybdd.demos.todos.pageobjects.features.accessing_the_application; - -import net.serenitybdd.annotations.*; -import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; -import net.serenitybdd.junit.runners.SerenityParameterizedRunner; -import net.thucydides.junit.annotations.Concurrent; -import net.thucydides.junit.annotations.TestData; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; - -import java.util.Arrays; -import java.util.Collection; - -@RunWith(SerenityParameterizedRunner.class) -@Concurrent(threads = "4") -@WithTagValuesOf("smoketest") -@WithTags({ - @WithTag("PageObjects pattern"), - @WithTag("version:RELEASE-3"), -}) -public class AddDifferentSortsOfTodos { - - @Managed - WebDriver janesBrowser; - - @TestData - public static Collection todoItems(){ - return Arrays.asList(new Object[][]{ - {"walk the lion"}, - {"wash the dishes"}, - {"feed the ferrets"}, - {"count the rabbits"}, - }); - } - - @Steps - TodoUserSteps james; - - private final String todo; - - - public AddDifferentSortsOfTodos(String todo) { - this.todo = todo; - } - - - @Before - public void openTheApplication() { - james.starts_with_an_empty_todo_list(); - - } - - @Test -// @Manual - public void shouldBeAbleToAddANewTodoItem() { - james.should_see_the_correct_website_title(); - james.should_see_the_correct_application_heading(); - james.should_see_the_about_section(); - } -} diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_todos/CompleteATodo.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_the_todos/CompleteATodo.java similarity index 96% rename from serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_todos/CompleteATodo.java rename to serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_the_todos/CompleteATodo.java index 3a4b01786..f04a71ad9 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_todos/CompleteATodo.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_the_todos/CompleteATodo.java @@ -1,4 +1,4 @@ -package net.serenitybdd.demos.todos.pageobjects.features.completing_todos; +package net.serenitybdd.demos.todos.pageobjects.features.completing_the_todos; import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; import net.serenitybdd.junit.runners.SerenityRunner; @@ -6,7 +6,6 @@ import net.serenitybdd.annotations.Steps; import net.serenitybdd.annotations.WithTag; import net.serenitybdd.annotations.WithTags; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -18,7 +17,6 @@ @WithTag("version:RELEASE-2"), @WithTag("smoke"), }) - public class CompleteATodo { @Managed(uniqueSession = true) diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_todos/ToggleAllTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_the_todos/ToggleAllTodos.java similarity index 99% rename from serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_todos/ToggleAllTodos.java rename to serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_the_todos/ToggleAllTodos.java index 7f5a65eaa..534142156 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_todos/ToggleAllTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/completing_the_todos/ToggleAllTodos.java @@ -1,4 +1,4 @@ -package net.serenitybdd.demos.todos.pageobjects.features.completing_todos; +package net.serenitybdd.demos.todos.pageobjects.features.completing_the_todos; import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; import net.serenitybdd.junit.runners.SerenityRunner; diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/TodosBelongToAUser.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/TodosBelongToAUser.java deleted file mode 100644 index 1f8cb9b86..000000000 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/TodosBelongToAUser.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.serenitybdd.demos.todos.pageobjects.features.maintain_my_todo_list; - -import net.serenitybdd.junit.runners.SerenityRunner; -import net.serenitybdd.annotations.WithTag; -import org.junit.Ignore; -import org.junit.runner.RunWith; - -@RunWith(SerenityRunner.class) -@WithTag("PageObjects pattern") -@Ignore -public class TodosBelongToAUser { - - // This test requires two browsers running in parallel within a single test. - // As it's not doable using the Classic Serenity with PageObjects, - // please use the Screenplay version instead. -} diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/ClearCompletedTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/ClearCompletedTodos.java similarity index 98% rename from serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/ClearCompletedTodos.java rename to serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/ClearCompletedTodos.java index 4f9b1fb72..fbacca2fe 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/ClearCompletedTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/ClearCompletedTodos.java @@ -1,4 +1,4 @@ -package net.serenitybdd.demos.todos.pageobjects.features.maintain_my_todo_list; +package net.serenitybdd.demos.todos.pageobjects.features.maintain_the_todo_list; import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; import net.serenitybdd.junit.runners.SerenityRunner; diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/DeleteTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/DeleteTodos.java similarity index 98% rename from serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/DeleteTodos.java rename to serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/DeleteTodos.java index 8f452a1fe..4b1482853 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/DeleteTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/DeleteTodos.java @@ -1,4 +1,4 @@ -package net.serenitybdd.demos.todos.pageobjects.features.maintain_my_todo_list; +package net.serenitybdd.demos.todos.pageobjects.features.maintain_the_todo_list; import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; import net.serenitybdd.junit.runners.SerenityRunner; diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/FilteringTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/FilteringTodos.java similarity index 99% rename from serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/FilteringTodos.java rename to serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/FilteringTodos.java index bafc1d096..d8830590a 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_my_todo_list/FilteringTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/pageobjects/features/maintain_the_todo_list/FilteringTodos.java @@ -1,4 +1,4 @@ -package net.serenitybdd.demos.todos.pageobjects.features.maintain_my_todo_list; +package net.serenitybdd.demos.todos.pageobjects.features.maintain_the_todo_list; import net.serenitybdd.demos.todos.pageobjects.model.TodoStatusFilter; import net.serenitybdd.demos.todos.pageobjects.steps.TodoUserSteps; diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/accessing_the_application/LearnAboutTheApplication.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/accessing_the_application/LearnAboutTheApplication.java index 4afb69c19..6cbaab6e1 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/accessing_the_application/LearnAboutTheApplication.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/accessing_the_application/LearnAboutTheApplication.java @@ -1,17 +1,16 @@ package net.serenitybdd.demos.todos.screenplay.features.accessing_the_application; +import net.serenitybdd.annotations.Managed; import net.serenitybdd.demos.todos.screenplay.questions.Application; import net.serenitybdd.demos.todos.screenplay.questions.Placeholder; import net.serenitybdd.demos.todos.screenplay.tasks.Start; -import net.serenitybdd.junit.runners.SerenityRunner; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.abilities.BrowseTheWeb; -import net.serenitybdd.annotations.Managed; -import net.serenitybdd.annotations.WithTag; -import net.serenitybdd.annotations.WithTags; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.WebDriver; import static net.serenitybdd.screenplay.GivenWhenThen.*; @@ -23,11 +22,7 @@ /** * This example illustrates using Serenity Steps with JUnit. */ -@RunWith(SerenityRunner.class) -@WithTags({ - @WithTag("Screenplay pattern"), - @WithTag("version:RELEASE-1"), -}) +@ExtendWith(SerenityJUnit5Extension.class) public class LearnAboutTheApplication { private Actor james = Actor.named("James"); @@ -35,7 +30,7 @@ public class LearnAboutTheApplication { @Managed private WebDriver hisBrowser; - @Before + @BeforeEach public void jamesCanBrowseTheWeb() { james.can(BrowseTheWeb.with(hisBrowser)); } diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/completing_todos/CompleteATodo.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/completing_todos/CompleteATodo.java index a0cf2503a..24241a224 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/completing_todos/CompleteATodo.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/completing_todos/CompleteATodo.java @@ -1,29 +1,23 @@ package net.serenitybdd.demos.todos.screenplay.features.completing_todos; +import net.serenitybdd.annotations.Managed; import net.serenitybdd.demos.todos.screenplay.questions.TheItemStatus; import net.serenitybdd.demos.todos.screenplay.questions.TheItems; import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItem; import net.serenitybdd.demos.todos.screenplay.tasks.Start; -import net.serenitybdd.junit.runners.SerenityRunner; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.abilities.BrowseTheWeb; -import net.serenitybdd.annotations.Managed; -import net.serenitybdd.annotations.WithTag; -import net.serenitybdd.annotations.WithTags; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.WebDriver; import static net.serenitybdd.demos.todos.screenplay.model.TodoStatus.Completed; import static net.serenitybdd.screenplay.GivenWhenThen.*; import static org.hamcrest.CoreMatchers.is; -@RunWith(SerenityRunner.class) -@WithTags({ - @WithTag("Screenplay pattern"), - @WithTag("version:RELEASE-1"), -}) +@ExtendWith(SerenityJUnit5Extension.class) public class CompleteATodo { private Actor james = Actor.named("James"); @@ -31,7 +25,8 @@ public class CompleteATodo { @Managed private WebDriver hisBrowser; - @Before public void jamesCanBrowseTheWeb() { + @BeforeEach + public void jamesCanBrowseTheWeb() { james.can(BrowseTheWeb.with(hisBrowser)); } @@ -39,16 +34,16 @@ public class CompleteATodo { public void should_be_able_to_complete_a_todo() { givenThat(james).wasAbleTo( - Start.withATodoListContaining("Walk the dog", "Put out the garbage") + Start.withATodoListContaining("Walk the dog", "Put out the garbage") ); when(james).attemptsTo( - CompleteItem.called("Walk the dog") + CompleteItem.called("Walk the dog") ); then(james).should( - seeThat(TheItemStatus.forTheItemCalled("Walk the dog"), is(Completed)), - seeThat(TheItems.leftCount(), is(1)) + seeThat(TheItemStatus.forTheItemCalled("Walk the dog"), is(Completed)), + seeThat(TheItems.leftCount(), is(1)) ); } @@ -56,11 +51,11 @@ public void should_be_able_to_complete_a_todo() { public void should_see_the_number_of_todos_decrease_when_an_item_is_completed() { givenThat(james).wasAbleTo( - Start.withATodoListContaining("Walk the dog", "Put out the garbage") + Start.withATodoListContaining("Walk the dog", "Put out the garbage") ); when(james).attemptsTo( - CompleteItem.called("Walk the dog") + CompleteItem.called("Walk the dog") ); then(james).should(seeThat(TheItems.leftCount(), is(1))); diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java index 22c3a4398..0d221c4e1 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/maintain_my_todo_list/FilteringTodos.java @@ -1,80 +1,99 @@ package net.serenitybdd.demos.todos.screenplay.features.maintain_my_todo_list; +import net.serenitybdd.annotations.Managed; +import net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter; import net.serenitybdd.demos.todos.screenplay.questions.CurrentFilter; import net.serenitybdd.demos.todos.screenplay.questions.TheItems; import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItem; +import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItems; import net.serenitybdd.demos.todos.screenplay.tasks.FilterItems; import net.serenitybdd.demos.todos.screenplay.tasks.Start; -import net.serenitybdd.junit.runners.SerenityRunner; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.abilities.BrowseTheWeb; -import net.serenitybdd.annotations.Managed; -import net.serenitybdd.annotations.WithTag; -import net.serenitybdd.annotations.WithTags; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.openqa.selenium.WebDriver; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import static net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter.*; import static net.serenitybdd.screenplay.GivenWhenThen.*; import static org.hamcrest.Matchers.*; -@RunWith(SerenityRunner.class) -@WithTags({ - @WithTag("Screenplay pattern"), - @WithTag("version:RELEASE-2"), -}) +@ExtendWith(SerenityJUnit5Extension.class) public class FilteringTodos { private Actor james = Actor.named("James"); - @Managed private WebDriver hisBrowser; - @Before public void jamesCanBrowseTheWeb() { - james.can(BrowseTheWeb.with(hisBrowser)); - } - - @Test - public void should_be_able_to_view_only_completed_todos() { - givenThat(james).wasAbleTo(Start.withATodoListContaining("Walk the dog", "Put out the garbage")); - - when(james).attemptsTo( - CompleteItem.called("Walk the dog"), - FilterItems.toShow(Completed) - ); + @Managed + private WebDriver hisBrowser; - then(james).should(seeThat(TheItems.displayed(), hasItems("Walk the dog"))); - and(james).should(seeThat(TheItems.displayed(), not(hasItems("Put out the garbage")))); - and(james).should(seeThat(CurrentFilter.selected(), is(Completed))); + @BeforeEach + public void jamesCanBrowseTheWeb() { + james.can(BrowseTheWeb.with(hisBrowser)); } - @Test - public void should_be_able_to_view_only_incomplete_todos() { - - givenThat(james).wasAbleTo(Start.withATodoListContaining("Walk the dog", "Put out the garbage")); - - when(james).attemptsTo( - CompleteItem.called("Walk the dog"), - FilterItems.toShow(Active) + @ParameterizedTest + @CsvSource({ + // initialTodos, itemsToComplete, filtersToApply, expectedDisplayedItems, expectedNotDisplayedItems, expectedSelectedFilter + "'Walk the dog;Put out the garbage', 'Walk the dog', 'Completed', 'Walk the dog', 'Put out the garbage', 'Completed'", + "'Walk the dog;Put out the garbage', 'Walk the dog', 'Active', 'Put out the garbage', 'Walk the dog', 'Active'", + "'Walk the dog;Put out the garbage', 'Walk the dog', 'All', 'Walk the dog;Put out the garbage', '', 'All'" + }) + public void should_be_able_to_filter_todos( + String initialTodosStr, + String itemsToCompleteStr, + String filterToApply, + String expectedDisplayedItemsStr, + String expectedNotDisplayedItemsStr, + String expectedSelectedFilterStr + ) { + // Parse the CSV string parameters into lists + List initialTodos = parseStringToList(initialTodosStr); + List itemsToComplete = parseStringToList(itemsToCompleteStr); + List expectedDisplayedItems = parseStringToList(expectedDisplayedItemsStr); + List expectedNotDisplayedItems = parseStringToList(expectedNotDisplayedItemsStr); + TodoStatusFilter expectedSelectedFilter = TodoStatusFilter.valueOf(expectedSelectedFilterStr); + + // Given + givenThat(james).wasAbleTo(Start.withATodoListContaining(initialTodos)); + + // When + james.attemptsTo( + CompleteItems.called(itemsToComplete), + FilterItems.toShow(TodoStatusFilter.valueOf(filterToApply)) ); - then(james).should(seeThat(TheItems.displayed(), hasItems("Put out the garbage"))); - and(james).should(seeThat(TheItems.displayed(), not(hasItems("Walk the dog")))); - and(james).should(seeThat(CurrentFilter.selected(), is(Active))); + // Then + then(james).should( + seeThat(TheItems.displayed(), hasItems(expectedDisplayedItems.toArray(new String[0]))), + seeThat(CurrentFilter.selected(), is(expectedSelectedFilter)) + ); + if (!expectedNotDisplayedItems.isEmpty()) { + and(james).should(seeThat(TheItems.displayed(), not(hasItems(expectedNotDisplayedItems.toArray(new String[0]))))); + } } - @Test - public void should_be_able_to_view_both_complete_and_incomplete_todos() { - - givenThat(james).wasAbleTo(Start.withATodoListContaining("Walk the dog", "Put out the garbage")); - - when(james).attemptsTo( - CompleteItem.called("Walk the dog"), - FilterItems.toShow(Active), - FilterItems.toShow(All) - ); + // Helper method to parse semicolon-separated strings into lists + private List parseStringToList(String str) { + if (str == null || str.trim().isEmpty()) { + return new ArrayList<>(); + } + return Arrays.asList(str.split(";")); + } - then(james).should(seeThat(TheItems.displayed(), hasItems("Walk the dog", "Put out the garbage"))); - and(james).should(seeThat(CurrentFilter.selected(), is(All))); + // Helper method to parse filter names into TodoStatusFilter enum instances + private List parseFilters(List filterNames) { + List filters = new ArrayList<>(); + for (String name : filterNames) { + filters.add(TodoStatusFilter.valueOf(name)); + } + return filters; } } diff --git a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/record_todos/AddNewTodos.java b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/record_todos/AddNewTodos.java index a889140f4..e52f508ca 100644 --- a/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/record_todos/AddNewTodos.java +++ b/serenity-smoketests/src/test/java/net/serenitybdd/demos/todos/screenplay/features/record_todos/AddNewTodos.java @@ -2,14 +2,15 @@ import net.serenitybdd.demos.todos.screenplay.questions.TheItems; import net.serenitybdd.demos.todos.screenplay.tasks.AddATodoItem; import net.serenitybdd.demos.todos.screenplay.tasks.Start; -import net.serenitybdd.junit.runners.SerenityRunner; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.abilities.BrowseTheWeb; import net.serenitybdd.annotations.Managed; import net.serenitybdd.annotations.WithTag; import net.serenitybdd.annotations.WithTags; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; import org.openqa.selenium.WebDriver; @@ -20,16 +21,13 @@ /** * This example illustrates using Serenity Steps with JUnit. */ -@RunWith(SerenityRunner.class) -@WithTags({ - @WithTag("Screenplay pattern"), - @WithTag("version:RELEASE-1"), -}) +@ExtendWith(SerenityJUnit5Extension.class) public class AddNewTodos { private Actor james = Actor.named("James"); @Managed private WebDriver hisBrowser; - @Before public void jamesCanBrowseTheWeb() { + @BeforeEach + public void jamesCanBrowseTheWeb() { james.can(BrowseTheWeb.with(hisBrowser)); } diff --git a/serenity-smoketests/src/test/resources/features/cucumber/add_new_items.feature b/serenity-smoketests/src/test/resources/features/cucumber/add_new_items.feature new file mode 100644 index 000000000..99497bbfc --- /dev/null +++ b/serenity-smoketests/src/test/resources/features/cucumber/add_new_items.feature @@ -0,0 +1,29 @@ +Feature: Add new items + + Scenario: Add items to an empty list + Given Toby starts with an empty list + When he adds "Buy some milk" to his list + Then the todo list should contain the following items: + | Buy some milk | + + Scenario: Add two items to an empty list + Given Toby starts with an empty list + When he adds "Buy some milk" to his list + And he adds "Buy some cheese" to his list + Then the todo list should contain the following items: + | Buy some milk | + | Buy some cheese | + + + Scenario Outline: Add different items to an empty list + Given Toby starts with an empty list + When he adds "" to his list + Then the todo list should contain the following items: + | | + Examples: + | task | + | Buy some milk | + | Buy some cheese | + | Buy some cereal | + | Buy some beef | + diff --git a/serenity-smoketests/src/test/resources/features/todomvc/add_new_items.feature b/serenity-smoketests/src/test/resources/features/todomvc/add_new_items.feature deleted file mode 100644 index 36acf817d..000000000 --- a/serenity-smoketests/src/test/resources/features/todomvc/add_new_items.feature +++ /dev/null @@ -1,7 +0,0 @@ -Feature: Add new items - - Scenario: Add items to an empty list - Given Toby starts with an empty list - When he adds "Buy some milk" to his list - Then the todo list should contain the following items: - | Buy some milk | \ No newline at end of file diff --git a/serenity-smoketests/src/test/resources/serenity.conf b/serenity-smoketests/src/test/resources/serenity.conf index 3fdf47909..0b0610f7c 100644 --- a/serenity-smoketests/src/test/resources/serenity.conf +++ b/serenity-smoketests/src/test/resources/serenity.conf @@ -9,7 +9,7 @@ headless.mode = true serenity { project.name = "Demo Project using Serenity and Cucumber" - test.root = "net.serenitybdd.demos.todos.screenplay.features" + test.root = "net.serenitybdd.demos.todos" tag.failures = "true" linked.tags = "issue" restart.browser.for.each = scenario