WebOpLib.py测试库
from selenium import webdriver from cfg import *
class WebOpLib():
def openwebsite(self): self.driver=webdriver.Chrome() self.driver.maximize_window() self.driver.implicitly_wait(10) def TeacherLogin(self,uname,pwd): self.driver.get(g_teacher_login_url) self.driver.find_element_by_id('username').send_keys(uname) self.driver.find_element_by_id('password').send_keys(pwd) self.driver.find_element_by_id('submit').click() time.sleep(1) def closewebsite(self): self.driver.quit()
遇到的问题:
对登陆这个模块的用例进行自动化,每执行一个用例,打开一个谷歌,显然是可以优化的!
from selenium import webdriver from cfg import * class WebOpLib(): ROBOT_LIBRARY_SCOPE = 'GLOBAL' #调用这个库的用例都打开同一个浏览器,设置全局的参数
def openwebsite(self): self.driver=webdriver.Chrome() self.driver.maximize_window() self.driver.implicitly_wait(10) def TeacherLogin(self,uname,pwd): self.driver.get(g_teacher_login_url) self.driver.find_element_by_id('username').send_keys(uname) self.driver.find_element_by_id('password').send_keys(pwd) self.driver.find_element_by_id('submit').click() time.sleep(1) def closewebsite(self): self.driver.quit()