-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathLoginTest.java
131 lines (108 loc) · 4.92 KB
/
LoginTest.java
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.DataSource;
import io.github.tahanima.annotation.Smoke;
import io.github.tahanima.annotation.Validation;
import io.github.tahanima.dto.LoginDto;
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 createBrowserContextAndPageAndLoginPageInstances(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 closeBrowserContextSession() {
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
@DataSource(id = "TC-1", fileName = CSV_PATH, clazz = LoginDto.class)
public void testCorrectLoginCredentials(final LoginDto data) {
ProductsPage productsPage = loginPage.loginAs(data.getUsername(), data.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
@DataSource(id = "TC-2", fileName = CSV_PATH, clazz = LoginDto.class)
public void testIncorrectLoginCredentials(final LoginDto data) {
loginPage.loginAs(data.getUsername(), data.getPassword());
assertThat(loginPage.getErrorMessage()).hasText(data.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
@DataSource(id = "TC-3", fileName = CSV_PATH, clazz = LoginDto.class)
public void testBlankUserName(final LoginDto data) {
loginPage.open().typePassword(data.getPassword()).submitLogin();
assertThat(loginPage.getErrorMessage()).hasText(data.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
@DataSource(id = "TC-4", fileName = CSV_PATH, clazz = LoginDto.class)
public void testBlankPassword(final LoginDto data) {
loginPage.open().typeUsername(data.getUsername()).submitLogin();
assertThat(loginPage.getErrorMessage()).hasText(data.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
@DataSource(id = "TC-5", fileName = CSV_PATH, clazz = LoginDto.class)
public void testLockedOutUser(final LoginDto data) {
loginPage.loginAs(data.getUsername(), data.getPassword());
assertThat(loginPage.getErrorMessage()).hasText(data.getErrorMessage());
}
}