An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
-
章 登恒 authoredde31e028
import datetime
import threading
import time
import traceback
from airtest.core.api import *
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import *
from selenium.webdriver import Chrome, ChromeOptions
from airtest.core.api import *
from airtest_selenium.proxy import *
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from public.mail1 import send_email1
from public.tools import *
opt = ChromeOptions() # 创建 Chrome 参数对象
opt.headless = False # 把 Chrome 设置成无界面模式,windows/Linux 皆可
opt.add_argument('--start-maximized')
opt.add_argument('--window-size=1280x1024')
chrome = webdriver.Chrome(chrome_options=opt)
wait = WebDriverWait(chrome,20,poll_frequency=0.2)
SIT_URL = 'http://scdev.cmic.com.cn:8088/beta/'#SIT环境地址
#通行证
usr1,pwd1 = 'bj_01','Gyxc1234'
usr2,pwd2 = 'bj_02','Gyxc1234'
usr3,pwd3 = 'bj_03','Gyxc1234'
usr4,pwd4 = 'bj_04','Gyxc1234'
usr5,pwd5 = 'bj_05','Gyxc1234'
warehousename = '北京强生非WMS仓'#仓库名称
contractnumber = 41007#合同号
salesman = '杨春刚'#业务员名称
productcode = 10156326#商品编码
productdate = '2023-10-01'
expirdate = '2026-09-30'
class LoginSys():#登录
def loginsys(self,url,usr,pwd):
chrome.get(url)
sleep(2)
chrome.find_element_by_id('input1').clear()
chrome.find_element_by_id('input1').send_keys(usr)
chrome.find_element_by_id('input2').clear()
chrome.find_element_by_id('input2').send_keys(pwd)
chrome.find_element_by_id('input2').send_keys(Keys.ENTER)
locator = (By.XPATH, '//span[text()="退出"]')
wait.until(ec.presence_of_element_located(locator))
# while True:
# try:
# if(chrome.find_element_by_xpath('//span[text()="退出"]').is_displayed()==True):
# break
# except:
# continue
class PurchaseOrder():#普通采购单界面操作
def data_add(self):#填写表单数据
chrome.implicitly_wait(10)
order_link = chrome.find_element_by_xpath('//span[text()="普通采购订单"]')
chrome.execute_script("arguments[0].click();", order_link)
chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
sleep(2)
chrome.find_element_by_xpath('//span[text()="新建"]').click()
sleep(4)
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(2)
# 获取订单号
global orderno1
orderno1 = chrome.find_element_by_xpath('//div[text() = "订单号 "]/following-sibling::div/span').text
print('普通采购单号为:',orderno1)
#填写仓库信息
chrome.find_element_by_xpath('//div[text()="仓库名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
sleep(1)
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库名称,仓库编码"]').send_keys(warehousename)
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库名称,仓库编码"]').send_keys(Keys.ENTER)
sleep(1)
btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="022bc5d182335c5146b3817a500c2cbc7"]')
chrome.execute_script("arguments[0].click();", btn_div)
sleep(1)
chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
sleep(1)
#填写合同信息
chrome.find_element_by_xpath('//div[text()="合同信息"]').click()
sleep(1)
chrome.find_element_by_xpath(
'//div[text()="采购合同/协议号 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
sleep(1)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:合同协议号,合同号,项目编码,项目名称,业态编码,对方编码,产品线编码"]').send_keys(
contractnumber)
sleep(1)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:合同协议号,合同号,项目编码,项目名称,业态编码,对方编码,产品线编码"]').send_keys(
Keys.ENTER)
sleep(1)
# chrome.find_element_by_xpath(
# '//div[@class="multiple-header string_col" and text()="38443"]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="03992a2172b8f7327a077e60ac1da11b8"]')
chrome.execute_script("arguments[0].click();", btn_div)
sleep(1)
chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
sleep(1)
#业务员名称
chrome.find_element_by_xpath(
'//div[text()="业务员名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
sleep(1)
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员编码,业务员名称,部门编码,部门名称"]').send_keys(salesman)
sleep(1)
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员编码,业务员名称,部门编码,部门名称"]').send_keys(Keys.ENTER)
sleep(1)
btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="06c32a810e3dabf2a50d1ab040c7951c8"]')
chrome.execute_script("arguments[0].click();", btn_div)
sleep(1)
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[3]').click()
sleep(1)
#其他信息页签
chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
sleep(1)
# 子表信息录入
chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
sleep(1)
chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
sleep(1)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,厂家物料编码"]').send_keys(productcode)
sleep(0.5)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,厂家物料编码"]').send_keys(Keys.ENTER)
sleep(2)
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
chrome.find_element_by_xpath(
'//th[@class="el-table_15_column_199 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
sleep(0.5)
chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[4]').click()
sleep(5)
#填写数量价格
for i in range(1):
wait.until(ec.visibility_of_element_located((By.XPATH,'(//td[@colid="col_164" and @f="F_QUANTITY_ORD" and @i=%s])'%i)))
element = chrome.find_element_by_xpath('(//td[@colid="col_164" and @f="F_QUANTITY_ORD" and @i=%s])'%i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('awsui-input-number-right').send_keys('1')
sleep(1)
chrome.find_element_by_xpath('(//td[@colid="col_171" and @f="F_PURUNIT_TXT" and @i=%s])' % i).click()
sleep(1)
def return_pchno(self):#返回采购单号
return orderno1
def closetab(self):#关闭菜单
chrome.switch_to.default_content()
sleep(1)
# chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
# chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
# chrome.find_element_by_class_name('awsui-tabs-icon close').click()
chrome.find_element_by_xpath('//span[@class="awsui-tabs-icon close"]').click()
sleep(1)
def button_click1(self,type=2,el1='el-loading-spinner',el2='//p[text()="办理成功"]'):#保存/提交订单:type=1为保存,否则为提交
if type == 1:
chrome.find_element_by_xpath('//span[text()="保存"]').click()
sleep(1)
locator = (By.CLASS_NAME, f'{el1}')
wait.until_not(ec.presence_of_element_located(locator))
else:
chrome.find_element_by_xpath('//span[text()="提交"]').click()
sleep(1)
locator = (By.XPATH, f'{el2}')
wait.until(ec.presence_of_element_located(locator))
self.closetab()
def query_click(self,menu_name,orderno,el,qrcond='订单号'):#查询出订单并点击
order_link = chrome.find_element_by_xpath('//span[text()="%s"]'%menu_name)
chrome.execute_script("arguments[0].click();", order_link)
sleep(3)
chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
sleep(1)
# 输入采购单号并查询
chrome.find_element_by_xpath('//label[text()="%s"]/parent::div/div/div/div/input'%qrcond).send_keys(orderno)
sleep(1)
chrome.find_element_by_xpath('//label[text()="%s"]/parent::div/div/div/div/input'%qrcond).send_keys(Keys.ENTER)
sleep(3)
# locator = (By.CLASS_NAME, 'el-loading-spinner')
# wait.until_not(ec.presence_of_element_located(locator))
# sleep(1)
#点击采购单
# chrome.find_element_by_xpath(
# '//span[text()="%s"]//parent::div/parent::td//preceding-sibling::td[1]/div/span' % orderno1).click()
element = chrome.find_element_by_xpath('//td[@class="%s"]/div/span'%el)
element.click()
sleep(1)
def commit_order(self,type=2):#保存/提交订单:type=1为保存,否则为提交
self.query_click('普通采购订单',orderno1,'vxe-body--column col_19 col--last col--ellipsis dw-click-cell')
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(0.5)
locator = (By.XPATH, '//span[text()="提交"]')
wait.until(ec.presence_of_element_located(locator))
sleep(2)
# 审批/驳回订单
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
self.button_click1(type)
def switch_loggin(self,usr,pwd):#切换登录
chrome.switch_to.default_content()
sleep(0.5)
chrome.find_element_by_xpath('//span[text()="退出"]').click()
sleep(0.5)
chrome.find_element_by_xpath('//button[text()="确定"]').click()
sleep(1)
chrome.find_element_by_id('input1').clear()
chrome.find_element_by_id('input1').send_keys(usr)
chrome.find_element_by_id('input2').clear()
chrome.find_element_by_id('input2').send_keys(pwd)
chrome.find_element_by_id('input2').send_keys(Keys.ENTER)
locator = (By.XPATH, '//span[text()="退出"]')
wait.until(ec.presence_of_element_located(locator))
def button_click2(self,type,msg='办理成功'):#审批/驳回订单:type=1为审批/其余为驳回订单
if type == 1:
chrome.find_element_by_xpath('//span[text()="审核通过"]').click()
locator = (By.XPATH, '//textarea[@placeholder="意见留言"]')
wait.until(ec.presence_of_element_located(locator))
sleep(0.5)
chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('审核通过')
sleep(0.5)
chrome.find_element_by_xpath('//span[text()="发送"]').click()
locator = (By.XPATH, '//p[text()="%s"]'%msg)
wait.until(ec.presence_of_element_located(locator))
print('订单审核成功')
else:
chrome.find_element_by_xpath('//span[text()="审核驳回"]').click()
locator = (By.XPATH, '//textarea[@placeholder="意见留言"]')
wait.until(ec.presence_of_element_located(locator))
sleep(0.5)
chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('审核驳回')
sleep(0.5)
chrome.find_element_by_xpath('//span[text()="发送"]').click()
locator = (By.XPATH, '//p[text()="发送成功"]')
wait.until(ec.presence_of_element_located(locator))
print('订单驳回成功')
self.closetab()
def approve_order(self,type=1):#审核/驳回订单:type=1为审核通过,否则为审核驳回
self.query_click('普通采购订单',orderno1,'vxe-body--column col_19 col--last col--ellipsis dw-click-cell')
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(0.5)
locator = (By.XPATH, '//span[text()="审核通过"]')
wait.until(ec.presence_of_element_located(locator))
sleep(2)
self.button_click2(type)
class Instore(PurchaseOrder):
def take_over_goods(self,orderno,type=2):
PurchaseOrder.query_click(self,'仓库收货',orderno,'vxe-body--column col_19 col--left col--last col--ellipsis dw-click-cell')
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(0.5)
wait.until(ec.presence_of_element_located((By.XPATH, '//span[text()="收货"]')))
sleep(0.5)
chrome.find_element_by_xpath('//span[text()="收货"]').click()
wait.until(ec.presence_of_element_located((By.XPATH, '//span[text()="确定"]')))
sleep(0.5)
chrome.find_element_by_xpath('//span[text()="确定"]').click()
wait.until(ec.presence_of_element_located((By.XPATH, '//span[text()="提交"]')))
sleep(0.5)
self.button_click3(type)
def button_click3(self,type):
if type == 1:
chrome.find_element_by_xpath('//span[text()="单据撤回"]').click()
elif type == 2:
chrome.find_element_by_xpath('//span[text()="提交"]').click()
wait.until(ec.presence_of_element_located((By.XPATH, '//p[text()="提交成功"]')))
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
print("收货成功")
PurchaseOrder.closetab(self)
else:
chrome.find_element_by_xpath('//span[text()="保存"]').click()
def goods_check(self,orderno,type=2):
PurchaseOrder.query_click(self,'仓库验收',orderno,'vxe-body--column col_19 col--left col--ellipsis dw-click-cell')
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(0.5)
wait.until(ec.visibility_of_element_located((By.XPATH, '//span[text()="提交"]')))
sleep(0.5)
chrome.execute_script(
"document.getElementsByClassName('vxe-table--footer-wrapper body--wrapper')[0].scrollLeft = 2000")
sleep(1)
# chrome.execute_script(
# "document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollTop = %s*30;" % i)
for i in range(1):
#填写生产批号
element = chrome.find_element_by_xpath('(//td[@colid="col_161" and @f="F_PRO_NUM" and @i=%s])' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('el-input__inner').send_keys('ZDH'+orderno)
sleep(1)
# 填写生产日期
element = chrome.find_element_by_xpath('(//td[@colid="col_162" and @f="F_PRODUCR_DATE" and @i=%s])' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('el-input__inner').send_keys(productdate)
sleep(0.5)
chrome.find_element_by_xpath('(//td[@colid="col_161" and @f="F_PRO_NUM" and @i=%s])' % i).click()
sleep(0.5)
# 填写失效日期
element = chrome.find_element_by_xpath('(//td[@colid="col_163" and @f="F_PERIOD_DATE" and @i=%s])' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('el-input__inner').send_keys(expirdate)
sleep(0.5)
chrome.find_element_by_xpath('(//td[@colid="col_161" and @f="F_PRO_NUM" and @i=%s])' % i).click()
sleep(0.5)
#填写灭菌批号
element = chrome.find_element_by_xpath('(//td[@colid="col_165" and @f="F_STE_NUM" and @i=%s])' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('el-input__inner').send_keys('ZDH'+orderno)
sleep(1)
# 填写灭菌日期
element = chrome.find_element_by_xpath('(//td[@colid="col_166" and @f="F_STE_DATE" and @i=%s])' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('el-input__inner').send_keys(productdate)
sleep(0.5)
chrome.find_element_by_xpath('(//td[@colid="col_165" and @f="F_STE_NUM" and @i=%s])' % i).click()
sleep(0.5)
# 填写灭菌失效日期
element = chrome.find_element_by_xpath('(//td[@colid="col_167" and @f="F_STE_LOSE_DATE" and @i=%s])' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(0.5)
chrome.find_element_by_class_name('el-input__inner').send_keys(expirdate)
sleep(0.5)
chrome.find_element_by_xpath('(//td[@colid="col_165" and @f="F_STE_NUM" and @i=%s])' % i).click()
sleep(0.5)
PurchaseOrder.button_click1(self,type)
print('仓库验收成功')