Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Automation_selenium
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Trình Nguyễn
Automation_selenium
Commits
6ea400e6
Commit
6ea400e6
authored
May 11, 2026
by
Đỗ Gia Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add separate test files for Lesson 14 (JS Executor) and Lesson 15 (Wait)
parent
72447216
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
HandleJavascriptExecutorTest.java
...om/automation/testcases/HandleJavascriptExecutorTest.java
+45
-0
HandleWaitTest.java
src/test/java/com/automation/testcases/HandleWaitTest.java
+46
-0
testng.xml
testng.xml
+2
-0
No files found.
src/test/java/com/automation/testcases/HandleJavascriptExecutorTest.java
0 → 100644
View file @
6ea400e6
package
com
.
automation
.
testcases
;
import
com.automation.base.BaseSetup
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.JavascriptExecutor
;
import
org.openqa.selenium.WebElement
;
import
org.testng.annotations.Test
;
public
class
HandleJavascriptExecutorTest
extends
BaseSetup
{
@Test
(
priority
=
1
,
description
=
"Bài 14: Sử dụng JS để Click và Scroll"
)
public
void
testJavascriptExecutorActions
()
throws
InterruptedException
{
driver
.
get
(
"https://anhtester.com/"
);
JavascriptExecutor
js
=
(
JavascriptExecutor
)
driver
;
// 1. Lấy Title của trang bằng JS
String
title
=
(
String
)
js
.
executeScript
(
"return document.title;"
);
System
.
out
.
println
(
"Title via JS: "
+
title
);
// 2. Cuộn chuột xuống cuối trang
System
.
out
.
println
(
">>> Đang cuộn xuống cuối trang..."
);
js
.
executeScript
(
"window.scrollTo(0, document.body.scrollHeight)"
);
Thread
.
sleep
(
2000
);
// 3. Cuộn chuột lên đầu trang
System
.
out
.
println
(
">>> Đang cuộn lên đầu trang..."
);
js
.
executeScript
(
"window.scrollTo(0, 0)"
);
Thread
.
sleep
(
2000
);
// 4. Tìm và cuộn đến một element cụ thể
WebElement
btnAllCourses
=
driver
.
findElement
(
By
.
xpath
(
"//h2[contains(text(),'Các Khóa Học Mới Nhất')]"
));
System
.
out
.
println
(
">>> Đang cuộn đến section khóa học..."
);
js
.
executeScript
(
"arguments[0].scrollIntoView(true);"
,
btnAllCourses
);
highlightElement
(
btnAllCourses
);
Thread
.
sleep
(
2000
);
// 5. Click vào element bằng JS (Hữu ích khi element bị che khuất)
WebElement
blogMenu
=
driver
.
findElement
(
By
.
xpath
(
"//a[contains(text(),'Blog')]"
));
System
.
out
.
println
(
">>> Đang Click vào menu Blog bằng JS..."
);
js
.
executeScript
(
"arguments[0].click();"
,
blogMenu
);
Thread
.
sleep
(
2000
);
}
}
src/test/java/com/automation/testcases/HandleWaitTest.java
0 → 100644
View file @
6ea400e6
package
com
.
automation
.
testcases
;
import
com.automation.base.BaseSetup
;
import
org.openqa.selenium.By
;
import
org.openqa.selenium.WebElement
;
import
org.openqa.selenium.support.ui.ExpectedConditions
;
import
org.openqa.selenium.support.ui.WebDriverWait
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
import
java.time.Duration
;
public
class
HandleWaitTest
extends
BaseSetup
{
@Test
(
priority
=
1
,
description
=
"Bài 15: Sử dụng Explicit Wait (WebDriverWait)"
)
public
void
testExplicitWait
()
{
driver
.
get
(
"https://anhtester.com/login"
);
// Khởi tạo WebDriverWait (Chờ tối đa 10 giây)
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
Duration
.
ofSeconds
(
10
));
// 1. Chờ cho tiêu đề trang chứa từ khóa cụ thể
wait
.
until
(
ExpectedConditions
.
titleContains
(
"Đăng nhập"
));
System
.
out
.
println
(
">>> Title đã sẵn sàng."
);
// 2. Chờ cho element Login button hiển thị và có thể click được
WebElement
loginBtn
=
wait
.
until
(
ExpectedConditions
.
elementToBeClickable
(
By
.
id
(
"btn-login"
)));
highlightElement
(
loginBtn
);
System
.
out
.
println
(
">>> Nút Login đã sẵn sàng để Click (không dùng Thread.sleep)."
);
Assert
.
assertTrue
(
loginBtn
.
isDisplayed
());
}
@Test
(
priority
=
2
,
description
=
"Bài 15: Chờ một element biến mất hoặc xuất hiện"
)
public
void
testWaitVisibility
()
{
driver
.
get
(
"https://anhtester.com/"
);
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
Duration
.
ofSeconds
(
10
));
// Chờ cho Logo xuất hiện
WebElement
logo
=
wait
.
until
(
ExpectedConditions
.
visibilityOfElementLocated
(
By
.
xpath
(
"//a[@class='logo']//img"
)));
System
.
out
.
println
(
">>> Logo đã hiển thị: "
+
logo
.
getAttribute
(
"src"
));
Assert
.
assertTrue
(
logo
.
isDisplayed
());
}
}
testng.xml
View file @
6ea400e6
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
<class
name=
"com.automation.testcases.HandleRobotClassTest"
/>
<class
name=
"com.automation.testcases.HandleRobotClassTest"
/>
<class
name=
"com.automation.testcases.HandleAlertTest"
/>
<class
name=
"com.automation.testcases.HandleAlertTest"
/>
<class
name=
"com.automation.testcases.HandleWindowIFrameTest"
/>
<class
name=
"com.automation.testcases.HandleWindowIFrameTest"
/>
<class
name=
"com.automation.testcases.HandleJavascriptExecutorTest"
/>
<class
name=
"com.automation.testcases.HandleWaitTest"
/>
</classes>
</classes>
</test>
</test>
</suite>
</suite>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment