Skip to content

Commit 7f33de3

Browse files
committed
Update Playwright version 1.40.0
1 parent 42bd4b6 commit 7f33de3

36 files changed

+1265
-151
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ buildNumber.properties
99
.mvn/timing.properties
1010
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
1111
.mvn/wrapper/maven-wrapper.jar
12-
.idea
1312
*.zip
13+
.idea/
14+
reports/
15+
logs/
16+
*.iml

pom.xml

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,148 @@
1919
<dependency>
2020
<groupId>com.microsoft.playwright</groupId>
2121
<artifactId>playwright</artifactId>
22-
<version>1.28.1</version>
22+
<version>1.40.0</version>
2323
</dependency>
2424

2525
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
2626
<dependency>
2727
<groupId>org.testng</groupId>
2828
<artifactId>testng</artifactId>
29-
<version>7.4.0</version>
30-
<scope>test</scope>
29+
<version>7.8.0</version>
3130
</dependency>
3231

3332
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
3433
<dependency>
3534
<groupId>org.slf4j</groupId>
3635
<artifactId>slf4j-api</artifactId>
37-
<version>2.0.6</version>
36+
<version>2.0.9</version>
3837
<scope>test</scope>
3938
</dependency>
4039

4140
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
4241
<dependency>
4342
<groupId>org.slf4j</groupId>
4443
<artifactId>slf4j-simple</artifactId>
45-
<version>2.0.6</version>
44+
<version>2.0.9</version>
4645
<scope>test</scope>
4746
</dependency>
4847

48+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
49+
<dependency>
50+
<groupId>org.apache.poi</groupId>
51+
<artifactId>poi</artifactId>
52+
<version>5.2.5</version>
53+
</dependency>
54+
55+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
56+
<dependency>
57+
<groupId>org.apache.poi</groupId>
58+
<artifactId>poi-ooxml</artifactId>
59+
<version>5.2.5</version>
60+
</dependency>
61+
62+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
63+
<dependency>
64+
<groupId>commons-io</groupId>
65+
<artifactId>commons-io</artifactId>
66+
<version>2.15.1</version>
67+
</dependency>
68+
69+
<!-- https://mvnrepository.com/artifact/com.github.stephenc.monte/monte-screen-recorder -->
70+
<dependency>
71+
<groupId>com.github.stephenc.monte</groupId>
72+
<artifactId>monte-screen-recorder</artifactId>
73+
<version>0.7.7.0</version>
74+
</dependency>
75+
76+
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
77+
<dependency>
78+
<groupId>org.apache.logging.log4j</groupId>
79+
<artifactId>log4j-core</artifactId>
80+
<version>2.22.0</version>
81+
</dependency>
82+
83+
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
84+
<dependency>
85+
<groupId>org.apache.logging.log4j</groupId>
86+
<artifactId>log4j-api</artifactId>
87+
<version>2.22.0</version>
88+
</dependency>
89+
90+
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
91+
<dependency>
92+
<groupId>com.aventstack</groupId>
93+
<artifactId>extentreports</artifactId>
94+
<version>5.1.1</version>
95+
</dependency>
96+
97+
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
98+
<dependency>
99+
<groupId>io.qameta.allure</groupId>
100+
<artifactId>allure-testng</artifactId>
101+
<version>2.25.0</version>
102+
</dependency>
103+
104+
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-attachments -->
105+
<dependency>
106+
<groupId>io.qameta.allure</groupId>
107+
<artifactId>allure-attachments</artifactId>
108+
<version>2.25.0</version>
109+
</dependency>
110+
111+
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
112+
<dependency>
113+
<groupId>org.aspectj</groupId>
114+
<artifactId>aspectjweaver</artifactId>
115+
<version>1.9.21</version>
116+
</dependency>
117+
118+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
119+
<dependency>
120+
<groupId>org.projectlombok</groupId>
121+
<artifactId>lombok</artifactId>
122+
<version>1.18.30</version>
123+
<scope>provided</scope>
124+
</dependency>
125+
126+
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
127+
<dependency>
128+
<groupId>com.google.guava</groupId>
129+
<artifactId>guava</artifactId>
130+
<version>33.0.0-jre</version>
131+
</dependency>
132+
49133
</dependencies>
50134

51135
<build>
52136
<plugins>
53137
<plugin>
54138
<groupId>org.apache.maven.plugins</groupId>
55139
<artifactId>maven-compiler-plugin</artifactId>
56-
<version>3.10.1</version>
57-
<configuration>
58-
<source>${maven.compiler.source}</source>
59-
<target>${maven.compiler.target}</target>
60-
</configuration>
140+
<version>3.12.0</version>
61141
</plugin>
62142

