From 56e745eade087b8608a150a3bd4ca4e298d30703 Mon Sep 17 00:00:00 2001 From: Khang Nguyen Date: Tue, 14 Oct 2025 22:50:12 +0700 Subject: [PATCH 1/2] Nop bai tap Playwright: buoi 1 va 2, Khang Nguyen --- khangnguyen_pw_baitap/.vscode/settings.json | 4 ++ .../Buoi 1/.vscode/settings.json | 4 ++ .../Buoi 1/tests/buoi1_bt.py | 21 +++++++++ .../Buoi 2/tests/.vscode/settings.json | 4 ++ .../buoi2_bt2.cpython-313-pytest-8.4.2.pyc | Bin 0 -> 1598 bytes .../Buoi 2/tests/buoi2_bt1.py | 43 ++++++++++++++++++ .../Buoi 2/tests/buoi2_bt2.py | 23 ++++++++++ 7 files changed, 99 insertions(+) create mode 100644 khangnguyen_pw_baitap/.vscode/settings.json create mode 100644 khangnguyen_pw_baitap/Buoi 1/.vscode/settings.json create mode 100644 khangnguyen_pw_baitap/Buoi 1/tests/buoi1_bt.py create mode 100644 khangnguyen_pw_baitap/Buoi 2/tests/.vscode/settings.json create mode 100644 khangnguyen_pw_baitap/Buoi 2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc create mode 100644 khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt1.py create mode 100644 khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py diff --git a/khangnguyen_pw_baitap/.vscode/settings.json b/khangnguyen_pw_baitap/.vscode/settings.json new file mode 100644 index 0000000..d63ccb8 --- /dev/null +++ b/khangnguyen_pw_baitap/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python-envs.defaultEnvManager": "ms-python.python:system", + "python-envs.pythonProjects": [] +} \ No newline at end of file diff --git a/khangnguyen_pw_baitap/Buoi 1/.vscode/settings.json b/khangnguyen_pw_baitap/Buoi 1/.vscode/settings.json new file mode 100644 index 0000000..d63ccb8 --- /dev/null +++ b/khangnguyen_pw_baitap/Buoi 1/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python-envs.defaultEnvManager": "ms-python.python:system", + "python-envs.pythonProjects": [] +} \ No newline at end of file diff --git a/khangnguyen_pw_baitap/Buoi 1/tests/buoi1_bt.py b/khangnguyen_pw_baitap/Buoi 1/tests/buoi1_bt.py new file mode 100644 index 0000000..3e4886a --- /dev/null +++ b/khangnguyen_pw_baitap/Buoi 1/tests/buoi1_bt.py @@ -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/") \ No newline at end of file diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/.vscode/settings.json b/khangnguyen_pw_baitap/Buoi 2/tests/.vscode/settings.json new file mode 100644 index 0000000..d63ccb8 --- /dev/null +++ b/khangnguyen_pw_baitap/Buoi 2/tests/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python-envs.defaultEnvManager": "ms-python.python:system", + "python-envs.pythonProjects": [] +} \ No newline at end of file diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc b/khangnguyen_pw_baitap/Buoi 2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3176db4ffbf7dc195edd5f6375f5fe8cf3996157 GIT binary patch literal 1598 zcmZ`(O>7%Q6rQzr;=eeCZVV(8v>}IJDfL3q3eu7)X)6SY6{0LTl(br{cPI9e^~`E^ zwyu2&5)$ErI8@}w5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C?q;W>c<- zyEW3k8g{T_*?~vppYZfLr6}U6ydklqKLYxugf5F0&wkJnU*AVJX+?zcM;c1-IISqk bzj>f2UxFc+{{xhc)sixE_~}1DxVZm6TFR1V literal 0 HcmV?d00001 diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt1.py b/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt1.py new file mode 100644 index 0000000..2adfb87 --- /dev/null +++ b/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt1.py @@ -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) + + + + + + diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py b/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py new file mode 100644 index 0000000..61f05e3 --- /dev/null +++ b/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py @@ -0,0 +1,23 @@ +# 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") + + productCount = page.locator(".inventory_item").count() + print(f"Inventory: {productCount}") + + page.wait_for_timeout(5000) \ No newline at end of file From cefdc3b7a335e1c86cd3ac96c399bc748a0a79bf Mon Sep 17 00:00:00 2001 From: Khang Nguyen Date: Tue, 14 Oct 2025 23:34:02 +0700 Subject: [PATCH 2/2] Chinh sua bai tap, Khang --- .../{Buoi 1 => Session1}/.vscode/settings.json | 0 .../{Buoi 1 => Session1}/tests/buoi1_bt.py | 0 .../tests/.vscode/settings.json | 0 .../buoi2_bt2.cpython-313-pytest-8.4.2.pyc | Bin .../{Buoi 2 => Session2}/tests/buoi2_bt1.py | 0 .../{Buoi 2 => Session2}/tests/buoi2_bt2.py | 3 --- 6 files changed, 3 deletions(-) rename khangnguyen_pw_baitap/{Buoi 1 => Session1}/.vscode/settings.json (100%) rename khangnguyen_pw_baitap/{Buoi 1 => Session1}/tests/buoi1_bt.py (100%) rename khangnguyen_pw_baitap/{Buoi 2 => Session2}/tests/.vscode/settings.json (100%) rename khangnguyen_pw_baitap/{Buoi 2 => Session2}/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc (100%) rename khangnguyen_pw_baitap/{Buoi 2 => Session2}/tests/buoi2_bt1.py (100%) rename khangnguyen_pw_baitap/{Buoi 2 => Session2}/tests/buoi2_bt2.py (89%) diff --git a/khangnguyen_pw_baitap/Buoi 1/.vscode/settings.json b/khangnguyen_pw_baitap/Session1/.vscode/settings.json similarity index 100% rename from khangnguyen_pw_baitap/Buoi 1/.vscode/settings.json rename to khangnguyen_pw_baitap/Session1/.vscode/settings.json diff --git a/khangnguyen_pw_baitap/Buoi 1/tests/buoi1_bt.py b/khangnguyen_pw_baitap/Session1/tests/buoi1_bt.py similarity index 100% rename from khangnguyen_pw_baitap/Buoi 1/tests/buoi1_bt.py rename to khangnguyen_pw_baitap/Session1/tests/buoi1_bt.py diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/.vscode/settings.json b/khangnguyen_pw_baitap/Session2/tests/.vscode/settings.json similarity index 100% rename from khangnguyen_pw_baitap/Buoi 2/tests/.vscode/settings.json rename to khangnguyen_pw_baitap/Session2/tests/.vscode/settings.json diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc b/khangnguyen_pw_baitap/Session2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc similarity index 100% rename from khangnguyen_pw_baitap/Buoi 2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc rename to khangnguyen_pw_baitap/Session2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt1.py b/khangnguyen_pw_baitap/Session2/tests/buoi2_bt1.py similarity index 100% rename from khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt1.py rename to khangnguyen_pw_baitap/Session2/tests/buoi2_bt1.py diff --git a/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py b/khangnguyen_pw_baitap/Session2/tests/buoi2_bt2.py similarity index 89% rename from khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py rename to khangnguyen_pw_baitap/Session2/tests/buoi2_bt2.py index 61f05e3..532de62 100644 --- a/khangnguyen_pw_baitap/Buoi 2/tests/buoi2_bt2.py +++ b/khangnguyen_pw_baitap/Session2/tests/buoi2_bt2.py @@ -16,8 +16,5 @@ def test_login_success(page: Page): expect(page.locator("[data-test='error']")).to_contain_text("Username and password do not match") print("Invalid credentials, login failed") - - productCount = page.locator(".inventory_item").count() - print(f"Inventory: {productCount}") page.wait_for_timeout(5000) \ No newline at end of file