基于Selenium的web自动化框架(4)

发表于:2016-11-23来源:测试改进工场作者:测试改进工场点击数: 标签:框架
) cancelButton = (By.XPATH, //button[@class=\btn btn-warning ng-binding\][@ng-click=\cancel()\] ) okButton = (By.XPATH, //button[@class=\btn btn-primary ng-binding\][@ng-click=\ok()\] ) # Get username
) cancelButton = (By.XPATH,'//button[@class=\"btn btn-warning ng-binding\"][@ng-click=\"cancel()\"]') okButton = (By.XPATH,'//button[@class=\"btn btn-primary ng-binding\"][@ng-click=\"ok()\"]') #Get username textbox and input username def set_username(self,username): name = self.driver.find_element(*LoginPage.usename) name.send_keys(username) #Get password textbox and input password, then hit return def set_password(self, password): pwd = self.driver.find_element(*LoginPage.password) pwd.send_keys(password + Keys.RETURN) #Get pop up dialog title def get_DiaglogTitle(self): digTitle = self.driver.find_element(*LoginPage.dialogTitle) return digTitle.text #Get "cancel" button and then click def click_cancel(self): cancelbtn = self.driver.find_element(*LoginPage.cancelButton) cancelbtn.click() #click Sign in def click_SignIn(self): okbtn = self.driver.find_element(*LoginPage.okButton) okbtn.click()
复制代码

 

 

采用页面模式来管理页面和测试用例有很多好处,主要体现在:

  • 简单并且清晰

每个页面都有单独的类来封装页面元素和操作,让页面操作更加具体化,而不是相对独立的。

比如未使用页面模式,测试用例的输入用户名和密码的代码:

原文转自:http://www.cnblogs.com/AlwinXu/p/5836709.html

...

热门标签