学习笔记-POM介绍

2019-12-26  本文已影响0人  sofiiii

1. 简介

2. 分层思想

3. POM优点

4. 示例

class Login(Page):
    '''user login'''
    url = '/UserManage/Login'
 
    __login_username_loc = (By.ID, "txtUInfo")
    __login_password_loc = (By.ID, "txtpwd")
    __login_button_loc = (By.LINK_TEXT,"登   录")
 
    #input username
    __def login_username(self, username):
        self.find_element(*self.login_username_loc).send_keys(username)
 
    #input_password
    __def login_password(self, password):
        self.find_element(*self.login_password_loc).send_keys(password)
 
    #click login button
    __def login_button(self):
        self.find_element(*self.login_button_loc).click()
    #login
    def user_login(self, username="defaultuser", password="defaultpwd"):
        self.open()
        self.login_username(username)
        self.login_password(password)
        self.login_button()
 
    __error_hint_loc = (By.ID, "sperrtip")
    __login_success_loc = (By.ID, "ausername")
 
    #login error message
    def error_hint(self):
        return self.find_element(*self.error_hint_loc).text
 
    #login successfully
    def user_login_success(self):
        return self.find_element(*self.login_success_loc).text
class loginTest(myunit.MyTest):
    
    def test_login1(self):
        page = Login(self.driver)
        page.user_login()
        self.assertEquals(page.user_login_success(), 'defaultuser')
 
    def test_login2(self):
        '''The test case will be failed'''
        page = Login(self.driver)
        page.user_login()
        self.assertEquals(page.user_login_success(), 'wronguser')
 
    def test_login_3(self):
        '''wrong pwd'''
        page = Login(self.driver)
        page.user_login('userb','111111')
        self.assertEquals(page.error_hint(), '密码错误,请重新输入密码'.decode('utf8'))
上一篇 下一篇

猜你喜欢

热点阅读