Skip to content

Commit 12d2fcb

Browse files
committed
Update test cases
1 parent 997c6e1 commit 12d2fcb

28 files changed

+480
-220
lines changed

.gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
target/
2+
out/
3+
bin/
4+
.vs/
25
pom.xml.tag
36
pom.xml.releaseBackup
47
pom.xml.versionsBackup
@@ -11,6 +14,6 @@ buildNumber.properties
1114
.mvn/wrapper/maven-wrapper.jar
1215
*.zip
1316
.idea/
14-
report/
1517
logs/
16-
*.iml
18+
exports/
19+
*.iml

pom.xml

+14-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.anhtester</groupId>
88
<artifactId>PlaywrightJava</artifactId>
9-
<version>1.44.0</version>
9+
<version>1.45.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>17</maven.compiler.source>
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>com.microsoft.playwright</groupId>
2121
<artifactId>playwright</artifactId>
22-
<version>1.44.0</version>
22+
<version>1.45.0</version>
2323
</dependency>
2424

2525
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
@@ -40,21 +40,21 @@
4040
<dependency>
4141
<groupId>org.slf4j</groupId>
4242
<artifactId>slf4j-simple</artifactId>
43-
<version>2.0.11</version>
43+
<version>2.0.13</version>
4444
</dependency>
4545

4646
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
4747
<dependency>
4848
<groupId>org.apache.poi</groupId>
4949
<artifactId>poi</artifactId>
50-
<version>5.2.5</version>
50+
<version>5.3.0</version>
5151
</dependency>
5252

5353
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
5454
<dependency>
5555
<groupId>org.apache.poi</groupId>
5656
<artifactId>poi-ooxml</artifactId>
57-
<version>5.2.5</version>
57+
<version>5.3.0</version>
5858
</dependency>
5959

6060
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
@@ -89,21 +89,21 @@
8989
<dependency>
9090
<groupId>com.aventstack</groupId>
9191
<artifactId>extentreports</artifactId>
92-
<version>5.1.1</version>
92+
<version>5.1.2</version>
9393
</dependency>
9494

9595
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
9696
<dependency>
9797
<groupId>io.qameta.allure</groupId>
9898
<artifactId>allure-testng</artifactId>
99-
<version>2.27.0</version>
99+
<version>2.28.0</version>
100100
</dependency>
101101

102102
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-attachments -->
103103
<dependency>
104104
<groupId>io.qameta.allure</groupId>
105105
<artifactId>allure-attachments</artifactId>
106-
<version>2.27.0</version>
106+
<version>2.28.0</version>
107107
</dependency>
108108

109109
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
@@ -117,15 +117,15 @@
117117
<dependency>
118118
<groupId>org.projectlombok</groupId>
119119
<artifactId>lombok</artifactId>
120-
<version>1.18.32</version>
120+
<version>1.18.34</version>
121121
<scope>provided</scope>
122122
</dependency>
123123

124124
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
125125
<dependency>
126126
<groupId>com.google.guava</groupId>
127127
<artifactId>guava</artifactId>
128-
<version>33.2.0-jre</version>
128+
<version>33.2.1-jre</version>
129129
</dependency>
130130

131131
</dependencies>
@@ -135,7 +135,7 @@
135135
<plugin>
136136
<groupId>org.apache.maven.plugins</groupId>
137137
<artifactId>maven-compiler-plugin</artifactId>
138-
<version>3.12.1</version>
138+
<version>3.13.0</version>
139139
</plugin>
140140

141141
<plugin>
@@ -144,13 +144,14 @@
144144
<version>3.2.5</version>
145145
<configuration>
146146
<suiteXmlFiles>
147-
<suiteXmlFile>suites/SuiteAll.xml</suiteXmlFile>
147+
<suiteXmlFile>src/test/resources/suites/SuiteAll.xml</suiteXmlFile>
148148
</suiteXmlFiles>
149149

150150
<argLine>
151-
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.21/aspectjweaver-1.9.21.jar"
151+
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.22.1/aspectjweaver-1.9.22.1.jar"
152152
</argLine>
153153
<testFailureIgnore>true</testFailureIgnore>
154+
<skipTests>false</skipTests>
154155
<systemPropertyVariables>
155156
<allure.results.directory>target/allure-results</allure.results.directory>
156157
</systemPropertyVariables>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package com.anhtester.constants;
22

3+
import com.anhtester.helpers.PropertiesHelper;
4+
35
public class AppConfig {
4-
public static final boolean HEADLESS = false;
6+
public static boolean HEADLESS = Boolean.parseBoolean(PropertiesHelper.getValue("HEADLESS"));
7+
public static String URL = PropertiesHelper.getValue("URL");
8+
public static String BROWSER = PropertiesHelper.getValue("BROWSER");
9+
public static int VIEWPORT_WIDTH = Integer.parseInt(PropertiesHelper.getValue("VIEWPORT_WIDTH"));
10+
public static int VIEWPORT_HEIGHT = Integer.parseInt(PropertiesHelper.getValue("VIEWPORT_HEIGHT"));
11+
public static boolean VIDEO_RECORD = Boolean.parseBoolean(PropertiesHelper.getValue("VIDEO_RECORD"));
12+
public static boolean SCREENSHOT_FAIL = Boolean.parseBoolean(PropertiesHelper.getValue("SCREENSHOT_FAIL"));
13+
public static boolean SCREENSHOT_PASS = Boolean.parseBoolean(PropertiesHelper.getValue("SCREENSHOT_PASS"));
14+
public static int TIMEOUT_STEP = Integer.parseInt(PropertiesHelper.getValue("TIMEOUT_STEP"));
515
}

src/main/java/com/anhtester/helpers/SystemHelper.java

