From 7142505802e48cb81005205db6217e68f0458794 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Sun, 11 Aug 2024 12:38:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=B8=80=E4=B8=AAclass?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_demo.py | 83 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/test_demo.py b/test_demo.py index 43123ca..d6743f3 100644 --- a/test_demo.py +++ b/test_demo.py @@ -3,44 +3,45 @@ import pytest from config import * -def setup(): - # setup 步骤 - driver = sync_playwright().start() - browser = driver.chromium.launch(headless=False) - context = browser.new_context() - page = context.new_page() - - -def test_admin_login(page): - # 访问医馆首页 - page.goto(BASE_URL) - - # 输入手机号后失焦触发获取医馆列表事件 - mobile_input = page.get_by_placeholder('请输入手机号') - mobile_input.fill(ADMIN_ACCOUNT) - mobile_input.blur() - - # 选择厚生堂诊所 - page.get_by_placeholder('请选择诊所名称').click() - page.get_by_text(CLINIC_NAME).click() - - # 输入密码 - page.get_by_placeholder('请输入密码').fill(ADMIN_PWD) - - #点击登录 - page.get_by_role('button', name='登录').click() - - # 验证测试结果 - assert page.locator('.max-logo').inner_text == CLINIC_NAME - - # 临时代码 - page.wait_for_timeout(2000) - -def teardown(context, page): - # teardown 步骤 - context.close() - page.close() - - -if __name__ == '__main__': - pytest.main('-vs') \ No newline at end of file +class Test_Admin(): + def setup_class(self): + # setup 步骤 + print('setup') + driver = sync_playwright().start() + browser = driver.chromium.launch(headless=False) + self.context = browser.new_context() + self.page = self.context.new_page() + + def teardown_class(self): + print('teardown') + # teardown 步骤 + self.context.close() + self.page.close() + + def test_admin_login(self): + # 访问医馆首页 + self.page.goto(BASE_URL) + + # 输入手机号后失焦触发获取医馆列表事件 + mobile_input = self.page.get_by_placeholder('请输入手机号') + mobile_input.fill(ADMIN_ACCOUNT) + mobile_input.blur() + + # 选择厚生堂诊所 + self.page.get_by_placeholder('请选择诊所名称').click() + self.page.get_by_text(CLINIC_NAME).click() + + # 输入密码 + self.page.get_by_placeholder('请输入密码').fill(ADMIN_PWD) + + #点击登录 + self.page.get_by_role('button', name='登录').click() + + print(self.page.locator('.max-logo').inner_text()) + # 验证测试结果 + assert self.page.locator('.max-logo').inner_text() == CLINIC_NAME + + # 临时代码 + self.page.wait_for_timeout(2000) + +