diff --git a/pom.xml b/pom.xml index 2c24f2ee..df9bf338 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ UTF-8 - 4.0.30 + 4.0.43 UTF-8 diff --git a/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItem.java b/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItem.java index 4efecd90..cc127bc0 100644 --- a/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItem.java +++ b/src/main/java/net/serenitybdd/demos/todos/screenplay/tasks/CompleteItem.java @@ -7,7 +7,7 @@ public class CompleteItem { public static Performable called(String item) { - return Task.where("{0} completes the item called" + item, + return Task.where("{0} completes the item called " + item, Click.on(TodoListItem.COMPLETE_ITEM.of(item)) ); } diff --git a/src/test/java/net/serenitybdd/demos/todos/cucumber/CucumberTestSuite.java b/src/test/java/net/serenitybdd/demos/todos/cucumber/CucumberTestSuite.java index f0e3f4e8..b0196326 100644 --- a/src/test/java/net/serenitybdd/demos/todos/cucumber/CucumberTestSuite.java +++ b/src/test/java/net/serenitybdd/demos/todos/cucumber/CucumberTestSuite.java @@ -5,14 +5,12 @@ import org.junit.platform.suite.api.SelectClasspathResource; import org.junit.platform.suite.api.Suite; -import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; -import static io.cucumber.junit.platform.engine.Constants.FILTER_TAGS_PROPERTY_NAME; +import static io.cucumber.junit.platform.engine.Constants.*; @Suite @IncludeEngines("cucumber") @SelectClasspathResource("/features") -//@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@current") -@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, - value = "io.cucumber.core.plugin.SerenityReporterParallel,pretty,timeline:target/test-results/timeline") +@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "net.serenitybdd.demos.todos.cucumber.steps") +@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "not @ignore") public class CucumberTestSuite { } diff --git a/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/BrowserCustomisation.java b/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/BrowserCustomisation.java deleted file mode 100644 index 2386e77b..00000000 --- a/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/BrowserCustomisation.java +++ /dev/null @@ -1,2 +0,0 @@ -package net.serenitybdd.demos.todos.cucumber.steps;public class BrowserCustomisation { -} diff --git a/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/TodoUserSteps.java b/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/TodoUserSteps.java index c6fd9050..5a4997c8 100644 --- a/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/TodoUserSteps.java +++ b/src/test/java/net/serenitybdd/demos/todos/cucumber/steps/TodoUserSteps.java @@ -10,22 +10,27 @@ import io.cucumber.java.en.When; import net.serenitybdd.core.annotations.events.AfterExample; import net.serenitybdd.demos.todos.cucumber.MissingTodoItemsException; +import net.serenitybdd.demos.todos.screenplay.model.TodoStatus; import net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter; +import net.serenitybdd.demos.todos.screenplay.questions.TheItemStatus; import net.serenitybdd.demos.todos.screenplay.questions.TheItems; import net.serenitybdd.demos.todos.screenplay.tasks.*; import net.serenitybdd.model.buildinfo.BuildInfo; import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.actors.OnStage; import net.serenitybdd.screenplay.actors.OnlineCast; +import net.serenitybdd.screenplay.ensure.Ensure; +import net.serenitybdd.screenplay.waits.Wait; import java.util.List; import static java.util.Collections.EMPTY_LIST; +import static net.serenitybdd.demos.todos.screenplay.model.TodoStatus.Completed; import static net.serenitybdd.screenplay.GivenWhenThen.seeThat; import static net.serenitybdd.screenplay.actors.OnStage.setTheStage; import static net.serenitybdd.screenplay.actors.OnStage.theActorInTheSpotlight; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItem; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.*; public class TodoUserSteps { @@ -70,7 +75,7 @@ public void that_James_has_an_empty_todo_list(Actor actor) { actor.wasAbleTo(Start.withAnEmptyTodoList()); } - @Given("that {actor} has a todo list containing {items}") + @Given("{actor} has a todo list containing {items}") public void that_James_has_an_empty_todo_list(Actor actor, List items) { actor.wasAbleTo(Start.withATodoListContaining(items)); } @@ -80,6 +85,26 @@ public void completesTask(Actor actor, String item) { actor.attemptsTo(CompleteItem.called(item)); } + @Then("{actor} remaining todo count should be {int}") + public void checkRemainingTodoCount(Actor actor, int count) { + actor.attemptsTo(Ensure.that(TheItems.leftCount()).isEqualTo(count)); + + // ALTERNATIVE VERSION: + int itemCount = actor.asksFor(TheItems.leftCount()); + assertThat(itemCount).isEqualTo(count); + } + + @Then("the {string} task should be shown as {}") + public void checkRemainingTodoCount(String taskName, TodoStatus status) { + theActorInTheSpotlight().attemptsTo( + Ensure.that(TheItemStatus.forTheItemCalled(taskName)).isEqualTo(status) + ); + + // ALTERNATIVE VERSION: + TodoStatus currentStatus = theActorInTheSpotlight().asksFor(TheItemStatus.forTheItemCalled(taskName)); + assertThat(currentStatus).isEqualTo(status); + } + @When("{actor} adds {string} to his/her list") public void adds_to_his_list(Actor actor, String item) { actor.attemptsTo(AddATodoItem.called(item)); @@ -104,8 +129,11 @@ public void todo_list_should_contain(List expectedItems) { @Then("{actor}'s todo list should contain {items}") public void a_users_todo_list_should_contain(Actor actor, List expectedItems) { - actor.should(seeThat(TheItems.displayed(), equalTo(expectedItems)) - .orComplainWith(MissingTodoItemsException.class, "Missing todos " + expectedItems)); + actor.attemptsTo( + Wait.until(TheItems.displayed(), is(not(empty()))), + Ensure.that(TheItems.displayed()).containsElementsFrom(expectedItems) + .withReportedError("Missing todos " + expectedItems) + ); } diff --git a/src/test/java/net/serenitybdd/demos/todos/screenplay/completing_todos/DownloadTheApp.java b/src/test/java/net/serenitybdd/demos/todos/screenplay/completing_todos/DownloadTheApp.java deleted file mode 100644 index d71ff76e..00000000 --- a/src/test/java/net/serenitybdd/demos/todos/screenplay/completing_todos/DownloadTheApp.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.serenitybdd.demos.todos.screenplay.completing_todos; - -import net.serenitybdd.annotations.Managed; -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.junit5.SerenityJUnit5Extension; -import net.serenitybdd.screenplay.Actor; -import net.serenitybdd.screenplay.abilities.BrowseTheWeb; -import net.serenitybdd.screenplay.actions.Click; -import net.serenitybdd.screenplay.actions.Open; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; - -import java.util.List; - -import static net.serenitybdd.screenplay.GivenWhenThen.*; -import static org.hamcrest.CoreMatchers.is; - -@ExtendWith(SerenityJUnit5Extension.class) -@Tag("Screenplay") -public class DownloadTheApp { - - private Actor james = Actor.named("James"); - - @Managed//(driver = "chrome", options = "--headless") - private WebDriver hisBrowser; - - @BeforeEach - public void jamesCanBrowseTheWeb() { - james.can(BrowseTheWeb.with(hisBrowser)); - } - - @Test - public void should_be_able_to_download_the_application() { - - givenThat(james).wasAbleTo(Open.url("http://todomvc.com/")); - - List dl; - - when(james).attemptsTo( - Click.on(By.linkText("Download")) - ); - - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - - } - - @Test - 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")); - - when(james).attemptsTo( - CompleteItem.called("Walk the dog") - ); - - then(james).should(seeThat(TheItems.leftCount(), is(1))); - } -} diff --git a/src/test/java/net/serenitybdd/demos/todos/screenplay/maintain_my_todo_list/FilteringTodos.java b/src/test/java/net/serenitybdd/demos/todos/screenplay/maintain_my_todo_list/FilteringTodos.java index 1d4d69d1..eca9bc1b 100644 --- a/src/test/java/net/serenitybdd/demos/todos/screenplay/maintain_my_todo_list/FilteringTodos.java +++ b/src/test/java/net/serenitybdd/demos/todos/screenplay/maintain_my_todo_list/FilteringTodos.java @@ -1,6 +1,7 @@ package net.serenitybdd.demos.todos.screenplay.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; @@ -13,8 +14,16 @@ import org.junit.jupiter.api.Tag; 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.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.openqa.selenium.WebDriver; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +import static java.util.Arrays.asList; import static net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter.*; import static net.serenitybdd.screenplay.GivenWhenThen.*; import static org.hamcrest.Matchers.*; @@ -60,18 +69,29 @@ public void should_be_able_to_view_only_incomplete_todos() { and(james).should(seeThat(CurrentFilter.selected(), is(Active))); } - @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")); + @ParameterizedTest + @MethodSource("todoTestData") + public void should_be_able_to_view_various_todo_combinations(String completeItem, + String incompleteItem, + TodoStatusFilter filterOption, + List filteredItems) { + givenThat(james).wasAbleTo(Start.withATodoListContaining(completeItem, incompleteItem)); when(james).attemptsTo( - CompleteItem.called("Walk the dog"), - FilterItems.toShow(Active), - FilterItems.toShow(All) + CompleteItem.called(completeItem), + FilterItems.toShow(filterOption) ); - then(james).should(seeThat(TheItems.displayed(), contains("Walk the dog", "Put out the garbage"))); - and(james).should(seeThat(CurrentFilter.selected(), is(All))); + then(james).should(seeThat(TheItems.displayed(), contains(filteredItems.toArray(new String[]{})))); + and(james).should(seeThat(CurrentFilter.selected(), is(filterOption))); + } + + private static Stream todoTestData() { + return Stream.of( + Arguments.of("Walk the dog", "Put out the garbage", All, asList("Walk the dog", "Put out the garbage")), + Arguments.of("Walk the dog", "Put out the garbage", Active, asList("Put out the garbage")), + Arguments.of("Walk the dog", "Put out the garbage", Completed, asList("Walk the dog")) + // Add more combinations of items and filter options here + ); } } diff --git a/src/test/resources/features/cucumber/maintain_my_todo_list/completing_todos.feature b/src/test/resources/features/cucumber/maintain_my_todo_list/completing_todos.feature index b249d9fa..feb49fe1 100644 --- a/src/test/resources/features/cucumber/maintain_my_todo_list/completing_todos.feature +++ b/src/test/resources/features/cucumber/maintain_my_todo_list/completing_todos.feature @@ -6,13 +6,34 @@ Feature: Completing todos As a forgetful person I want to be to _view all of things I have completed_ - Scenario: Mark a task as completed - Given that Jane has a todo list containing Buy some milk, Walk the dog + Scenario: When a task is completed it remains in the main list + Given Jane has a todo list containing Buy some milk, Walk the dog + When she completes the task called "Walk the dog" + Then her todo list should contain Buy some milk, Walk the dog + But the "Walk the dog" task should be shown as Completed + + Scenario: Completed tasks should appear in the Completed list + Given Jane has a todo list containing Buy some milk, Walk the dog When she completes the task called "Walk the dog" And she filters her list to show only Completed tasks Then her todo list should contain Walk the dog - Scenario: List of completed items should be empty if nothing has been completed - Given that Jane has a todo list containing Buy some milk, Walk the dog + Scenario Outline: Completed tasks should be shown as Completed + Given Jane has a todo list containing Buy some milk, Walk the dog + When she completes the task called "Walk the dog" + Then the "" task should be shown as + Examples: + | Task | Final Status | + | Walk the dog | Completed | + | Buy some milk | Active | + + Scenario: The list of completed items should be empty if nothing has been completed + Given Jane has a todo list containing Buy some milk, Walk the dog When she filters her list to show only Completed tasks Then her todo list should be empty + + Scenario: The todo count should keep track of how many todos remain + Given Jane has a todo list containing Buy some milk, Walk the dog + Then her remaining todo count should be 2 + When she completes the task called "Walk the dog" + Then her remaining todo count should be 1 diff --git a/src/test/resources/features/cucumber/maintain_my_todo_list/deleting_todos.feature b/src/test/resources/features/cucumber/maintain_my_todo_list/deleting_todos.feature index 86c616a7..c16c6a14 100644 --- a/src/test/resources/features/cucumber/maintain_my_todo_list/deleting_todos.feature +++ b/src/test/resources/features/cucumber/maintain_my_todo_list/deleting_todos.feature @@ -7,12 +7,12 @@ Feature: Deleting todos I want to be to delete the tasks once I am done with them Scenario: Delete an active item - Given that Jane has a todo list containing Buy some milk, Walk the dog + Given Jane has a todo list containing Buy some milk, Walk the dog When she deletes the task called 'Walk the dog' Then her todo list should contain Buy some milk Scenario: Delete all the items - Given that Jane has a todo list containing Buy some milk, Walk the dog + Given Jane has a todo list containing Buy some milk, Walk the dog When she deletes the task called 'Walk the dog' And she deletes the task called 'Buy some milk' Then her todo list should be empty diff --git a/src/test/resources/features/cucumber/maintain_my_todo_list/filtering_todos.feature b/src/test/resources/features/cucumber/maintain_my_todo_list/filtering_todos.feature index a7dcea7a..56697674 100644 --- a/src/test/resources/features/cucumber/maintain_my_todo_list/filtering_todos.feature +++ b/src/test/resources/features/cucumber/maintain_my_todo_list/filtering_todos.feature @@ -7,7 +7,7 @@ Feature: Filtering todos I want to be to view all of things I have completed Scenario Outline: Viewing the items by status - Given that Jane has a todo list containing + Given Jane has a todo list containing And she completes the task called "Walk the dog" When she filters her list to show only tasks Then her todo list should contain diff --git a/src/test/resources/features/cucumber/record_todos/add_new_items_to_the_todo_list.feature b/src/test/resources/features/cucumber/record_todos/add_new_items_to_the_todo_list.feature index 2ee097ae..be2b14ae 100644 --- a/src/test/resources/features/cucumber/record_todos/add_new_items_to_the_todo_list.feature +++ b/src/test/resources/features/cucumber/record_todos/add_new_items_to_the_todo_list.feature @@ -6,19 +6,19 @@ Feature: Add new todos As a forgetful person I want to be able to record what I need to do in a place where I won't forget about them - Scenario: Adding an item to an empty list in Cucumber + Scenario: Adding an item to an empty list Given that James has an empty todo list When he adds 'Buy some milk' to his list Then 'Buy some milk' should be recorded in his list - Scenario: Adding an item to a list with other items in Cucumber - Given that Jane has a todo list containing Buy some milk, Walk the dog + Scenario: Adding an item to a list with other items + Given Jane has a todo list containing Buy some milk, Walk the dog When she adds 'Buy some cereal' to her list Then her todo list should contain Buy some milk, Walk the dog, Buy some cereal - Scenario: Adding items to several peoples lists in Cucumber - Given that James has a todo list containing Buy some milk, Walk the dog - And that Jill has a todo list containing Buy some milk, Buy some cheese + Scenario: Adding items to several peoples lists + Given James has a todo list containing Buy some milk, Walk the dog + And Jill has a todo list containing Buy some milk, Buy some cheese When she adds 'Buy some cereal' to her list Then Jill's todo list should contain Buy some milk, Buy some cheese, Buy some cereal And James's todo list should contain Buy some milk, Walk the dog diff --git a/src/test/resources/serenity.conf b/src/test/resources/serenity.conf index cc2db22e..a59051da 100644 --- a/src/test/resources/serenity.conf +++ b/src/test/resources/serenity.conf @@ -51,7 +51,7 @@ environments { browserName = "chrome" acceptInsecureCerts = true "goog:chromeOptions" { - args = ["test-type", "ignore-certificate-errors", "headless", "--window-size=1000,800" + args = ["test-type", "ignore-certificate-errors", "--window-size=1000,800", "headless" "incognito", "disable-infobars", "disable-gpu", "disable-default-apps", "disable-popup-blocking"] } }