import unittest
import openpyxl
from selenium import webdriver
from key.bilibili_key import Key
excel = openpyxl.load_workbook('../data/test_case.xlsx')
sheets = excel.sheetnames
for name in sheets:
sheet = excel[name]
print(sheet)
for values in sheet.values:
if type(values[0]) is int:
data = {}
data['name'] = values[2]
data['value'] = values[3]
data['txt'] = values[4]
for key1 in list(data.keys()):
if data[key1] is None:
del data[key1]
print("正在执行:"+values[5])
if values[1]=='open_browser':
key=Key(**data)
else:
getattr(key,values[1])(**data)
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
def open_browser(txt):
try:
driver = getattr(webdriver, txt)()
except Exception as e:
print(e)
driver = webdriver.Chrome()
return driver
class Key:
def __init__(self, txt):
self.driver = open_browser(txt)
def locator(self, name, value):
return self.driver.find_element(name, value)
def click(self, name, value):
self.locator(name, value).click()
def input(self, name, value, txt):
self.locator(name, value).send_keys(txt)
def move(self, name, value):
element = self.locator(name, value)
ActionChains(self.driver).move_to_element(element).perform()
sleep(1)
def open(self, txt):
self.driver.get(txt)
def quit(self):
self.driver.quit()
def sleep(self, txt):
sleep(txt)
|