使用selenium对mis系统进行测试
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()
分类:
实验例题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构