Skip to content

Commit cd4ab34

Browse files
Test variations in the todo filters (Active, Completed, All) using a single parameterized test
1 parent 36496ad commit cd4ab34

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
11
package todomvc.acceptancetests;
22

3+
import org.assertj.core.api.Assertions;
4+
import org.junit.jupiter.api.AfterEach;
5+
import org.junit.jupiter.api.BeforeEach;
36
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.CsvSource;
10+
import org.junit.jupiter.params.provider.MethodSource;
11+
import org.openqa.selenium.WebDriver;
12+
import org.openqa.selenium.chrome.ChromeDriver;
13+
import todomvc.pageactions.ToDoPage;
414

15+
import java.util.Arrays;
16+
import java.util.List;
17+
import java.util.stream.Stream;
18+
19+
/*
20+
* Write a data-driven test to test the following scenarios:
21+
When you add the items "Feed the cat" and "Walk the dog", and complete "Feed the cat", and then filter by "Completed", you should only see "Feed the cat"
22+
When you add the items "Feed the cat" and "Walk the dog", and complete "Feed the cat", and then filter by "Active", you should only see "Walk the dog"
23+
When you add the items "Feed the cat" and "Walk the dog", and complete "Feed the cat", and then filter by "All", you should all the items
24+
*
25+
* */
526
public class WhenFilteringTasks {
627

28+
private WebDriver driver;
29+
private ToDoPage toDoPage;
30+
31+
@BeforeEach
32+
public void setUp(){
33+
driver = new ChromeDriver();
34+
toDoPage = new ToDoPage(driver);
35+
}
36+
37+
@AfterEach
38+
public void tearDown(){
39+
driver.quit();
40+
}
41+
42+
@ParameterizedTest(name="Complete task: {0},Filter by {1}, See tasks: {2}")
43+
@MethodSource("testDataProvider")
44+
public void canFilterByTaskStatus(String toDoItemToComplete, String filterLinkText, List<String> expectedToDoItems){
45+
toDoPage.openToDoApp();
46+
toDoPage.addItemsCalled("Feed the cat", "Walk the dog");
47+
toDoPage.completeItemCalled(toDoItemToComplete);
48+
49+
toDoPage.filterBy(filterLinkText);
50+
51+
Assertions.assertThat(toDoPage.listOfTextsOfToDoItems()).isEqualTo(expectedToDoItems);
52+
}
53+
54+
/* Return a Stream of Arguments
55+
Each Argument is a container for a set of String arguments (like a row of data in a csv source with each cell representing one argument)
56+
Each String is consumed as a parameter on the receiving end (by the Test Method), row by row
57+
*/
58+
public static Stream<Arguments> testDataProvider(){
59+
return Stream.of(
60+
Arguments.of("Feed the cat", "Completed", Arrays.asList("Feed the cat") ),
61+
Arguments.of("Feed the cat", "Active", Arrays.asList("Walk the dog") ),
62+
Arguments.of("Feed the cat", "All", Arrays.asList("Feed the cat", "Walk the dog" ))
63+
);
64+
}
765
}

0 commit comments

Comments
 (0)