63143
<plugin>
64144
<groupId>org.apache.maven.plugins</groupId>
65145
<artifactId>maven-surefire-plugin</artifactId>
66-
<version>3.0.0-M7</version>
146+
<version>3.2.3</version>
67147
<configuration>
68148
<suiteXmlFiles>
69149
<suiteXmlFile>suites/CategoryTest.xml</suiteXmlFile>
70150
</suiteXmlFiles>
151+
152+
<argLine>
153+
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.21/aspectjweaver-1.9.21.jar"
154+
</argLine>
155+
<testFailureIgnore>true</testFailureIgnore>
156+
<systemPropertyVariables>
157+
<!--Đường dẫn xuất ra report-->
158+
<allure.results.directory>target/allure-results</allure.results.directory>
159+
</systemPropertyVariables>
71160
</configuration>
72161
</plugin>
73162
</plugins>
163+
74164
</build>
75165

76166
</project>

src/main/java/anhtester/com/constant/AppConfig.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/anhtester/com/keyword/ActionKeyword.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.anhtester.constants;
2+
3+
public class AppConfig {
4+
public static final boolean HEADLESS = false;
5+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.anhtester.helpers;
2+
3+
import com.anhtester.managers.PageManager;
4+
5+
import org.monte.media.Format;
6+
import org.monte.media.Registry;
7+
import org.monte.media.math.Rational;
8+
import org.monte.screenrecorder.ScreenRecorder;
9+
10+
import java.awt.*;
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.nio.file.Paths;
14+
import java.text.SimpleDateFormat;
15+
import java.util.Date;
16+
17+
import com.microsoft.playwright.Browser;
18+
import com.microsoft.playwright.Locator;
19+
import com.microsoft.playwright.Page;
20+
import com.microsoft.playwright.Page.ScreenshotOptions;
21+
import com.microsoft.playwright.Playwright;
22+
import com.microsoft.playwright.options.ScreenshotCaret;
23+
24+
import static org.monte.media.FormatKeys.*;
25+
import static org.monte.media.VideoFormatKeys.*;
26+
27+
public class CaptureHelper extends ScreenRecorder {
28+
29+
// Record with Monte Media library
30+
public static ScreenRecorder screenRecorder;
31+
public String name;
32+
33+
//Hàm xây dựng
34+
public CaptureHelper(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder, String name) throws IOException, AWTException {
35+
super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat, movieFolder);
36+
this.name = name;
37+
}
38+
39+
//Hàm này bắt buộc để ghi đè custom lại hàm trong thư viên viết sẵn
40+
@Override
41+
protected File createMovieFile(Format fileFormat) throws IOException {
42+
43+
if (!movieFolder.exists()) {
44+
movieFolder.mkdirs();
45+
} else if (!movieFolder.isDirectory()) {
46+
throw new IOException("\"" + movieFolder + "\" is not a directory.");
47+
}
48+
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
49+
return new File(movieFolder, name + "-" + dateFormat.format(new Date()) + "." + Registry.getInstance().getExtension(fileFormat));
50+
}
51+
52+
// Start record video
53+
public static void startRecord(String methodName) {
54+
//Tạo thư mục để lưu file video vào
55+
File file = new File(SystemHelper.getCurrentDir() + PropertiesHelper.getValue("VIDEO_RECORD_PATH"));
56+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
57+
int width = screenSize.width;
58+
int height = screenSize.height;
59+
60+
Rectangle captureSize = new Rectangle(0, 0, width, height);
61+
62+
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
63+
try {
64+
screenRecorder = new CaptureHelper(gc, captureSize, new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24, FrameRateKey, Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)), null, file, methodName);
65+
screenRecorder.start();
66+
} catch (IOException e) {
67+
throw new RuntimeException(e);
68+
} catch (AWTException e) {
69+
throw new RuntimeException(e);
70+
}
71+
}
72+
73+
// Stop record video
74+
public static void stopRecord() {
75+
try {
76+
screenRecorder.stop();
77+
} catch (IOException e) {
78+
throw new RuntimeException(e);
79+
}
80+
}
81+
82+
83+
//Tạo format ngày giờ để xíu gắn dô cái name của screenshot hoặc record video không bị trùng tên (không bị ghi đè file)
84+
private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
85+
86+
87+
public static void takeScreenshot(String screenshotName) {
88+
try {
89+
// screenshots
90+
ScreenshotOptions screenshotOptions = new ScreenshotOptions();
91+
92+
File theDir = new File(SystemHelper.getCurrentDir() + PropertiesHelper.getValue("SCREENSHOT_PATH"));
93+
if (!theDir.exists()) {
94+
theDir.mkdirs();
95+
}
96+
97+
PageManager.getPage().screenshot(screenshotOptions.setPath(Paths.get(SystemHelper.getCurrentDir() + PropertiesHelper.getValue("SCREENSHOT_PATH") + File.separator + screenshotName + "_" + dateFormat.format(new Date()) + ".png")));
98+
System.out.println("Screenshot taken: " + screenshotName);
99+
System.out.println("Screenshot taken current URL: " + PageManager.getPage().url());
100+
} catch (Exception e) {
101+
System.out.println("Exception while taking screenshot: " + e.getMessage());
102+
}
103+
}
104+
105+
}

0 commit comments

Comments
 (0)