From cb886c3d3903b5ccca7a664ad595768e4a25870a Mon Sep 17 00:00:00 2001 From: RogerWork Date: Sun, 11 Aug 2024 12:08:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 10 ++++++++++ demo.py | 29 ----------------------------- test_demo.py | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 36 deletions(-) create mode 100644 config.py delete mode 100644 demo.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..f480fe2 --- /dev/null +++ b/config.py @@ -0,0 +1,10 @@ +# 测试地址 +BASE_URL= 'http://ankangfulu.yhz.com' + +# 医馆 +CLINIC_NAME = '厚生堂(测试)诊所' + +# 管理员账号 +ADMIN_ACCOUNT = '18611659484' +ADMIN_PWD = 'admin123' + diff --git a/demo.py b/demo.py deleted file mode 100644 index 6c2d3e7..0000000 --- a/demo.py +++ /dev/null @@ -1,29 +0,0 @@ -from playwright.sync_api import sync_playwright - -driver = sync_playwright().start() - -browser = driver.chromium.launch(headless=False) - -page = browser.new_page() - -page.goto('http://ankangfulu.yhz.com') - -login_input = page.locator('.ivu-input') - -login_input.nth(0).fill('18611659484') - -login_input.nth(1).click() -page.wait_for_timeout(1000) - -page.locator('.ivu-select-input').click() -all_clince = page.locator('.ivu-select-dropdown-list').locator('.ivu-select-item').all() -for clince in all_clince: - if clince.inner_text() == '厚生堂(测试)诊所': - clince.click() - -login_input.nth(1).click() -login_input.nth(1).fill('admin123') - -page.locator('.login-form-btn').click() - -page.wait_for_timeout(10000) \ No newline at end of file diff --git a/test_demo.py b/test_demo.py index 931bf7e..43123ca 100644 --- a/test_demo.py +++ b/test_demo.py @@ -1,5 +1,7 @@ from playwright.sync_api import sync_playwright import pytest +from config import * + def setup(): # setup 步骤 @@ -9,28 +11,27 @@ def setup(): page = context.new_page() -@ pytest.fixture def test_admin_login(page): # 访问医馆首页 - page.goto('http://ankangfulu.yhz.com') + page.goto(BASE_URL) # 输入手机号后失焦触发获取医馆列表事件 mobile_input = page.get_by_placeholder('请输入手机号') - mobile_input.fill('18611659484') + mobile_input.fill(ADMIN_ACCOUNT) mobile_input.blur() # 选择厚生堂诊所 page.get_by_placeholder('请选择诊所名称').click() - page.get_by_text('厚生堂(测试)诊所').click() + page.get_by_text(CLINIC_NAME).click() # 输入密码 - page.get_by_placeholder('请输入密码').fill('admin123') + page.get_by_placeholder('请输入密码').fill(ADMIN_PWD) #点击登录 page.get_by_role('button', name='登录').click() # 验证测试结果 - assert page.locator('.max-logo').inner_text == '厚生堂(测试)诊所' + assert page.locator('.max-logo').inner_text == CLINIC_NAME # 临时代码 page.wait_for_timeout(2000) @@ -38,4 +39,8 @@ def test_admin_login(page): def teardown(context, page): # teardown 步骤 context.close() - page.close() \ No newline at end of file + page.close() + + +if __name__ == '__main__': + pytest.main('-vs') \ No newline at end of file