1
1
package com .anhtester .keywords ;
2
2
3
+ import com .anhtester .constants .AppConfig ;
4
+ import com .anhtester .helpers .SystemHelper ;
3
5
import com .anhtester .managers .PageManager ;
4
6
import com .anhtester .reports .AllureManager ;
5
7
import com .anhtester .reports .ExtentTestManager ;
6
8
import com .anhtester .utils .LogUtils ;
7
9
import com .aventstack .extentreports .Status ;
8
10
import io .qameta .allure .Step ;
11
+ import org .testng .asserts .SoftAssert ;
9
12
10
13
import java .awt .*;
11
14
import java .awt .event .KeyEvent ;
12
15
13
16
public class WebKeyword {
14
- private static int TIMEOUT = 10 ;
15
- private static double STEP_TIME = 0 ;
16
- private static int PAGE_LOAD_TIMEOUT = 20 ;
17
+
18
+ private static SoftAssert softAssert ;
19
+
20
+ private static double STEP_TIME = AppConfig .TIMEOUT_STEP ;
21
+
22
+ public static SoftAssert getSoftAssert () {
23
+ if (softAssert == null ) {
24
+ softAssert = new SoftAssert ();
25
+ }
26
+ return softAssert ;
27
+ }
28
+
29
+ public static void closeSoftAssert () {
30
+ if (softAssert != null ) {
31
+ softAssert .assertAll ();
32
+ }
33
+ }
17
34
18
35
public static void sleep (double second ) {
19
36
try {
@@ -24,13 +41,16 @@ public static void sleep(double second) {
24
41
}
25
42
26
43
public static void maximizeBrowserOnWindow () {
44
+ System .out .println (SystemHelper .getOperatingSystem ());
27
45
Robot rb = null ;
28
46
try {
29
47
rb = new Robot ();
30
- rb .keyPress (KeyEvent .VK_WINDOWS );
31
- rb .keyPress (KeyEvent .VK_UP );
32
- rb .keyRelease (KeyEvent .VK_UP );
33
- rb .keyRelease (KeyEvent .VK_WINDOWS );
48
+ if (SystemHelper .getOperatingSystem ().toLowerCase ().contains ("window" )) {
49
+ rb .keyPress (KeyEvent .VK_WINDOWS );
50
+ rb .keyPress (KeyEvent .VK_UP );
51
+ rb .keyRelease (KeyEvent .VK_UP );
52
+ rb .keyRelease (KeyEvent .VK_WINDOWS );
53
+ }
34
54
} catch (AWTException e ) {
35
55
e .printStackTrace ();
36
56
}
@@ -39,7 +59,7 @@ public static void maximizeBrowserOnWindow() {
39
59
@ Step ("Navigate to URL: {0}" )
40
60
public static void navigate (String url ) {
41
61
PageManager .getPage ().navigate (url );
42
- sleep ( STEP_TIME );
62
+ PageManager . getPage (). waitForLoadState ( );
43
63
LogUtils .info ("Navigate to URL: " + url );
44
64
ExtentTestManager .logMessage (Status .INFO , "Navigate to URL: " + url );
45
65
}
@@ -60,16 +80,50 @@ public static void fill(String locator, String value) {
60
80
ExtentTestManager .logMessage (Status .INFO , "Fill text " + value + " on element " + locator );
61
81
}
62
82
83
+ @ Step ("Get attribute {1} of element {0}" )
84
+ public static void getAttribute (String locator , String attributeName ) {
85
+ sleep (STEP_TIME );
86
+ String text = PageManager .getPage ().locator (locator ).getAttribute (attributeName );
87
+ LogUtils .info ("Get attribute " + attributeName + " of element " + locator );
88
+ ExtentTestManager .logMessage (Status .INFO , "Get attribute " + attributeName + " of element " + locator );
89
+ }
90
+
91
+ @ Step ("Clear text in element {0}" )
92
+ public static void clear (String locator ) {
93
+ sleep (STEP_TIME );
94
+ PageManager .getPage ().locator (locator ).clear ();
95
+ LogUtils .info ("Clear text in element " + locator );
96
+ ExtentTestManager .logMessage (Status .INFO , "Clear text in element " + locator );
97
+ }
98
+
99
+ @ Step ("High light element {0}" )
100
+ public static void highlight (String locator ) {
101
+ sleep (STEP_TIME );
102
+ PageManager .getPage ().locator (locator ).highlight ();
103
+ LogUtils .info ("High light element " + locator );
104
+ ExtentTestManager .logMessage (Status .INFO , "High light element " + locator );
105
+ }
106
+
63
107
@ Step ("Get text of element {0}" )
64
108
public static String textContent (String locator ) {
65
109
sleep (STEP_TIME );
66
110
String text = PageManager .getPage ().locator (locator ).textContent ();
67
111
LogUtils .info ("Get text of element " + locator + " ==> " + text );
68
112
ExtentTestManager .logMessage (Status .INFO , "Get text of element " + locator );
69
113
ExtentTestManager .logMessage (Status .INFO , "==> Text: " + text );
70
-
71
114
AllureManager .saveTextLog ("==> " + text );
115
+ return text ;
116
+ }
72
117
118
+ @ Step ("Get text of element {0}" )
119
+ public static String innerText (String locator ) {
120
+ sleep (STEP_TIME );
121
+ String text = PageManager .getPage ().locator (locator ).innerText ();
122
+ LogUtils .info ("Get text of element " + locator + " ==> " + text );
123
+ ExtentTestManager .logMessage (Status .INFO , "Get text of element " + locator );
124
+ ExtentTestManager .logMessage (Status .INFO , "==> Text: " + text );
125
+ AllureManager .saveTextLog ("==> " + text );
73
126
return text ;
74
127
}
128
+
75
129
}
0 commit comments