case执行的代码
from keywordselenium.actionMethod import ActionMethod
from util.exlcel_util import ExcelUtil
class KeywordCase:
def run_main(self):
self.actionmethod = ActionMethod()
handle_excel = ExcelUtil(r'../config/keyword.xls')
lines = handle_excel.get_lines()
if lines:
for i in range(1,lines):
if_run = handle_excel.get_col_value(i,3)
if if_run == 'yes':
method = handle_excel.get_col_value(i,4)
send_value = handle_excel.get_col_value(i,5)
handle_value = handle_excel.get_col_value(i,6)
self.run_method(method,send_value,handle_value)
def run_method(self,method,send_value,handle_value):
method_value = getattr(self.actionmethod,method)
if send_value:
method_value(send_value,handle_value)
else:
method_value(handle_value)
if __name__ == '__main__':
run = KeywordCase()
run.run_main()
执行方法的代码
from selenium import webdriver
from base.find_element import Findelement
from time import sleep
class ActionMethod:
#打开浏览器
def open_browser(self,browser):
if browser == 'chrome':
self.driver = webdriver.Chrome()
elif browser == 'firefox':
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Edge()
#打开网页
def get_url(self,url):
self.driver.get(url)
self.driver.maximize_window()
#定位元素
def get_element(self,key):
findelement = Findelement(self.driver)
element = findelement.get_element(key)
return element
#输入元素
def element_send_keys(self,value,key):
element = self.get_element(key)
element.send_keys(value)
#点击元素
def click_element(self,key):
self.get_element(key).click()
#等待时间
def wait_time(self):
sleep(3)
#关闭浏览器
def close_browser(self):
self.driver.close()
#获取标题
def get_tittle(self):
tittle = self.driver.title
return tittle