Skip to content

Commit

Permalink
Updated to Serenitg 4.0.43
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jan 13, 2024
1 parent 7265e96 commit acfc326
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 107 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>4.0.30</serenity.version>
<serenity.version>4.0.43</serenity.version>
<encoding>UTF-8</encoding>
<serenity.test.root></serenity.test.root>
<tags></tags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String> items) {
actor.wasAbleTo(Start.withATodoListContaining(items));
}
Expand All @@ -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));
Expand All @@ -104,8 +129,11 @@ public void todo_list_should_contain(List<String> expectedItems) {

@Then("{actor}'s todo list should contain {items}")
public void a_users_todo_list_should_contain(Actor actor, List<String> 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)
);
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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<String> 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<Arguments> 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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>" task should be shown as <Final Status>
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tasks>
Given Jane has a todo list containing <tasks>
And she completes the task called "Walk the dog"
When she filters her list to show only <filter> tasks
Then her todo list should contain <expected>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/test/resources/serenity.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
Expand Down

0 comments on commit acfc326

Please sign in to comment.