+6
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ public static String getCurrentDir() {
77
String current = System.getProperty("user.dir") + File.separator;
88
return current;
99
}
10+
11+
public static String getOperatingSystem() {
12+
String os = System.getProperty("os.name");
13+
// System.out.println("OS name: " + os);
14+
return os;
15+
}
1016
}

src/main/java/com/anhtester/keywords/WebKeyword.java

+63-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
package com.anhtester.keywords;
22

3+
import com.anhtester.constants.AppConfig;
4+
import com.anhtester.helpers.SystemHelper;
35
import com.anhtester.managers.PageManager;
46
import com.anhtester.reports.AllureManager;
57
import com.anhtester.reports.ExtentTestManager;
68
import com.anhtester.utils.LogUtils;
79
import com.aventstack.extentreports.Status;
810
import io.qameta.allure.Step;
11+
import org.testng.asserts.SoftAssert;
912

1013
import java.awt.*;
1114
import java.awt.event.KeyEvent;
1215

1316
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+
}
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
}

src/main/java/com/anhtester/managers/BrowserFactory.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.anhtester.managers;
22

33
import com.anhtester.constants.AppConfig;
4+
import com.anhtester.keywords.WebKeyword;
45
import com.microsoft.playwright.*;
56

67
import java.awt.*;
@@ -10,14 +11,9 @@ public class BrowserFactory {
1011
protected static Browser browser;
1112
protected static BrowserContext browserContext;
1213
protected static Page page;
13-
14-
private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
15-
private static int screenWidth = ((int) screenSize.getWidth());
16-
private static int screenHeight = ((int) screenSize.getHeight());
17-
1814
//https://playwright.dev/java/docs/browsers
1915

20-
public static Page createBrowser(String browserName) {
16+
public static void createBrowser(String browserName) {
2117
playwright = Playwright.create();
2218
PageManager.setPlaywright(playwright);
2319

@@ -48,21 +44,17 @@ public static Page createBrowser(String browserName) {
4844
break;
4945
}
5046

51-
System.out.println("Screen Browser Width: " + screenWidth);
52-
System.out.println("Screen Browser Height: " + screenHeight);
53-
5447
PageManager.setBrowser(browser);
5548

56-
screenWidth = screenWidth - ((screenWidth * 5) / 100);
57-
System.out.println("Screen Browser Width (customize): " + screenWidth);
49+
// System.out.println("Screen Browser Width (customize): " + AppConfig.VIEWPORT_WIDTH);
50+
// System.out.println("Screen Browser Height (customize): " + AppConfig.VIEWPORT_HEIGHT);
5851

59-
browserContext = PageManager.getBrowser().newContext(new Browser.NewContextOptions().setViewportSize(screenWidth, screenHeight).setScreenSize(screenWidth, screenHeight));
52+
browserContext = PageManager.getBrowser().newContext(new Browser.NewContextOptions().setViewportSize(AppConfig.VIEWPORT_WIDTH, AppConfig.VIEWPORT_HEIGHT).setDeviceScaleFactor(1));
6053

6154
PageManager.setBrowserContext(browserContext);
6255
page = PageManager.getBrowserContext().newPage();
6356

6457
PageManager.setPage(page);
65-
//WebKeyword.maximizeBrowserOnWindow();
66-
return PageManager.getPage();
58+
WebKeyword.maximizeBrowserOnWindow();
6759
}
6860
}

src/main/resources/log4j2.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ appender.console.layout.pattern=[%level] %d{dd-MM-yyyy HH:mm:ss} [%t] %c{1} - %m
1010
appender.file.type=File
1111
appender.file.name=LOGFILE
1212
appender.file.fileName=${filename}
13-
appender.file.filePattern=logs/applog-%d{dd-MM-yyyy}.log
13+
#appender.file.filePattern=logs/applog-%d{dd-MM-yyyy}.log
1414
appender.file.layout.type=PatternLayout
1515
appender.file.layout.pattern=[%level] %d{dd-MM-yyyy HH:mm:ss} [%t] %c{1} - %msg%n
1616

@@ -21,6 +21,6 @@ logger.file.appenderRefs=file
2121
logger.file.appenderRef.file.ref=LOGFILE
2222

2323
rootLogger.level=info
24-
rootLogger.appenderRefs=stdout, file
24+
rootLogger.appenderRefs=console, file
2525
rootLogger.appenderRef.stdout.ref=STDOUT
2626
rootLogger.appenderRef.file.ref=LOGFILE
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package com.anhtester.common;
22

3+
import com.anhtester.constants.AppConfig;
4+
import com.anhtester.helpers.PropertiesHelper;
5+
import com.anhtester.keywords.WebKeyword;
36
import com.anhtester.listeners.TestListener;
47
import com.anhtester.managers.BrowserFactory;
58
import com.anhtester.managers.PageManager;
9+
import com.anhtester.pom.pages.CommonPage;
610
import org.testng.annotations.*;
711

812
@Listeners(TestListener.class)
9-
public class BaseTest {
13+
public class BaseTest extends CommonPage {
1014

1115
@BeforeMethod
1216
@Parameters({"BROWSER"})
1317
public void createBrowser(@Optional("chrome") String browserName) {
14-
BrowserFactory.createBrowser(browserName);
18+
if (AppConfig.BROWSER != null && !AppConfig.BROWSER.isEmpty()) {
19+
BrowserFactory.createBrowser(AppConfig.BROWSER);
20+
}else {
21+
BrowserFactory.createBrowser(browserName);
22+
}
1523
}
1624

1725
@AfterMethod
1826
public void closePage() {
1927
PageManager.closePage();
2028
PageManager.closeBrowser();
29+
30+
WebKeyword.closeSoftAssert();
2131
}
2232

2333
}

0 commit comments

Comments
 (0)