Skip to content

Commit

Permalink
Added Cucumber and JUnit 5 tests to the smoketests
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 20, 2024
1 parent bdd7641 commit e3da38c
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion serenity-smoketests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<browserstack.browser></browserstack.browser>
<browserstack.version></browserstack.version>
<junit-jupiter.version>5.11.2</junit-jupiter.version>
<junit-platform-suite-api.version>1.11.1</junit-platform-suite-api.version>
<junit-platform-suite-api.version>1.11.2</junit-platform-suite-api.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -148,6 +148,9 @@
<configuration>
<source>11</source>
<target>11</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> itemNames) {
return Task.where("{0} completes the items called: " + itemNames,
actor -> {
itemNames.forEach(itemName -> actor.attemptsTo(
Click.on(TodoListItem.COMPLETE_ITEM.of(itemName))
));
}
);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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;
import net.serenitybdd.annotations.Managed;
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;
Expand All @@ -18,7 +17,6 @@
@WithTag("version:RELEASE-2"),
@WithTag("smoke"),
})

public class CompleteATodo {

@Managed(uniqueSession = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -23,19 +22,15 @@
/**
* 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");

@Managed
private WebDriver hisBrowser;

@Before
@BeforeEach
public void jamesCanBrowseTheWeb() {
james.can(BrowseTheWeb.with(hisBrowser));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,61 @@
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");

@Managed
private WebDriver hisBrowser;

@Before public void jamesCanBrowseTheWeb() {
@BeforeEach
public void jamesCanBrowseTheWeb() {
james.can(BrowseTheWeb.with(hisBrowser));
}

@Test
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))
);
}

@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")
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)));
Expand Down
Loading

0 comments on commit e3da38c

Please sign in to comment.