Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions khangnguyen_pw_baitap/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system",
"python-envs.pythonProjects": []
}
4 changes: 4 additions & 0 deletions khangnguyen_pw_baitap/Session1/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system",
"python-envs.pythonProjects": []
}
21 changes: 21 additions & 0 deletions khangnguyen_pw_baitap/Session1/tests/buoi1_bt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Viết file mới test_bai_tap.py để:
# 1️⃣ Truy cập vào trang web yêu thích (ví dụ: shopee.vn, vnexpress.net, công ty bạn).
# 2️⃣ Kiểm tra tiêu đề trang có đúng mong đợi.
# 3️⃣ Kiểm tra URL trang web.


from playwright.sync_api import Page, expect
import re, time

def test_title_and_page_url(page: Page):
print("Opening Google Chrome browser...")
page.goto("https://www.parcelperform.com/")
time.sleep(5)

# Verify title
expect(page).to_have_title("Parcel Perform | AI Delivery Experience SaaS Software")
print("Title is correct: Parcel Perform | AI Delivery Experience SaaS Software")

# Verify URL
expect(page).to_have_url("https://www.parcelperform.com/")
print("URL is correct: https://www.parcelperform.com/")
4 changes: 4 additions & 0 deletions khangnguyen_pw_baitap/Session2/tests/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system",
"python-envs.pythonProjects": []
}
Binary file not shown.
43 changes: 43 additions & 0 deletions khangnguyen_pw_baitap/Session2/tests/buoi2_bt1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Truy cập trang https://www.saucedemo.com/
# Sử dụng page.get_by_placeholder("Username") để điền standard_user.
# Sử dụng page.get_by_placeholder("Password") để điền secret_sauce.
# Click nút Login bằng page.get_by_role("button", name="Login").
# Dùng expect để chờ và xác nhận tiêu đề "Products" xuất hiện: expect(page.get_by_text("Products")).to_be_visible().
# In ra số lượng sản phẩm có trên trang (gợi ý: locator là .inventory_item).

from playwright.sync_api import Page, expect
import re, time

def test_login_success(page: Page):
page.goto(" https://www.saucedemo.com/")

# Find username and password field

# Locators
usernameId = page.locator("#user-name").fill("standard_user")
passwordId = page.locator("#password").fill("secret_sauce")
loginId = page.locator("login-button").click()

# Xpath
usernameXpath = page.locator("//div//input[@id='user-name']").fill("standard_user")
passwordXpath = page.locator("//div//input[@id='password']").fill("secret_sauce")
loginXpath = page.locator("//div//input[@id='login-button']").click()

# Get by placeholder
usernameField = page.get_by_placeholder("Username").fill("standard_user")
passwordField = page.get_by_placeholder("Password").fill("secret_sauce")
loginButton = page.get_by_role("button", name="Login").click()

expect(page.get_by_text("Products")).to_be_visible()
print("Login successful, Products page is opened")

productCount = page.locator(".inventory_item").count()
print(f"Inventory: {productCount}")

page.wait_for_timeout(5000)






20 changes: 20 additions & 0 deletions khangnguyen_pw_baitap/Session2/tests/buoi2_bt2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Cũng tại trang trên, cố tình nhập sai password.
# Click nút Login.
# Sử dụng page.locator("[data-test='error']") kết hợp với expect().to_contain_text() để chờ và xác minh thông báo lỗi "Username and password do not match" xuất hiện.

from playwright.sync_api import Page, expect
import re, time

def test_login_success(page: Page):
page.goto(" https://www.saucedemo.com/")

# Find username and password field
usernameField = page.get_by_placeholder("Username").fill("standard_user")
passwordField = page.get_by_placeholder("Password").fill("secret_sauce123")
loginButton = page.get_by_role("button", name="Login").click()

expect(page.locator("[data-test='error']")).to_contain_text("Username and password do not match")

print("Invalid credentials, login failed")

page.wait_for_timeout(5000)