Repository navigation
Expand file tree
/
Copy pathSystemUsersTest.java
More file actions
112 lines (96 loc) · 4.81 KB
/
Copy pathSystemUsersTest.java
File metadata and controls
112 lines (96 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Package of the test classes
package com.automation.selenium.tests;
// TestNG assertions: each fails the test with the given message when the check is false
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
// Column values come back as lists
import java.util.List;
// Marks a method (or every public method of a class) as a TestNG test
import org.testng.annotations.Test;
// Base class: starts a browser before each test and closes it afterwards
import com.automation.selenium.base.BaseTest;
// Page object of Admin → System Users
import com.automation.selenium.pages.SystemUsersPage;
/**
* Admin → System Users: searching and filtering the user list. The demo site
* is shared, so the checks never depend on how many users exist, only on
* every listed user matching the filters.
*/
// Every test in this class belongs to the "admin" group (run only these with -Dgroups=admin)
@Test(groups = "admin")
public class SystemUsersTest extends BaseTest {
// Placeholder the drop-down filters show when nothing is chosen
private static final String NOTHING_CHOSEN = "-- Select --";
/**
* Opens Admin from the side menu and checks the title and that users are listed.
*/
// groups = "smoke" is added to the class group, so this test is in both "admin" and "smoke"
@Test(groups = "smoke", description = "[TC-111] System Users page opens from the Admin menu")
public void tc111_systemUsersPageOpensFromMenu() {
// Log in, then click Admin in the side menu
SystemUsersPage users = loginAsAdmin().openAdmin();
// The header shows the module name "Admin"
assertEquals(users.moduleTitle(), "Admin", "Module title");
// At least one user is listed (Admin always exists)
assertFalse(users.usernames().isEmpty(), "The user list should not be empty");
}
/**
* Searches for user name "Admin" and checks that every listed user is Admin.
*/
@Test(description = "[TC-112] Filtering by username lists only that user")
public void tc112_filterByUsername() {
// Log in, open Admin, type "Admin" into the Username filter, press Search (methods are chained)
SystemUsersPage users = loginAsAdmin().openAdmin().filterByUsername("Admin").search();
// Read the Username column of the results
List<String> usernames = users.usernames();
// Something must be found...
assertFalse(usernames.isEmpty(), "User 'Admin' should be found");
// ...and every row must be "Admin" ("Admin"::equals is short for name -> "Admin".equals(name))
assertTrue(usernames.stream().allMatch("Admin"::equals), "Only 'Admin' should be listed, got " + usernames);
}
/**
* Searches for enabled admins and checks the role and status of every listed user.
*/
@Test(description = "[TC-113] Filtering by role and status lists only matching users")
public void tc113_filterByRoleAndStatus() {
// Choose User Role = Admin and Status = Enabled in the drop-downs, then Search
SystemUsersPage users = loginAsAdmin().openAdmin().filterByRole("Admin").filterByStatus("Enabled").search();
// Read the User Role and Status columns
List<String> roles = users.roles();
List<String> statuses = users.statuses();
// At least one enabled admin exists (the Admin user itself)
assertFalse(roles.isEmpty(), "At least one enabled admin should be found");
// Every row has role Admin...
assertTrue(roles.stream().allMatch("Admin"::equals), "Only admins should be listed, got " + roles);
// ...and status Enabled
assertTrue(statuses.stream().allMatch("Enabled"::equals), "Only enabled users should be listed, got " + statuses);
}
/**
* Searches for a user name that does not exist and checks the empty result.
*/
@Test(description = "[TC-114] Searching for an unknown username finds no records")
public void tc114_unknownUsernameFindsNoRecords() {
// Search for a name nobody has
SystemUsersPage users = loginAsAdmin().openAdmin().filterByUsername("no.such.user.42").search();
// The text above the table says so
assertEquals(users.recordCount(), "No Records Found", "Record count");
// And the table has no rows
assertTrue(users.usernames().isEmpty(), "The table should be empty");
}
/**
* Sets all three filters, presses Reset and checks that every filter is empty again.
*/
@Test(description = "[TC-115] Reset clears every filter")
public void tc115_resetClearsFilters() {
// Fill all three filters, then press Reset (no search needed)
SystemUsersPage users = loginAsAdmin().openAdmin()
.filterByUsername("Admin").filterByRole("Admin").filterByStatus("Enabled")
.reset();
// Text box is empty again
assertEquals(users.usernameFilter(), "", "Username filter");
// Both drop-downs show the "-- Select --" placeholder again
assertEquals(users.roleFilter(), NOTHING_CHOSEN, "User Role filter");
assertEquals(users.statusFilter(), NOTHING_CHOSEN, "Status filter");
}
}