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.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 public.mail1 import send_email1 from public.tools import * # chrome = webdriver.Chrome(chrome_options=opt) def job(type=2): print("这是一个需要执行的任务。。。。。") create_salesorder(type) print("当前线程的个数:", threading.active_count()) time.sleep(1) print("当前线程的信息:", threading.current_thread()) def add_goods(goodsname,chrome): sleep(4) chrome.find_element_by_xpath( '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys( goodsname) sleep(2) chrome.find_element_by_xpath( '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys( Keys.ENTER) sleep(2) #获取页数 # pagecount=chrome.find_element_by_xpath('(// li[ @class ="number"])[16]').text pagecount=10 for i in range(int(pagecount)): # chrome.find_element_by_xpath('//span[text()="添加商品"]').click() # chrome.find_element_by_xpath( # '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys( # goodsname) # chrome.find_element_by_xpath( # '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys( # Keys.ENTER) sleep(1) chrome.find_element_by_xpath( '//th[@class="el-table_18_column_269 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click() #翻页 sleep(2) chrome.find_element_by_xpath('(//button[@class="btn-next is-last"])[6]').click() #点击确定 # chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click() sleep(2) def create_salesorder(type=1): import time pro_path = get_pro_path() start = time.clock() print('订单开始时间', start) # caps = DesiredCapabilities().CHROME # caps["pageLoadStrategy"] = "normal" # complete # caps["pageLoadStrategy"] = "eager" # interactive # caps["pageLoadStrategy"] = "none" # chrome = webdriver.Chrome(desired_capabilities=caps) opt = ChromeOptions() # 创建 Chrome 参数对象 # opt.headless = True # 把 Chrome 设置成无界面模式,windows/Linux 皆可 opt.headless = False # 把 Chrome 设置成无界面模式,windows/Linux 皆可 opt.add_argument('--start-maximized') opt.add_argument('--window-size=1280x1024') # chrome = Chrome(options=opt) # 创建无界面对象 # chrome = WebChrome(chrome_options=opt) # chrome = WebChrome(chrome_options=opt) chrome=webdriver.Chrome(chrome_options=opt) try: chrome.implicitly_wait(20) chrome.get("http://10.17.65.200:8088/portal/") # chrome.get("http://10.17.65.207:8088/uat/r/w") sleep(2) chrome.implicitly_wait(30) # chrome.maximize_window() chrome.find_element_by_id('input1').clear() chrome.find_element_by_id('input1').send_keys('admin') chrome.find_element_by_id('input2').clear() chrome.find_element_by_id('input2').send_keys('Gyxc1234') chrome.find_element_by_id('input2').send_keys(Keys.ENTER) while True: try: if(chrome.find_element_by_xpath('//span[text()="退出"]').is_displayed()==True): break except: continue #切换所属公司 chrome.find_element_by_class_name('changeCom').click() sleep(1) chrome.find_element_by_xpath('//span[text()="国药集团北京医疗器械有限公司"]/following-sibling::button').click() sleep(1) chrome.find_element_by_xpath('// button[text() = "确定"]').click() sleep(1) # chrome.find_element_by_xpath('//div[text()="销售管理"]').click() # actions = ActionChains(chrome) # actions.move_to_element(chrome.find_element_by_xpath('//div[text()="销售业务"]')).perform() # chrome.find_element_by_xpath('//span[text()="销售订单"]').click() 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(4) chrome.find_element_by_xpath('//span[text()="新建"]').click() sleep(4) chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]')) #获取订单号 orderno=chrome.find_element_by_xpath('//div[text() = "销售订单号 "]/following-sibling::div/span').text print(orderno) # chrome.switch_to.default_content() sleep(4) # while True: # try: # if chrome.find_element_by_xpath('//div[text()="订单公司名称 "]').is_displayed(): # print(chrome.find_element_by_xpath('//div[text()="订单公司名称 "]').text) # break # except: # continue print(chrome.find_element_by_xpath('//div[text()="订单公司名称 "]').text) sleep(2) # chrome.find_element_by_xpath( # '//div[text()="订单公司名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click() # chrome.find_element_by_xpath('//input[@placeholder="模糊检索:公司名称,公司编码"]').send_keys('国药集团北京') # chrome.find_element_by_xpath('//input[@placeholder="模糊检索:公司名称,公司编码"]').send_keys(Keys.ENTER) # chrome.find_element_by_xpath('(//span[@class="el-radio__inner"])[1]').click() # chrome.find_element_by_xpath('//span[@class="ensureBtn"]/button').click() # chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]').click() chrome.find_element_by_xpath('//div[text()="出库仓库 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click() chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库编码,仓库名称,是否传WMS,所属公司名称"]').send_keys('北京强生非') chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库编码,仓库名称,是否传WMS,所属公司名称"]').send_keys(Keys.ENTER) # chrome.find_element_by_xpath('//span/input[@type="radio" and @value="03105272b49986351ef7eb2930b5454de"]').click() btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="03105272b49986351ef7eb2930b5454de"]') chrome.execute_script("arguments[0].click();", btn_div) 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() chrome.find_element_by_xpath( '//div[text()="合同号 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click() chrome.find_element_by_xpath('//input[@placeholder="模糊检索:合同号,合同协议号,对方编码,项目名称,项目编码,业态编码,参考部门,参考部门编码,参考业务员,参考业务员编码,产品线名称,产品线编码,合同类型,合同属性"]').send_keys('38443') chrome.find_element_by_xpath('//input[@placeholder="模糊检索:合同号,合同协议号,对方编码,项目名称,项目编码,业态编码,参考部门,参考部门编码,参考业务员,参考业务员编码,产品线名称,产品线编码,合同类型,合同属性"]').send_keys(Keys.ENTER) 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() chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[3]').click() sleep(2) #客户名称 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( '1000486') sleep(2) chrome.find_element_by_xpath( '//input[@placeholder="模糊检索:客户编码,客户名称,收货地址号,收货地址信息,公司编码,货币码,税率/税区,客户分类,联系人,联系人电话"]').send_keys( Keys.ENTER) sleep(2) chrome.find_element_by_xpath( '//div[@class="multiple-header number_col" and text()="1000486"]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click() chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[4]').click() sleep(2) #业务员名称 chrome.find_element_by_xpath( '//div[text()="业务员名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click() sleep(2) chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,业务部门编码,部门类型编码"]').send_keys('杨春刚') sleep(2) chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,业务部门编码,部门类型编码"]').send_keys(Keys.ENTER) sleep(2) chrome.find_element_by_xpath('(//div[text()="杨春刚"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click() sleep(2) chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[4]').click() #其他信息页签 chrome.find_element_by_xpath('//div[text()="其他信息"]').click() sleep(2) chrome.find_element_by_xpath('//div[@cid="AWSUI.SwitchButton"]//div/div/div/div/span[1]').click() # 子表信息录入 chrome.find_element_by_xpath('//div[text()="主体信息"]').click() # 点击添加商品弹出添加商品子窗口 for i in range(1): chrome.find_element_by_xpath('//span[text()="添加商品"]').click() add_goods('PTCA',chrome) chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click() sleep(20) # for i in range(1): # chrome.find_element_by_xpath('//span[text()="添加商品"]').click() # add_goods('PTCA', chrome) # chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click() # sleep(10) # chrome.find_element_by_xpath('//span[text()="添加商品"]').click() # chrome.find_element_by_xpath( # '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys( # 'PTCA') # chrome.find_element_by_xpath( # '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys( # Keys.ENTER) # sleep(1) # chrome.find_element_by_xpath('//th[@class="el-table_18_column_229 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click() # chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click() # sleep(2) # sleep(6) while True: try: chrome.find_element_by_xpath('//div[@class="el-loading-spinner"]').is_displayed() continue except: break for i in range(1,101): sleep(2) element = chrome.find_element_by_xpath('(//td[@colid="col_177"])[%s]'%i) chrome.execute_script("arguments[0].click();", element) # element=chrome.find_element_by_xpath('(//td[@colid="col_177"])[%s]'%i) # element.click() # element=chrome.find_element_by_xpath('//span[@class="form-grid-check-num" and text()="%s"]/ancestor::td/following-sibling::td[5]'%i) # element.click() sleep(2) # element.send_keys("1") # chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='1'") chrome.find_element_by_class_name('awsui-input-number-right').send_keys('1') # chrome.find_element_by_xpath('//td[@colid="col_177"]/div/div').send_keys('1') sleep(2) chrome.find_element_by_xpath('(//td[@colid="col_178"])[%s]'%i).click() # element = chrome.find_element_by_xpath('(//td[@colid="col_178"])[%s]' % i) # chrome.execute_script("arguments[0].click();", element) # element = chrome.find_element_by_xpath( # '//span[@class="form-grid-check-num" and text()="%s"]/ancestor::td/following-sibling::td[6]' % i) # element.click() sleep(2) chrome.execute_script( "document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollTop = %s*30;" % i) sleep(2) # print('200条输入完毕') # chrome.find_element_by_xpath('//button[@ class="vxe-pager--next-btn" and @title="下一页"]').click() # # sleep(2) # chrome.execute_script( # "document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollTop=0;") #输入第二页数据 # for i in range(1,51): # # # element = chrome.find_element_by_xpath('(//td[@colid="col_177"])[%s]'%i) # # chrome.execute_script("arguments[0].click();", element) # # # element=chrome.find_element_by_xpath('(//td[@colid="col_177"])[%s]'%i) # # element.click() # element=chrome.find_element_by_xpath('//span[@class="form-grid-check-num" and text()="%s"]/ancestor::td/following-sibling::td[5]'%i) # element.click() # sleep(2) # # element.send_keys("1") # # chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='1'") # chrome.find_element_by_class_name('awsui-input-number-right').send_keys('1') # # chrome.find_element_by_xpath('//td[@colid="col_177"]/div/div').send_keys('1') # sleep(2) # # chrome.find_element_by_xpath('(//td[@colid="col_178"])[%s]'%i).click() # # element = chrome.find_element_by_xpath('(//td[@colid="col_178"])[%s]' % i) # # chrome.execute_script("arguments[0].click();", element) # element = chrome.find_element_by_xpath( # '//span[@class="form-grid-check-num" and text()="%s"]/ancestor::td/following-sibling::td[6]' % i) # element.click() # sleep(2) print('ok') #滚动条右拉 # document.getElementsByClassName('vxe-table--footer-wrapper body--wrapper')[0].scrollLeft = 5000 # 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=0;") # for i in range(1,201): # element = chrome.find_element_by_xpath('(//td[@colid="col_197"])[%s]'%i) # element.click() # sleep(2) # chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'") # sleep(2) # element = chrome.find_element_by_xpath('(//td[@colid="col_198"])[%s]'%i) # element.click() # sleep(2) # chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'") # sleep(2) # lock = threading.Lock() # lock.acquire() # start = time.clock() #方案一============================开始 if type==1: import datetime now = datetime.datetime.now() one_minutes_later = now + datetime.timedelta(minutes=1) now = now.strftime('%Y-%m-%d %H:%M') one_minutes_later = one_minutes_later.strftime('%Y-%m-%d %H:%M') # print('bbbbbbbb'+one_minutes_later) while True: now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M') # print('变化的时间' + now) if now == one_minutes_later: print('时间到了') # global start start = time.clock() chrome.find_element_by_xpath('//span[text()="提交"]').click() break # 方案一============================结束 #方案二===============开始 if type==2: m=get_time_m() #当前时间的分钟 m1=get_submit_time1(m)#计划提交时间的分钟 print('销售订单计划提交时间的分钟',m1) while True: m2=get_time_m() #循环获取当前的分 # sleep(30) if (m2==m1): # chrome.find_element_by_xpath('//span[text()="保存"]').click() start = time.clock() chrome.find_element_by_xpath('//span[text()="提交"]').click() break #方案二===============结束 chrome.implicitly_wait(0) while True: try: if chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini awsui-button awsui-button--primary"]').is_displayed()==True: chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini awsui-button awsui-button--primary"]').click() break except: continue while True: try: if chrome.find_element_by_xpath('//p[text()="办理成功"]').is_displayed()==True: # print('订单完成了') break # else: # print('共享任务创建成功的元素没有出现') except: continue # lock.release() # sleep(2) # chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini awsui-button awsui-button--primary"]//span[text()="确定"]').click() chrome.switch_to.default_content() chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]')) # sleep(60) # while True: # try: # # if chrome.find_element_by_xpath('(//span[text()="%s"])[2]'%orderno).is_displayed()==True: # if chrome.find_element_by_xpath( # '//span[text() = "1"]/ancestor-or-self::td/following-sibling::td/div/span').is_displayed() == True: # # print('aaaaaaaaaaaaaaaaaaaaaaaa', chrome.find_element_by_xpath( # # '//span[text() = "1"]/ancestor-or-self::td/following-sibling::td/div/span').text) # break # except: # continue chrome.implicitly_wait(30) print('销售订单创建完成') end = time.clock() print(start, end) imgInfo = getErrorPhoto(chrome) imgName = imgInfo[0] image_path = imgInfo[1] info=orderno+'执行耗时'+str(end - start) now = get_time() writeFile_append(pro_path + '/logs/catalina.out', info) send_email1(image_path, info) print('CPU执行时间: ', end - start) except Exception as e: print('出现异常') # 将日志写入到文件中单独存储 pro_path = get_pro_path() traceback.print_exc() imgInfo = getErrorPhoto(chrome) imgName = imgInfo[0] image_path = imgInfo[1] print(imgName, image_path) print(repr(e)) info = repr(e) now = get_time() writeFile_append(pro_path + '/logs/logerror%s.txt' % now, info) # send_email1(image_path, info) if __name__ == "__main__": # 创建多线程时, 需要制定该线程执行的任务.name线程名字 target目标函数名 # t1 = threading.Thread(target=job,name="job1") # t2 = threading.Thread(target=job,name="job2") # t1.start() # t2.start() # opt = ChromeOptions() # 创建 Chrome 参数对象 # # opt.headless = True # 把 Chrome 设置成无界面模式,windows/Linux 皆可 # opt.headless = False # 把 Chrome 设置成无界面模式,windows/Linux 皆可 # opt.add_argument('--start-maximized') # opt.add_argument('--window-size=1280x1024') # # chrome = Chrome(options=opt) # 创建无界面对象 # chrome = WebChrome(chrome_options=opt) # airtest中的类 count=10 for i in range(count): t = threading.Thread(target=job) t.start() t.join() def start1(): count = 1 for i in range(count): t = threading.Thread(target=job) t.start() t.join() # print(threading.active_count()) # print("程序执行结束.....") # create_salesorder()