2
2
3
3
import static com .microsoft .playwright .assertions .PlaywrightAssertions .assertThat ;
4
4
5
+ import static io .github .tahanima .config .ConfigurationManager .config ;
6
+
7
+ import com .microsoft .playwright .Browser ;
8
+
5
9
import io .github .artsok .ParameterizedRepeatedIfExceptionsTest ;
6
10
import io .github .tahanima .annotation .DataSource ;
7
11
import io .github .tahanima .annotation .Smoke ;
13
17
14
18
import org .junit .jupiter .api .AfterEach ;
15
19
import org .junit .jupiter .api .BeforeEach ;
20
+ import org .junit .jupiter .api .TestInfo ;
21
+
22
+ import java .nio .file .Paths ;
16
23
17
24
/**
18
25
* @author tahanima
19
26
*/
20
27
@ Feature ("Login Test" )
21
28
public class LoginTest extends BaseTest {
22
29
23
- private static final String PATH = "login.csv" ;
30
+ private static final String CSV_PATH = "login.csv" ;
31
+ private static final String VIDEO_PATH = "login/" ;
24
32
25
33
@ BeforeEach
26
- public void createBrowserContextAndPageAndLoginPageInstances () {
27
- browserContext = browser .newContext ();
28
- page = browserContext .newPage ();
34
+ public void createBrowserContextAndPageAndLoginPageInstances (TestInfo testInfo ) {
35
+ String testMethodName =
36
+ (testInfo .getTestMethod ().isPresent ())
37
+ ? testInfo .getTestMethod ().get ().getName ()
38
+ : "" ;
39
+
40
+ if (config ().video ()) {
41
+ browserContext =
42
+ browser .newContext (
43
+ new Browser .NewContextOptions ()
44
+ .setRecordVideoDir (
45
+ Paths .get (
46
+ config ().baseTestVideoPath ()
47
+ + VIDEO_PATH
48
+ + testMethodName )));
49
+ } else {
50
+ browserContext = browser .newContext ();
51
+ }
29
52
53
+ page = browserContext .newPage ();
30
54
loginPage = createInstance (LoginPage .class );
31
55
}
32
56
@@ -46,7 +70,7 @@ public void closeBrowserContextSession() {
46
70
@ Description (
47
71
"Test that verifies user gets redirected to 'Products' page after submitting correct login credentials" )
48
72
@ ParameterizedRepeatedIfExceptionsTest
49
- @ DataSource (id = "TC-1" , fileName = PATH , clazz = LoginDto .class )
73
+ @ DataSource (id = "TC-1" , fileName = CSV_PATH , clazz = LoginDto .class )
50
74
public void testCorrectLoginCredentials (final LoginDto data ) {
51
75
ProductsPage productsPage = loginPage .loginAs (data .getUsername (), data .getPassword ());
52
76
@@ -59,7 +83,7 @@ public void testCorrectLoginCredentials(final LoginDto data) {
59
83
@ Description (
60
84
"Test that verifies user gets error message after submitting incorrect login credentials" )
61
85
@ ParameterizedRepeatedIfExceptionsTest
62
- @ DataSource (id = "TC-2" , fileName = PATH , clazz = LoginDto .class )
86
+ @ DataSource (id = "TC-2" , fileName = CSV_PATH , clazz = LoginDto .class )
63
87
public void testIncorrectLoginCredentials (final LoginDto data ) {
64
88
loginPage .loginAs (data .getUsername (), data .getPassword ());
65
89
@@ -72,7 +96,7 @@ public void testIncorrectLoginCredentials(final LoginDto data) {
72
96
@ Description (
73
97
"Test that verifies user gets error message after submitting login credentials where the username is blank" )
74
98
@ ParameterizedRepeatedIfExceptionsTest
75
- @ DataSource (id = "TC-3" , fileName = PATH , clazz = LoginDto .class )
99
+ @ DataSource (id = "TC-3" , fileName = CSV_PATH , clazz = LoginDto .class )
76
100
public void testBlankUserName (final LoginDto data ) {
77
101
loginPage .open ().typePassword (data .getPassword ()).submitLogin ();
78
102
@@ -85,7 +109,7 @@ public void testBlankUserName(final LoginDto data) {
85
109
@ Description (
86
110
"Test that verifies user gets error message after submitting login credentials where the password is blank" )
87
111
@ ParameterizedRepeatedIfExceptionsTest
88
- @ DataSource (id = "TC-4" , fileName = PATH , clazz = LoginDto .class )
112
+ @ DataSource (id = "TC-4" , fileName = CSV_PATH , clazz = LoginDto .class )
89
113
public void testBlankPassword (final LoginDto data ) {
90
114
loginPage .open ().typeUsername (data .getUsername ()).submitLogin ();
91
115
@@ -98,7 +122,7 @@ public void testBlankPassword(final LoginDto data) {
98
122
@ Description (
99
123
"Test that verifies user gets error message after submitting login credentials for locked out user" )
100
124
@ ParameterizedRepeatedIfExceptionsTest
101
- @ DataSource (id = "TC-5" , fileName = PATH , clazz = LoginDto .class )
125
+ @ DataSource (id = "TC-5" , fileName = CSV_PATH , clazz = LoginDto .class )
102
126
public void testLockedOutUser (final LoginDto data ) {
103
127
loginPage .loginAs (data .getUsername (), data .getPassword ());
104
128
0 commit comments