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/Session1/.vscode/settings.json b/khangnguyen_pw_baitap/Session1/.vscode/settings.json new file mode 100644 index 0000000..d63ccb8 --- /dev/null +++ b/khangnguyen_pw_baitap/Session1/.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/Session1/tests/buoi1_bt.py b/khangnguyen_pw_baitap/Session1/tests/buoi1_bt.py new file mode 100644 index 0000000..3e4886a --- /dev/null +++ b/khangnguyen_pw_baitap/Session1/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/Session2/tests/.vscode/settings.json b/khangnguyen_pw_baitap/Session2/tests/.vscode/settings.json new file mode 100644 index 0000000..d63ccb8 --- /dev/null +++ b/khangnguyen_pw_baitap/Session2/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/Session2/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 new file mode 100644 index 0000000..3176db4 Binary files /dev/null and b/khangnguyen_pw_baitap/Session2/tests/__pycache__/buoi2_bt2.cpython-313-pytest-8.4.2.pyc differ diff --git a/khangnguyen_pw_baitap/Session2/tests/buoi2_bt1.py b/khangnguyen_pw_baitap/Session2/tests/buoi2_bt1.py new file mode 100644 index 0000000..2adfb87 --- /dev/null +++ b/khangnguyen_pw_baitap/Session2/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/Session2/tests/buoi2_bt2.py b/khangnguyen_pw_baitap/Session2/tests/buoi2_bt2.py new file mode 100644 index 0000000..532de62 --- /dev/null +++ b/khangnguyen_pw_baitap/Session2/tests/buoi2_bt2.py @@ -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) \ No newline at end of file