from selenium import webdriver
from selenium.webdriver.edge.service import Service
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
def init():
service = Service('C:/Users/LLL/Desktop/edgedriver_win64/msedgedriver.exe')
# 创建一个EdgeOptions对象,并设置一些选项
options = webdriver.EdgeOptions()
options.add_argument('--start-maximized')
# 将Service对象传递给EdgeOptions的service属性
options.service = service
# 创建一个Edge浏览器的WebDriver实例
driver = webdriver.Edge(options=options)
# edge = webdriver.Edge('C:/Users/LLL/Desktop/edgedriver_win64/msedgedriver.exe')
return driver
# driver.get('http://localhost:8080/SMBMS_war/login.jsp')
# time.sleep(2)
# driver.quit()
def login():
# 测试登录
driver = init()
driver.get('http://localhost:8080/SMBMS_war/login.jsp')
# time.sleep(2)
name = driver.find_element(By.ID, 'userCode')
psw = driver.find_element(By.ID, 'userPassword')
name.send_keys('admin')
psw.send_keys('1234567')
button = driver.find_element(By.CLASS_NAME, 'subBtn').find_element(By.CSS_SELECTOR, 'input[type=submit]')
# time.sleep(2)
button.click()
# time.sleep(3)
# 获取登录用户信息
# 验证是否跳转到首页,并且是否显示了用户名信息
# assert ('http://localhost:8080/SMBMS_war/jsp/frame' in driver.current_url)
# driver.quit()
return driver
def dingdan_select():
# 订单管理测试
# 进入订单管理
driver = login()
# include = driver.find_element(By.XPATH, 'http://localhost:8080/SMBMS_war/jsp/billManagement')
w = driver.find_element(By.ID, 'head_1')
w.click()
assert ('http://localhost:8080/SMBMS_war/jsp/billManagement' in driver.current_url)
# driver.implicitly_wait(2)
time.sleep(3)
# 开始进行搜索,测试
# 商品名称
ProductName = driver.find_element(By.NAME, 'queryProductName')
# 供应商
Provider = driver.find_element(By.NAME, 'queryProviderId')
select1 = Select(Provider)
select1.select_by_index(1)
# 是否付款
pay = driver.find_element(By.NAME, 'queryIsPayment')
select2 = Select(pay)
select2.select_by_index(1)
chaxun = driver.find_element(By.ID, 'searchbutton')
chaxun.click()
time.sleep(3)
driver.quit()
def dingdan_add(data):
driver = login()
w = driver.find_element(By.ID, 'head_1')
w.click()
time.sleep(2)
for q in data:
add = driver.find_element(By.ID, 'dingda_add')
add.click()
time.sleep(2)
billCode = driver.find_element(By.ID, 'billCode')
productName = driver.find_element(By.ID, 'productName')
productUnit = driver.find_element(By.ID, 'productUnit')
productCount = driver.find_element(By.ID, 'productCount')
totalPrice = driver.find_element(By.ID, 'totalPrice')
proveder = driver.find_element(By.ID, 'providerId')
select1 = Select(proveder)
billCode.clear()
billCode.send_keys(q[0])
productCount.clear()
productCount.send_keys(q[1])
productName.clear()
productName.send_keys(q[2])
productUnit.clear()
productUnit.send_keys(q[3])
totalPrice.clear()
totalPrice.send_keys(q[4])
select1.select_by_index(1)
driver.find_element(By.XPATH, '/html/body/section[2]/div[2]/div[2]/form/div[8]/input[1]').submit()
time.sleep(2)
# 处理弹出页面
# confirm_button = driver.find_element(By.ID, "add")
# confirm_button.click()
# time.sleep(2)
driver.quit()
"""def dingdan_add1(data):
driver = login()
w = driver.find_element(By.ID, 'head_1')
w.click()
# time.sleep(2)
add = driver.find_element(By.ID, 'dingda_add')
add.click()
# time.sleep(2)
billCode = driver.find_element(By.ID, 'billCode')
productName = driver.find_element(By.ID, 'productName')
productUnit = driver.find_element(By.ID, 'productUnit')
productCount = driver.find_element(By.ID, 'productCount')
totalPrice = driver.find_element(By.ID, 'totalPrice')
proveder = driver.find_element(By.ID, 'providerId')
select1 = Select(proveder)
billCode.send_keys('8')
productCount.send_keys('8')
productName.send_keys('8')
productUnit.send_keys('8')
totalPrice.send_keys('8')
select1.select_by_index(1)
submit = driver.find_element(By.ID, 'add').submit()
time.sleep(1)
driver.implicitly_wait(2)
# confirm_button = driver.find_element(By.ID, 'yes')
# confirm_button.click()
driver.quit()"""
def dingdan_delete():
driver = login()
w = driver.find_element(By.ID, 'head_1')
w.click()
time.sleep(2)
# 定位并点击删除按钮
# 删除编号为1的
delete_button = driver.find_element(By.XPATH, "//tr[td/span='3']//a[@class='deleteBill']")
delete_button.click()
time.sleep(5)
# 处理弹出页面
confirm_button = driver.find_element(By.CSS_SELECTOR, "#yes")
confirm_button.click()
time.sleep(2)
driver.quit()
def dingdan_modify():
driver = login()
w = driver.find_element(By.ID, 'head_1')
w.click()
time.sleep(2)
# 修改编号为1的订单
modify_button = driver.find_element(By.XPATH, "//tr[td/span='1']//a[@class='modifyBill']")
modify_button.click()
time.sleep(2)
# 修改设置值
billCode = driver.find_element(By.ID, 'billCode')
productName = driver.find_element(By.ID, 'productName')
productUnit = driver.find_element(By.ID, 'productUnit')
productCount = driver.find_element(By.ID, 'productCount')
totalPrice = driver.find_element(By.ID, 'totalPrice')
billCode.send_keys('1')
productCount.send_keys('2')
productName.send_keys('3')
productUnit.send_keys('4')
totalPrice.send_keys('5')
submit = driver.find_element(By.ID, 'save')
submit.click()
time.sleep(2)
# 处理弹出页面
confirm_button = driver.find_element(By.CSS_SELECTOR, "#yes")
confirm_button.click()
time.sleep(2)
driver.quit()
def dingdan_detail():
driver = login()
w = driver.find_element(By.ID, 'head_1')
w.click()
time.sleep(2)
detail_button = driver.find_element(By.XPATH, "//tr[td/span='1']//a[@class='viewBill']")
detail_button.click()
time.sleep(2)
driver.quit()
if __name__ == '__main__':
# dingdan_detail()
# dingdan_modify()
# dingdan_delete()
data = [
['1', '1', '1', '1', '1'],
['2', '2', '2', '2', '3'],
['3', '3', '3', '3', '3']
]
dingdan_add(data)
# dingdan()
# login()