11package com .anhtester .keywords ;
22
3+ import com .anhtester .constants .AppConfig ;
4+ import com .anhtester .helpers .SystemHelper ;
35import com .anhtester .managers .PageManager ;
46import com .anhtester .reports .AllureManager ;
57import com .anhtester .reports .ExtentTestManager ;
68import com .anhtester .utils .LogUtils ;
79import com .aventstack .extentreports .Status ;
810import io .qameta .allure .Step ;
11+ import org .testng .asserts .SoftAssert ;
912
1013import java .awt .*;
1114import java .awt .event .KeyEvent ;
1215
1316public 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+ }
1734
1835 public static void sleep (double second ) {
1936 try {
@@ -24,13 +41,16 @@ public static void sleep(double second) {
2441 }
2542
2643 public static void maximizeBrowserOnWindow () {
44+ System .out .println (SystemHelper .getOperatingSystem ());
2745 Robot rb = null ;
2846 try {
2947 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+ }
3454 } catch (AWTException e ) {
3555 e .printStackTrace ();
3656 }
@@ -39,7 +59,7 @@ public static void maximizeBrowserOnWindow() {
3959 @ Step ("Navigate to URL: {0}" )
4060 public static void navigate (String url ) {
4161 PageManager .getPage ().navigate (url );
42- sleep ( STEP_TIME );
62+ PageManager . getPage (). waitForLoadState ( );
4363 LogUtils .info ("Navigate to URL: " + url );
4464 ExtentTestManager .logMessage (Status .INFO , "Navigate to URL: " + url );
4565 }
@@ -60,16 +80,50 @@ public static void fill(String locator, String value) {
6080 ExtentTestManager .logMessage (Status .INFO , "Fill text " + value + " on element " + locator );
6181 }
6282
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+
63107 @ Step ("Get text of element {0}" )
64108 public static String textContent (String locator ) {
65109 sleep (STEP_TIME );
66110 String text = PageManager .getPage ().locator (locator ).textContent ();
67111 LogUtils .info ("Get text of element " + locator + " ==> " + text );
68112 ExtentTestManager .logMessage (Status .INFO , "Get text of element " + locator );
69113 ExtentTestManager .logMessage (Status .INFO , "==> Text: " + text );
70-
71114 AllureManager .saveTextLog ("==> " + text );
115+ return text ;
116+ }
72117
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 );
73126 return text ;
74127 }
128+
75129}
0 commit comments