-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathLoginTest.java
More file actions
131 lines (108 loc) · 4.98 KB
/
LoginTest.java
File metadata and controls
131 lines (108 loc) · 4.98 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package io.github.tahanima.e2e;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static io.github.tahanima.config.ConfigurationManager.config;
import com.microsoft.playwright.Browser;
import io.github.artsok.ParameterizedRepeatedIfExceptionsTest;
import io.github.tahanima.annotation.Smoke;
import io.github.tahanima.annotation.TestDataSource;
import io.github.tahanima.annotation.Validation;
import io.github.tahanima.testdata.LoginTestData;
import io.github.tahanima.ui.page.LoginPage;
import io.github.tahanima.ui.page.ProductsPage;
import io.qameta.allure.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import java.nio.file.Paths;
/**
* @author tahanima
*/
@Feature("Login Test")
public class LoginTest extends BaseTest {
private static final String CSV_PATH = "login.csv";
private static final String VIDEO_PATH = "login/";
@BeforeEach
public void setupEach(TestInfo testInfo) {
String testMethodName =
(testInfo.getTestMethod().isPresent())
? testInfo.getTestMethod().get().getName()
: "";
if (config().video()) {
browserContext =
browser.newContext(
new Browser.NewContextOptions()
.setRecordVideoDir(
Paths.get(
config().baseTestVideoPath()
+ VIDEO_PATH
+ testMethodName)));
} else {
browserContext = browser.newContext();
}
page = browserContext.newPage();
loginPage = createInstance(LoginPage.class);
}
@Attachment(value = "Failed Test Case Screenshot", type = "image/png")
protected byte[] captureScreenshotOnFailure() {
return loginPage.captureScreenshot();
}
@AfterEach
public void teardownEach() {
browserContext.close();
}
@Smoke
@Story("User enters correct login credentials")
@Owner("Tahanima Chowdhury")
@Description(
"Test that verifies user gets redirected to 'Products' page after submitting correct login credentials")
@ParameterizedRepeatedIfExceptionsTest
@TestDataSource(id = "TC-1", fileName = CSV_PATH, clazz = LoginTestData.class)
public void testCorrectLoginCredentials(LoginTestData testData) {
ProductsPage productsPage = loginPage.loginAs(testData.getUsername(), testData.getPassword());
assertThat(productsPage.getTitle()).hasText("Products");
}
@Validation
@Story("User enters incorrect login credentials")
@Owner("Tahanima Chowdhury")
@Description(
"Test that verifies user gets error message after submitting incorrect login credentials")
@ParameterizedRepeatedIfExceptionsTest
@TestDataSource(id = "TC-2", fileName = CSV_PATH, clazz = LoginTestData.class)
public void testIncorrectLoginCredentials(LoginTestData testData) {
loginPage.loginAs(testData.getUsername(), testData.getPassword());
assertThat(loginPage.getErrorMessage()).hasText(testData.getErrorMessage());
}
@Validation
@Story("User keeps the username blank")
@Owner("Tahanima Chowdhury")
@Description(
"Test that verifies user gets error message after submitting login credentials where the username is blank")
@ParameterizedRepeatedIfExceptionsTest
@TestDataSource(id = "TC-3", fileName = CSV_PATH, clazz = LoginTestData.class)
public void testBlankUserName(LoginTestData testData) {
loginPage.open().typePassword(testData.getPassword()).submitLogin();
assertThat(loginPage.getErrorMessage()).hasText(testData.getErrorMessage());
}
@Validation
@Story("User keeps the password blank")
@Owner("Tahanima Chowdhury")
@Description(
"Test that verifies user gets error message after submitting login credentials where the password is blank")
@ParameterizedRepeatedIfExceptionsTest
@TestDataSource(id = "TC-4", fileName = CSV_PATH, clazz = LoginTestData.class)
public void testBlankPassword(LoginTestData testData) {
loginPage.open().typeUsername(testData.getUsername()).submitLogin();
assertThat(loginPage.getErrorMessage()).hasText(testData.getErrorMessage());
}
@Validation
@Story("User is locked out")
@Owner("Tahanima Chowdhury")
@Description(
"Test that verifies user gets error message after submitting login credentials for locked out user")
@ParameterizedRepeatedIfExceptionsTest
@TestDataSource(id = "TC-5", fileName = CSV_PATH, clazz = LoginTestData.class)
public void testLockedOutUser(LoginTestData testData) {
loginPage.loginAs(testData.getUsername(), testData.getPassword());
assertThat(loginPage.getErrorMessage()).hasText(testData.getErrorMessage());
}
}