一、PO设计模式要点一:页面类都继承于BasePage
1、目录结构
ui_auto_test
--src
--pages
--__init__.py
--base_page.py
--login_page.py
--work_table_page.py
2、login_page.py
# conding:utf8
from .base_page import BasePage
from .home_page import WorkTablePage
#页面类都继承于BasePage
class LoginBage(BasePage):
def username_filed(self):
return self.by_css('#username')
def password_filed(self):
return self.by_css('#password_input')
def login_button(self):
return self.by_css('#tcloud_login_button')
def password_fail_text(self,text):
return self.by_css('#error-tips',text).text
class LoginAction(LoginBage):
def login_action(self,username,password):
self.username_filed().clear()
self.username_filed().send_keys(username)
self.password_filed().clear()
self.password_filed().send_keys(password)
self.login_button().click()
return WorkTablePage(self.driver)
3、work_table_page.py
# conding:utf8
from .base_page import BasePage
class WorkTablePage(BasePage):
def undo_word(self):
return self.by_css('.current.ul-inline a')
def get_undo_word_text(self):
return self.undo_word().text
二、test_case目录下面放你要执行的用例
1、目录结构
ui_auto_test
--src
--test_case
--__init.py
--test_login_case
--pages
--__init.py
--base_page.py
--login_page.py
--work_table_page.py
2、test_login_case.py
# conding:utf8
import unittest
import os, sys
#获取项目顶级文件夹绝对路径
src_path = os.path.split(os.path.split(__file__)[0])[0]
sys.path.insert(0, src_path)
from pages.login_page import LoginAction
from selenium import webdriver
class LoginCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def test_login_success(self):
login_page = LoginAction(self.driver, path='cloud_logins/login')
username = 'xxxxxx'
password = 'xxxxxx'
home_page = login_page.login_action(username, password)
text = home_page.get_undo_word_text()
print(text)
self.assertEqual('我的待办', text)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
创建了一个测试交流群,如果对软件测试、接口测试、自动化测试、面试经验交流感兴趣可以加测试交流群:829792258,还会有同行一起技术交流
网友评论