Skip to content

Commit

Permalink
Updated some smoketests
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 20, 2024
1 parent 7643efb commit c58deb0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
7 changes: 6 additions & 1 deletion serenity-smoketests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
<artifactId>serenity-junit5</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependency> <dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-ensure</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-browserstack</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;

import java.util.Arrays;
import java.util.List;

public class CompleteItems {
public static Performable called(List<String> itemNames) {
public static Performable called(String... itemNames) {
return Task.where("{0} completes the items called: " + itemNames,
actor -> {
itemNames.forEach(itemName -> actor.attemptsTo(
Arrays.asList(itemNames).forEach(itemName -> actor.attemptsTo(
Click.on(TodoListItem.COMPLETE_ITEM.of(itemName))
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@
import net.serenitybdd.junit5.SerenityJUnit5Extension;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.ensure.Ensure;
import org.junit.jupiter.api.BeforeEach;
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.screenplay.GivenWhenThen.*;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;

@ExtendWith(SerenityJUnit5Extension.class)
public class FilteringTodos {
Expand All @@ -38,43 +33,38 @@ public void jamesCanBrowseTheWeb() {
}

@ParameterizedTest
@CsvSource({
// initialTodos, itemsToComplete, filtersToApply, expectedDisplayedItems, expectedSelectedFilter
"Walk the dog;Put out the garbage, Walk the dog, Completed, Walk the dog, Completed",
"Walk the dog;Put out the garbage, Walk the dog, Active, Put out the garbage, 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 initialTodos,
String itemsToComplete,
String filterToApply,
String expectedDisplayedItems,
String expectedSelectedFilter
@CsvSource(delimiterString = "|", value = {
// initialTodos | itemsToComplete | filters | expectedDisplayedItems | selectedFilter
"Walk the dog;Put out the garbage | Walk the dog | Completed | Walk the dog | Completed",
"Walk the dog;Put out the garbage | Walk the dog | Active | Put out the garbage | Active",
"Walk the dog;Put out the garbage | Walk the dog | All | Walk the dog;Put out the garbage | All",
"Walk the dog | Walk the dog | Completed | | Completed"})
public void should_be_able_to_filter_todos(String initialTodos, String itemsToComplete, String filter,
String expectedDisplayedItems, String selectedFilter
) {
// Parse the CSV string parameters into lists
TodoStatusFilter expectedFilter = TodoStatusFilter.valueOf(expectedSelectedFilter);
TodoStatusFilter filterToApply = TodoStatusFilter.valueOf(filter);
TodoStatusFilter expectedFilter = TodoStatusFilter.valueOf(selectedFilter);

// Given
givenThat(james).wasAbleTo(Start.withATodoListContaining(asList(initialTodos)));
givenThat(james).wasAbleTo(
Start.withATodoListContaining(itemsIn(initialTodos))
);

// When
james.attemptsTo(
CompleteItems.called(asList(itemsToComplete)),
FilterItems.toShow(TodoStatusFilter.valueOf(filterToApply))
when(james).attemptsTo(
CompleteItems.called(itemsIn(itemsToComplete)),
FilterItems.toShow(filterToApply)
);

// Then
then(james).should(
seeThat(TheItems.displayed(), hasItems(expectedDisplayedItems)),
seeThat(CurrentFilter.selected(), is(expectedFilter))
then(james).attemptsTo(
Ensure.that(TheItems.displayed()).contains(itemsIn(expectedDisplayedItems)),
Ensure.that(CurrentFilter.selected()).isEqualTo(expectedFilter)
);
}

private List<String> asList(String str) {
if (str == null || str.trim().isEmpty()) {
return new ArrayList<>();
private String[] itemsIn(String listOfItems) {
if (listOfItems == null || listOfItems.trim().isEmpty()) {
return new String[]{};
}
return Arrays.asList(str.split(";"));
return listOfItems.split(";");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent

0 comments on commit c58deb0

Please sign in to comment.