Commit e3f3d11a authored by 章 登恒's avatar 章 登恒
Browse files

commit

parent 5be6c810
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from public.tools import wait
def settle_accounts_point(chrome,product_id,old_type="中心库入库结算",new_type="",flag=1):
if (flag==1):
wait()
chrome.find_element_by_xpath('//span[text()="%s"]'%old_type).click()
wait()
chrome.find_element_by_xpath('//span[text()="批量导入"]').click()
wait(2)
chrome.find_element_by_xpath('//input[@id="basic_goodsName" and @placeholder="编号/名称/简拼"]').send_keys(product_id)
wait()
chrome.find_element_by_xpath('(//span[text()="查 询"])[2]').click()
wait()
# 勾选产品前面的复选框
try:
chrome.find_element_by_xpath('//td[@title="%s"]/preceding-sibling::td/label/span/input' % product_id).click()
wait()
chrome.find_element_by_xpath('(//span[text()="确 定"])[1]').click()
except:
print('没查询出产品')
chrome.find_element_by_xpath('(//span[text()="取 消"])[1]').click()
wait()
elif (flag==2):
wait()
chrome.find_element_by_xpath('//span[text()="%s"]' % old_type).click()
wait()
chrome.find_element_by_id('form_item_goodsName').send_keys(product_id)
wait()
chrome.find_element_by_xpath('(//span[text()="查 询"])').click()
try:
chrome.find_element_by_xpath('//input[@type="checkbox"]').click()
except:
return
wait()
chrome.find_element_by_xpath('//span[contains(text(),"批量转")]').click()
wait()
# chrome.find_element_by_xpath('//label[text()="调整后规则"]/parent::div/following-sibling::div').click()
chrome.find_element_by_xpath('(//span[@class="ant-select-selection-item"])[2]').click()
wait()
chrome.find_element_by_xpath('//div[text()="中心库出库结算"]').click()
wait()
chrome.find_element_by_xpath('// span[text() = "确 定"]').click()
def nGuiBrowserObject():
opt = ChromeOptions() # 创建 Chrome 参数对象
opt.headless = False # 把 Chrome 设置成无界面模式,windows/Linux 皆可
# opt.headless = True # 无界面
opt.add_argument('--start-maximized')
opt.add_argument('--window-size=1920x887')
chrome = webdriver.Chrome(options=opt,executable_path="c:/python34/chromedriver.exe") # 创建无界面对象
return chrome
#打开网页
def openBrowser(url):
# chrome = webdriver.Chrome() #因为firefox是在此处定义的
chrome=nGuiBrowserObject()
chrome.implicitly_wait(10) #隐式等待 10秒
chrome.get(url)
return chrome #所以函数必须返回firefox,后面的脚本才能使用
#dbshop前台登录
def logIn(chrome,username,password):
chrome.find_element_by_xpath('//input[@placeholder="请输入用户名"]').clear()
chrome.find_element_by_xpath('//input[@placeholder="请输入用户名"]').send_keys(username)
# chrome.find_element_by_xpath('//input[@placeholder="请输入密码"]').send_keys(password)
chrome.find_element_by_xpath('//span[text()="登 录"]').click()
#dbshop前台修改密码
def changePassword(firefox,password,newPassword):
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("账户信息").click()
firefox.find_element_by_link_text("密码修改").click()
firefox.find_element_by_id("old_user_password").send_keys(password)
firefox.find_element_by_id("user_password").send_keys(newPassword)
firefox.find_element_by_id("user_password_con").send_keys(newPassword)
firefox.find_element_by_xpath('//button[@type="submit"]').click()
#dbshop前台退出
def logOut(firefox):
firefox.find_element_by_link_text("退出").click()
#dbshop后台登录
def logInAdmin(firefox):
firefox.find_element_by_id("user_name").send_keys("admin")
firefox.find_element_by_id("user_passwd").send_keys("123456")
firefox.find_element_by_xpath('//button[@class="btn"]').click()
#dbshop进入后台二级菜单
def enterMenu3(chrome,menu1,menu2,menu3):
wait()
chrome.find_element_by_xpath(menu1).click()
wait()
chrome.find_element_by_xpath(menu2).click()
wait()
chrome.find_element_by_xpath(menu3).click()
wait()
# #dbshop进入后台三级菜单
# def enterMenu3(firefox,menu1,menu2,menu3):
# firefox.find_element_by_link_text(menu1).click()
# from selenium.webdriver.common.action_chains import ActionChains # 导入ActionChains类
# mouse = ActionChains(firefox) # 以浏览器为参数,实例化一个对象mouse,用于模拟鼠标操作浏览器
# element = firefox.find_element_by_link_text(menu2) # 先定位到要操作的对象element
# mouse.move_to_element(element).perform() # 鼠标移动到元素element上,perform()是立即的意思
# firefox.find_element_by_link_text(menu3).click()
#dbshop项目页面切换
def switch_page(a,firefox):
firefox.switch_to.window(firefox.window_handles[a-1])
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.image import MIMEImage
send_usr = '18627022503@163.com' # 发件人
send_pwd = 'EBJFCICTFEONFQEO' # 授权码,邮箱设置
reverse = '18627022503@163.com' # 接收者
content = '2022<p>python官网链接如下:</p>' \
'<p><a href="https://www.python.org">python</a></p>'
#content 内容设置
html_img = '<p>{content}<br><img src="cid:image1"></br></p>' # html格式添加图片
email_server = 'smtp.163.com'
email_title = '脚本执行成功了' # 邮件主题
def send_email1(image_path,email_title):
msg = MIMEMultipart() # 构建主体
msg['Subject'] = Header(email_title,'utf-8') # 邮件主题
msg['From'] = send_usr # 发件人
msg['To'] = Header('xhs','utf-8') # 收件人--这里是昵称
# msg.attach(MIMEText(content,'html','utf-8')) # 构建邮件正文,不能多次构造
attchment = MIMEApplication(open(r'D:/test.xlsx','rb').read()) # 文件
attchment.add_header('Content-Disposition','attachment',filename='test.png')
msg.attach(attchment) # 添加附件到邮件
# f = open("D:\\PycharmProjects\\cmic_python_JobLog\\xhsmail\\2023-04-30_090212.png", 'rb') #打开图片
f = open(image_path, 'rb') #打开图片
msgimage = MIMEImage(f.read())
f.close()
msgimage.add_header('Content-ID', '<image1>') # 设置图片
msg.attach(msgimage)
msg.attach(MIMEText(html_img,'html','utf-8')) # 添加到邮件正文
try:
smtp = SMTP_SSL(email_server) #指定邮箱服务器
smtp.ehlo(email_server) # 部分邮箱需要
smtp.login(send_usr,send_pwd) # 登录邮箱
smtp.sendmail(send_usr,reverse,msg.as_string()) # 分别是发件人、收件人、格式
smtp.quit() # 结束服务
print('邮件发送完成--')
except:
print('发送失败')
# if __name__ == '__main__':
# send_email1()
import subprocess
from datetime import timedelta, date
def IsFileContentRight(url):
f = open(url, "r", encoding="utf-8") # 从文件中读取内容
str1=f.read()
import re
if (re.search(",",str1)!=None or re.search(":",str1)!=None):
return False
else:
f.close()
f = open(url, "r", encoding="utf-8") # 从文件中读取内容
mylist1 = f.readlines()
x = 0
j = 0
count=0
for i in mylist1:
if (re.match("子任务数:", i) != None):
print("找到了")
j = i[5:6]
print('子任务数', j)
break
for i in mylist1:
if (re.match("任务", i) != None):
print('找到了%s个任务' % x)
x = x + 1
print("真实子任务个数", x)
for i in mylist1:
if (re.match("实际工时", i) != None):
count=i.count(",")
count = int(count) + 1
# break
if (j == str(x)==str(count)):
return True
else:
return False
def End_Chrome_Progress():
subprocess.call("TASKKILL /f /IM CHROME.EXE")
subprocess.call("TASKKILL /f /IM CHROMEDRIVER.EXE")
# 读取文件所有内容
def readFile_all(url):
f = open(url, "r", encoding="utf-8") # 从文件中读取内容
t = f.read()
f.close()
return t
# 读取文件内容的函数,需要1个参数文件地址
def readFile(f):
# f = open(url, "r") # 从文件中读取内容
t = f.readline()
# f.close()
return t
# 覆盖写入
def writeFile(url, text):
f = open(url, "w", encoding="utf-8")
f.write(text)
f.close()
# 追加写入
def writeFile_append(url, text):
f = open(url, "a", encoding="utf-8")
f.write(get_time_hms()+":::"+text+'\n')
f.close()
# 读取文件内容的函数,对内容进行处理,去掉冒号前面的内容
def readFileContent(url):
f = open(url, "r", encoding="UTF-8") # 从文件中读取内容
t = f.readlines()
path1 = get_pro_path()
writeFile(path1 + '/add/Everydaylog.txt', "") # 先清空所有内容
writeFile(path1 + '/update/update_Everyday_log.txt', "") # 先清空所有内容
import re
for i in t:
if i == '\n':
break
mylist = re.split(":", i)
# print(mylist)
if mylist[0] == "实际工时":
mylist[1] = mylist[1].replace('\n', "")
writeFile_append(path1 + '/add/Everydaylog.txt', mylist[1])
writeFile_append(path1 + '/update/update_Everyday_log.txt', mylist[1])
f.close()
return t
def get_time(type=1):
import time
if (type==1):
t = time.strftime("%Y-%m-%d", time.localtime())
else:
t = time.strftime("%Y%m", time.localtime())
# t = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
return t
def get_time_add(days_aa):
import time
# t = time.strftime("%Y-%m-%d", datetime.datetime.now())
tomorrow = (date.today() + timedelta(days=days_aa)).strftime("%Y-%m-%d")
return tomorrow
def get_time_hms():
import time
# t = time.strftime("%Y-%m-%d", time.localtime())
timedelta(days=1)
t = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
return t
def get_localhost_ip():
import socket
ip = socket.gethostbyname(socket.gethostname())
ip = ip[0:5]
print("http://" + ip)
return "http://" + ip
# 获取当前项目的根目录的路径
def get_pro_path():
import os
# print('根据当前文件获取当前文件所在目录的路径', os.path.dirname(__file__))
curPath = os.path.abspath(os.path.dirname(__file__)) # 获取当前文件的所在目录的绝对路径
# print(curPath) # C:\Users\xhs\Desktop\dbshop项目相关文档2\dbshop1\main
# #将当前文件的所在目录的绝对路径进行分离,分离成C:\Users\xhs\Desktop\dbshop项目相关文档2\dbshop1 和main,存到元组中
print(os.path.split(curPath))
rootPath = os.path.split(curPath)[0] # [0]表示元组中的为一个元素
# print('当前项目的根目录', rootPath)
return rootPath
# 截图
def getErrorPhoto(chrome,type=1):
#1正常截图 2错误截图
import time
if type==1:
imgName = time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".png"
pro_path = get_pro_path() # 获取项目的根目录的路径
image_path = pro_path + "//logs//" + imgName
chrome.get_screenshot_as_file(image_path)
return imgName, image_path
else:
imgName = time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".png"
pro_path = get_pro_path() # 获取项目的根目录的路径
image_path = pro_path + "//logs_error//" + imgName
chrome.get_screenshot_as_file(image_path)
return imgName, image_path
#
def is_file_exist(filename):
try:
f = open(filename, 'r', encoding='utf-8')
except:
return False
else:
return True
#获取时间的分
def get_time_m():
import time
from datetime import datetime
nows = int(time.time())
# timestamp = 1591239600
dt = datetime.fromtimestamp(nows)
# print(dt.minute, dt.second)
return dt.minute
# if dt.minute == 0 and dt.second == 0:
# print('s ')
# elif dt.minute == 50 and dt.second == 0:
# print('s ')
#判断时间区间,制定提交时间
def get_submit_time(m):
if m>=0 and m<=10:
return 20
elif m>=11 and m<=20:
return 30
elif m>=21 and m<=30:
return 40
elif m>=31 and m<=40:
return 50
elif m>=41 and m<=50:
return 59
elif m>=51 and m<=59:
return 10
else:
return m+10
#判断时间区间,制定提交时间
#判断时间区间,制定提交时间
def get_submit_time1(m):
if m >= 0 and m <= 30:
return 40
elif m >30 and m <= 59:
return 10
else:
return m + 20
if __name__ == '__main__':
# End_Chrome_Progress()
# get_localhost_ip()
# readFileContent(r'..\add\main_Everydaylog.txt')
print(IsFileContentRight(r'..\add\main_Everydaylog.txt'))
\ No newline at end of file
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 mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def create_salesorder(type=1):
try:
import time
pro_path = get_pro_path()
start = time.clock()
# 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.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(2)
chrome.find_element_by_xpath('//span[text()="新建"]').click()
sleep(2)
# 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(2)
# # 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('//button[@class="el-button el-button--primary el-button--mini"]').click()
# # 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="模糊检索:员工编码,员工名称,部门编码,部门名称"]').send_keys('chenshuheng')
# chrome.find_element_by_xpath('//input[@placeholder="模糊检索:员工编码,员工名称,部门编码,部门名称"]').send_keys(
# Keys.ENTER)
# chrome.find_element_by_xpath(
# '(//div[text()="chenshuheng"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
# chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[1]').click()
#
# #手术类型
# chrome.find_element_by_xpath('(//input[@placeholder="请选择" and @type="text"])').click()
# sleep(1)
# chrome.find_element_by_xpath('//li[text()="初次手术"]').click()
# sleep(1)
# #手术种类
# chrome.find_element_by_xpath('(//input[@placeholder="请选择" and @type="text"])[2]').click()
# sleep(1)
# chrome.find_element_by_xpath('//li[text()="髋关节"]').click()
# sleep(1)
# chrome.find_element_by_xpath('//label[text()="手术日期 "]/following-sibling::div/div').click()
# sleep(1)
# chrome.find_element_by_xpath('//div[ @class ="el-date-table-cell"] // span[text()="31"]').click()
#
# #客户信息页签
# 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('北京大学第三医院')
# chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称"]').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="02f94bb93be972567166f428524aa3b43"]')
# chrome.execute_script("arguments[0].click();", btn_div)
# chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[3]').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('北京大学第三医院')
# chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客商名称"]').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="0c4d395678c596b20aa6c2a2fef3483d4"]')
# chrome.execute_script("arguments[0].click();", btn_div)
# chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[4]').click()
#
# # 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"])[4]').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('杨春刚')
# # chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,业务部门编码,部门类型编码"]').send_keys(Keys.ENTER)
# # chrome.find_element_by_xpath('(//div[text()="杨春刚"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
# # chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[4]').click()
# # #其他信息页签
# # chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
# # chrome.find_element_by_xpath('//div[@cid="AWSUI.SwitchButton"]//div/div/div/div/span[1]').click()
# # 子表信息录入
# chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
# chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品名称"]').send_keys(
# '10214724')
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品名称"]').send_keys(
# Keys.ENTER)
# sleep(1)
# chrome.find_element_by_xpath('(//span[@class="el-checkbox__inner"])[4]').click()
# chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[4]').click()
# sleep(3)
# # 滚动条右拉
# # chrome.execute_script("document.getElementsByClassName('vxe-table--footer-wrapper body--wrapper')[0].scrollLeft = 2000");
#
# element=chrome.find_element_by_xpath('//td[@colid="col_75"]')
# 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')
# sleep(2)
# chrome.find_element_by_xpath('//td[@colid="col_76"]').click()
# #滚动条右拉
# # 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");
# # element = chrome.find_element_by_xpath('//td[@colid="col_197"]')
# # element.click()
# # sleep(6)
# # chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# # sleep(2)
# # element = chrome.find_element_by_xpath('//td[@colid="col_198"]')
# # element.click()
# # sleep(6)
# # chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# # sleep(2)
# # lock = threading.Lock()
# # lock.acquire()
# #方案一============================开始
# # if user_count<=5:
# 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('时间到了')
# chrome.find_element_by_xpath('//span[text()="提交"]').click()
# break
# # 方案一============================结束
# #方案二===============开始
# if type==2:
# m=get_time_m() #当前时间的分钟
# m1=get_submit_time(m)#计划提交时间的分钟
# while True:
# m2=get_time_m() #循环获取当前的分
# # sleep(60)
# if (m2==m1):
# chrome.find_element_by_xpath('//span[text()="提交"]').click()
# break
# #方案二===============结束
# # lock.release()
# sleep(2)
# # chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]').click()
# # chrome.switch_to.default_content()
# # chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
# # sleep(20)
# while True:
# try:
# if chrome.find_element_by_xpath('//span[text()="%s"]'%orderno).is_displayed()==True:
# print('//span[text()="%s"]'%orderno)
# break
# except:
# continue
#进入手术配货单
chrome.switch_to.default_content()
chrome.find_element_by_xpath('//span[@class="awsui-tabs-icon close"]').click()
sleep(1)
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('//label[text()="请领单号"]/parent::div/div/div/div/input').send_keys('QLD23082800017B')
sleep(1)
chrome.find_element_by_xpath('//label[text()="请领单号"]/parent::div/div/div/div/input').send_keys(Keys.ENTER)
sleep(1)
sleep(1)
text1=chrome.find_element_by_xpath('(//span[text()="PHD23082800007B"])[2]').text
print(text1)
element = chrome.find_element_by_xpath('(//span[@class="vxe-checkbox--icon vxe-checkbox--unchecked-icon"])[2]')
chrome.execute_script("arguments[0].click();", element)
sleep(1)
chrome.find_element_by_xpath('//span[text()="批量提交"]').click()
sleep(1)
chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]/span[text()="确定"]').click()
print('手术请领单创建完成')
end = time.clock()
print(start, end)
print('CPU执行时间: ', end - start)
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)
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=1
for i in range(count):
t = threading.Thread(target=job)
t.start()
t.join()
def start1():
count = 5
for i in range(count):
t = threading.Thread(target=job)
t.start()
t.join()
# print(threading.active_count())
# print("程序执行结束.....")
# create_salesorder()
import threading
import time
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 *
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def create_salesorder():
import time
start = time.clock()
# 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.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').send_keys('admin')
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_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()
chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
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")]'))
# 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"])[3]').click()
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('40080')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:合同号,合同协议号,对方编码,项目名称,项目编码,业态编码,参考部门,参考部门编码,参考业务员,参考业务员编码,产品线名称,产品线编码,合同类型,合同属性"]').send_keys(Keys.ENTER)
chrome.find_element_by_xpath('//div[@class="multiple-header string_col" and text()="40080"]/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()
#客户名称
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('(//div[text()="北京大学第三医院"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[4]').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('杨春刚')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,业务部门编码,部门类型编码"]').send_keys(Keys.ENTER)
chrome.find_element_by_xpath(
'(//div[text()="杨春刚"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button)[13]').click()
#其他信息页签
chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
chrome.find_element_by_xpath('//div[@cid="AWSUI.SwitchButton"]//div/div/div/div/span[1]').click()
# 子表信息录入
chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys(
'10006179')
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys(
Keys.ENTER)
chrome.find_element_by_xpath('(//span[@class="el-checkbox__inner"])[4]').click()
chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[6]').click()
sleep(10)
element=chrome.find_element_by_xpath('//td[@colid="col_177"]')
element.click()
sleep(6)
# element.send_keys("1")
chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='1'");
sleep(3)
#滚动条右拉
# 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");
element = chrome.find_element_by_xpath('//td[@colid="col_197"]')
element.click()
sleep(6)
chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'");
sleep(2)
element = chrome.find_element_by_xpath('//td[@colid="col_198"]')
element.click()
sleep(6)
chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'");
sleep(2)
chrome.find_element_by_xpath('//span[text()="提交"]').click()
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()
while True:
try:
if chrome.find_element_by_xpath('//span[text()="新建"]').is_displayed()==True:
break
except:
continue
print('销售订单创建完成')
end = time.clock()
print(start, end)
print('CPU执行时间: ', end - start)
if __name__ == "__main__":
# 创建多线程时, 需要制定该线程执行的任务.name线程名字 target目标函数名
# t1 = threading.Thread(target=job,name="job1")
# t2 = threading.Thread(target=job,name="job2")
# t1.start()
# t2.start()
for i in range(1):
t = threading.Thread(target=job)
t.start()
# print(threading.active_count())
# print("程序执行结束.....")
# create_salesorder()
import threading
import time
from airtest.core.api import *
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import *
def job3():
print("这是一个需要执行的任务。。。。。")
from testcase.od.多明细.销售订单_多明细100 import create_salesorder
create_salesorder(2)
print("当前线程的个数:", threading.active_count() )
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def job1():
print("这是一个需要执行的任务。。。。。")
# from testcase.od.多明细.调拨出库单多明细100 import create_salesorder1
from testcase.od.多明细.手术请领单多明细100 import create_salesorder
create_salesorder(2)
print("当前线程的个数:", threading.active_count() )
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
if __name__ == "__main__":
# 创建多线程时, 需要制定该线程执行的任务.name线程名字 target目标函数名
# t1 = threading.Thread(target=create_salesorder,name="job1")
# t2 = threading.Thread(target=create_salesorder1,name="job2")
# t1.start()
# t2.start()
count = 25
# semaphore = threading.Semaphore(value=1)
# for i in range(count):
# if i<15:
# t = threading.Thread(target=job3)
# t.start()
# if i>=15:
# t = threading.Thread(target=job1)
# t.start()
# # t.join()
for i in range(count):
t = threading.Thread(target=job1)
t.start()
print(threading.active_count())
# sleep(30)
# sys.exit(0)
# print("程序执行结束.....")
# for i in range(10):
# from testcase.od.销售订单 import *
# start1()
This diff is collapsed.
This diff is collapsed.
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 mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def add_goods(goodsname,chrome):
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,厂家物料编码,件包数"]').send_keys(
goodsname)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,厂家物料编码,件包数"]').send_keys(
Keys.ENTER)
#获取页数
# pagecount=chrome.find_element_by_xpath('(// li[ @class ="number"])[16]').text
pagecount=10
for i in range(int(pagecount)):
sleep(1)
chrome.find_element_by_xpath(
'//th[@class="el-table_18_column_157 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
#翻页
chrome.find_element_by_xpath('(//button[@class="btn-next is-last"])[6]').click()
sleep(2)
def create_salesorder(type=1):
try:
import time
pro_path = get_pro_path()
start = time.clock()
# 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.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(2)
#输入配货单号
chrome.find_element_by_xpath('(//input[@class="el-input__inner"])[2]').send_keys('PHD23082800006A')
sleep(2)
chrome.find_element_by_xpath('(//input[@class="el-input__inner"])[2]').send_keys(Keys.ENTER)
sleep(2)
# chrome.find_element_by_xpath('//td[@class="vxe-body--column col_19 col--center col--last col--ellipsis dw-click-cell"]/div/span').click()
# chrome.find_element_by_xpath('//span[text()="PHD23082800006A"]').click()
chrome.find_element_by_xpath('//td[@class="vxe-body--column col_19 col--center col--last col--ellipsis dw-click-cell"]/div/span').click()
# 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"])[2]').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.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_xpath('//button[text()="自动配货"]').click()
sleep(2)
chrome.find_element_by_xpath('//span[text()="分配批次"]').click()
sleep(2)
chrome.execute_script(
'document.getElementsByClassName("body")[0].scrollTop = "300";')
# 滚动条右拉
chrome.execute_script(
"document.getElementsByClassName('vxe-table--footer-wrapper body--wrapper')[0].scrollLeft = 1200");
for i in range(1,101):
element = chrome.find_element_by_xpath('(//td[@colid="col_124"])[%s]'%i)
element.click()
sleep(2)
chrome.find_element_by_class_name('awsui-input-number-right').send_keys('1')
sleep(2)
chrome.find_element_by_xpath('//td[@colid="col_125"]').click()
sleep(1)
# element = chrome.find_element_by_xpath('//td[@colid="col_159"]')
# element.click()
# sleep(3)
# element.send_keys("1")
# chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='1'")
# chrome.find_element_by_xpath(
# '//div[@class="el-input el-input--fullScreenSize el-input--prefix el-input--suffix dataDialog awsui-input dataDialog"]/div/input').send_keys(
# '23072800OP0237')
# sleep(1)
# chrome.find_element_by_xpath('//td[@colid="col_160"]').click()
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,厂家物料编码,件包数"]').send_keys(
# '10006179')
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,厂家物料编码,件包数"]').send_keys(
# Keys.ENTER)
# chrome.find_element_by_xpath('(//span[@class="el-checkbox__inner"])[4]').click()
# chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click()
# sleep(3)
# 滚动条右拉
# 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')
# sleep(1)
# chrome.find_element_by_xpath('//td[@colid="col_166"]').click()
# sleep(1)
#滚动条右拉
# 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");
# element = chrome.find_element_by_xpath('//td[@colid="col_197"]')
# element.click()
# sleep(6)
# chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# sleep(2)
# element = chrome.find_element_by_xpath('//td[@colid="col_198"]')
# element.click()
# sleep(6)
# chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# sleep(2)
# lock = threading.Lock()
# lock.acquire()
#方案一============================开始
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('时间到了')
start = time.clock()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
# sleep(3)
# chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]').click()
break
# 方案一============================结束
#方案二===============开始
if type==2:
m=get_time_m() #当前时间的分钟
m1=get_submit_time(m)#计划提交时间的分钟
while True:
m2=get_time_m() #循环获取当前的分
sleep(10)
if (m2==m1):
start = time.clock()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
# sleep(3)
# chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]').click()
break
#方案二===============结束
# lock.release()
while True:
try:
if chrome.find_element_by_xpath('//p[text()="流程结束"]').is_displayed() == True:
# print('订单完成了')
break
except:
continue
sleep(2)
# chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]').click()
# chrome.switch_to.default_content()
# chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
# sleep(20)
# while True:
# try:
# if chrome.find_element_by_xpath('//span[text()="%s"]'%orderno).is_displayed()==True:
# print('//span[text()="%s"]'%orderno)
# break
# except:
# continue
print('寄售配货单创建完成')
end = time.clock()
print(start, end)
print('CPU执行时间: ', end - start)
imgInfo = getErrorPhoto(chrome)
imgName = imgInfo[0]
image_path = imgInfo[1]
info='执行耗时'+str(end - start)
now = get_time()
writeFile_append(pro_path + '/logs/catalina.out', info)
send_email1(image_path, info)
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=1
for i in range(count):
t = threading.Thread(target=job)
t.start()
# t.join()
def start1():
count = 5
for i in range(count):
t = threading.Thread(target=job)
t.start()
t.join()
# print(threading.active_count())
# print("程序执行结束.....")
# create_salesorder()
This diff is collapsed.
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 mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def add_goods(goodsname,chrome):
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_15_column_145 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"])[5]').click()
#点击确定
# chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click()
sleep(1)
def create_salesorder(type=1):
import time
pro_path = get_pro_path()
start = time.clock()
# 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)
chrome.implicitly_wait(20)
try:
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)
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(2)
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)
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('chenshuheng')
sleep(2)
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:员工编码,员工名称,部门编码,部门名称"]').send_keys(
Keys.ENTER)
sleep(2)
chrome.find_element_by_xpath(
'(//div[text()="chenshuheng"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[1]').click()
#手术类型
chrome.find_element_by_xpath('(//input[@placeholder="请选择" and @type="text"])').click()
sleep(1)
chrome.find_element_by_xpath('//li[text()="初次手术"]').click()
sleep(1)
#手术种类
chrome.find_element_by_xpath('(//input[@placeholder="请选择" and @type="text"])[2]').click()
sleep(1)
chrome.find_element_by_xpath('//li[text()="髋关节"]').click()
sleep(1)
chrome.find_element_by_xpath('//label[text()="手术日期 "]/following-sibling::div/div').click()
sleep(1)
chrome.find_element_by_xpath('//div[ @class ="el-date-table-cell"] // span[text()="31"]').click()
#客户信息页签
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('北京大学第三医院')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称"]').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="02f94bb93be972567166f428524aa3b43"]')
chrome.execute_script("arguments[0].click();", btn_div)
chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[3]').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('北京大学第三医院')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客商名称"]').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="0c4d395678c596b20aa6c2a2fef3483d4"]')
chrome.execute_script("arguments[0].click();", btn_div)
chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[4]').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(
'(//button[@class="el-button el-button--primary el-button--default"])[5]').click()
sleep(30)
for i in range(1, 101):
element = chrome.find_element_by_xpath('(//td[@colid="col_75"])[%s]' % i)
sleep(2)
chrome.execute_script("arguments[0].click();", element)
# element=chrome.find_element_by_xpath('(//td[@colid="col_177"])[%s]'%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_76"])[%s]' % i)
chrome.execute_script("arguments[0].click();", element)
sleep(2)
sleep(2)
chrome.find_element_by_xpath('//span[text()="提交"]').click()
while True:
try:
if chrome.find_element_by_xpath('//p[text()="共享任务创建成功"]').is_displayed() == True:
# print('订单完成了')
break
except:
continue
# lock.release()
sleep(2)
# chrome.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--mini"]').click()
# chrome.switch_to.default_content()
# chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
# # sleep(20)
# while True:
# try:
# if chrome.find_element_by_xpath('//span[text()="%s"]'%orderno).is_displayed()==True:
# print('//span[text()="%s"]'%orderno)
# break
# except:
# continue
# 进入手术配货单
chrome.switch_to.default_content()
sleep(3)
chrome.find_element_by_xpath('//span[@class="awsui-tabs-icon close"]').click()
sleep(1)
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('//label[text()="请领单号"]/parent::div/div/div/div/input').send_keys(orderno)
sleep(1)
chrome.find_element_by_xpath('//label[text()="请领单号"]/parent::div/div/div/div/input').send_keys(Keys.ENTER)
sleep(1)
# chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(1)
# text1 = chrome.find_element_by_xpath('(//span[text()="QLD23082800037B"])[2]').text
# print(text1)
chrome.find_element_by_xpath(
'//span[text()="%s"]//parent::div/parent::td//preceding-sibling::td[1]/div/span' % orderno).click()
# element = chrome.find_element_by_xpath('(//span[@class="vxe-checkbox--icon vxe-checkbox--unchecked-icon"])[2]')
# chrome.execute_script("arguments[0].click();", element)
sleep(1)
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(1)
# 方案一============================开始
# if user_count<=5:
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('时间到了')
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(60)
if (m2 == m1):
print('时间到了')
start = time.clock()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
break
# 方案二===============结束#
# chrome.find_element_by_xpath('//span[text()="提交"]').click()
while True:
try:
if chrome.find_element_by_xpath('//p[text()="流程结束"]').is_displayed() == True:
# print('订单完成了')
break
except:
continue
# chrome.find_element_by_xpath('//span[text()="批量提交"]').click()
sleep(1)
print('手术请领配货单创建完成')
end = time.clock()
print(start, end)
print('CPU执行时间: ', end - start)
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)
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=1
for i in range(count):
t = threading.Thread(target=job)
t.start()
t.join()
def start1():
count = 5
for i in range(count):
t = threading.Thread(target=job)
t.start()
t.join()
# print(threading.active_count())
# print("程序执行结束.....")
# create_salesorder()
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 selenium.webdriver.support.select import Select
from mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def add_goods(goodsname,chrome):
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,采购计量单位,销售计量单位,生产厂家编码"]').send_keys(
goodsname)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,采购计量单位,销售计量单位,生产厂家编码"]').send_keys(
Keys.ENTER)
# 获取页数
# pagecount=chrome.find_element_by_xpath('(// li[ @class ="number"])[16]').text
pagecount = 10
for i in range(int(pagecount)):
sleep(1)
chrome.find_element_by_xpath(
'//th[@class="el-table_15_column_192 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
# 翻页
chrome.find_element_by_xpath('(//button[@class="btn-next is-last"])[5]').click()
sleep(1)
#配货函数
def match_goods(chrome,orderno,type):
chrome.switch_to.default_content()
sleep(1)
chrome.find_element_by_xpath('//span[@class="awsui-tabs-icon close"]').click()
sleep(1)
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.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
sleep(2)
s = Select(chrome.find_element_by_id('purchasingCoOptSelect'))
s.select_by_index(0)
sleep(2)
# chrome.find_element_by_xpath('//li[text()="北京大学第三医院(3)"]').click()
# sleep(1)
chrome.find_element_by_xpath('//span[text()="%s"]'%orderno).click()
sleep(4)
# 点击自动填充按钮
chrome.find_element_by_xpath('//button[text()="自动填充"]').click()
# sleep(4)
while True:
try:
chrome.find_element_by_xpath('//button[text()="提交"]').click()
break
except:
continue
sleep(2)
# chrome.find_element_by_xpath('//a[text()="确认"]').click()
sleep(1)
# 方案一============================开始
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('时间到了')
start = time.clock()
print('提交订单开始时间', start)
chrome.find_element_by_xpath('//a[text()="确认"]').click()
break
# 方案一============================结束
# 方案二===============开始
if type == 2:
m = get_time_m() # 当前时间的分钟
m1 = get_submit_time(m) # 计划提交时间的分钟
print('销售订单计划提交时间的分钟', m1)
while True:
m2 = get_time_m() # 循环获取当前的分
# sleep(30)
if (m2 == m1):
start = time.clock()
chrome.find_element_by_xpath('//a[text()="确认"]').click()
break
# 方案二===============结束
while True:
try:
if chrome.find_element_by_xpath('//div[text()="提交成功"]').is_displayed() == True:
# print('订单完成了')
break
# else:
# print('共享任务创建成功的元素没有出现')
except:
continue
end = time.clock()
print(start, end)
# print('CPU执行时间: ', end - start)
return str(end - start)
def create_salesorder(type=1):
try:
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.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)
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('//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('//span/input[@type="radio" and @value="03105272b49986351ef7eb2930b5454de"]').click()
btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="012001f8d35054875d6157d4715404319"]')
chrome.execute_script("arguments[0].click();", btn_div)
chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[3]').click()
sleep(1)
#业务员名称
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('chenshuheng')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,部门编码,部门类型编码"]').send_keys(Keys.ENTER)
chrome.find_element_by_xpath('(//div[text()="chenshuheng"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[3]').click()
# #其他信息页签
# chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
# 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)[4]').click()
sleep(20)
# chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,采购计量单位,销售计量单位,生产厂家编码"]').send_keys(
# '10006179')
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,采购计量单位,销售计量单位,生产厂家编码"]').send_keys(
# Keys.ENTER)
# sleep(1)
# chrome.find_element_by_xpath('(//span[@class="el-checkbox__inner"])[4]').click()
# chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[4]').click()
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_93"])[%s]'%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_94"])[%s]'%i).click()
sleep(2)
chrome.execute_script(
"document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollTop = %s*50;" % i)
# #滚动条右拉
# # 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");
# element = chrome.find_element_by_xpath('//td[@colid="col_197"]')
# 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"]')
# element.click()
# sleep(2)
# chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# sleep(2)
# lock = threading.Lock()
# lock.acquire()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
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(20)
# while True:
# try:
# if chrome.find_element_by_xpath('//span[text()="%s"]' % orderno).is_displayed() == True:
# print('//span[text()="%s"]' % orderno)
# break
# except:
# continue
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
print('经销售要货申请单创建完成')
# 审批
chrome.switch_to.default_content()
chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
sleep(2)
chrome.find_element_by_xpath(
'//span[text() = "%s"]' % orderno).click()
chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
chrome.find_element_by_xpath('//span[text()="审核通过"]').click()
sleep(1)
chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('3333')
sleep(1)
chrome.find_element_by_xpath('//span[text()="发送"]').click()
while True:
try:
if chrome.find_element_by_xpath('//p[text()="共享任务创建成功"]').is_displayed() == True:
# print('订单完成了')
break
# else:
# print('共享任务创建成功的元素没有出现')
except:
continue
time1=match_goods(chrome, orderno,type)
# end = time.clock()
# print(start, end)
print('CPU执行时间: ', time1)
imgInfo = getErrorPhoto(chrome)
imgName = imgInfo[0]
image_path = imgInfo[1]
info=orderno+'执行耗时'+time1
now = get_time()
writeFile_append(pro_path + '/logs/catalina.out', info)
send_email1(image_path, info)
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=1
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()
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 mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder1(1)
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def add_goods(goodsname,chrome):
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品全称,规格型号,主计量单位,采购计量单位,厂家物料编码,存储条件,存储条件说明,生产企业编码,行类型,件包数,产品备注,产品描述,商品性质,是否免备案"]').send_keys(
goodsname)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品全称,规格型号,主计量单位,采购计量单位,厂家物料编码,存储条件,存储条件说明,生产企业编码,行类型,件包数,产品备注,产品描述,商品性质,是否免备案"]').send_keys(
Keys.ENTER)
#获取页数
# pagecount=chrome.find_element_by_xpath('(// li[ @class ="number"])[16]').text
pagecount=10
for i in range(int(pagecount)):
sleep(1)
chrome.find_element_by_xpath(
'//th[@class="el-table_18_column_144 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
#翻页
chrome.find_element_by_xpath('(//button[@class="btn-next is-last"])[6]').click()
sleep(2)
def create_salesorder1(type=1):
import time
start = time.clock()
# 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.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)
allot_link = chrome.find_element_by_xpath('//span[text()="调拨出库单"]')
chrome.execute_script("arguments[0].click();", allot_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)
sleep(2)
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"])[3]').click()
# 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"])[4]').click()
#业务员名称
sleep(1)
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('(//div[text()="杨春刚"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[2]').click()
#仓库信息页签
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="模糊检索:调拨出库仓库名称,调拨出库仓库编码,是否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="08374712eb9413253c6281062de2ab877"]')
chrome.execute_script("arguments[0].click();", btn_div)
chrome.find_element_by_xpath('(//span[@class="ensureBtn"])[3]/button').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="0e455e227177d35f275908320e3e32fe9"]')
chrome.execute_script("arguments[0].click();", btn_div)
chrome.find_element_by_xpath('(//span[@class="ensureBtn"])[4]/button').click()
# 子表信息录入
chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
# chrome.find_element_by_xpath('//span[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(10)
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品全称,规格型号,主计量单位,采购计量单位,厂家物料编码,存储条件,存储条件说明,生产企业编码,行类型,件包数,产品备注,产品描述,商品性质,是否免备案"]').send_keys(
# '10006179')
# chrome.find_element_by_xpath(
# '//input[@placeholder="模糊检索:商品编码,商品全称,规格型号,主计量单位,采购计量单位,厂家物料编码,存储条件,存储条件说明,生产企业编码,行类型,件包数,产品备注,产品描述,商品性质,是否免备案"]').send_keys(
# Keys.ENTER)
# sleep(1)
# chrome.find_element_by_xpath('(//span[@class="el-checkbox__inner"])[4]').click()
# chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[5]').click()
sleep(6)
for i in range(1, 101):
element=chrome.find_element_by_xpath('(//td[@colid="col_108"])[%s]'%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')
sleep(2)
#滚动条右拉
# 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");
# element = chrome.find_element_by_xpath('//td[@colid="col_197"]')
# element.click()
# sleep(6)
# chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# sleep(2)
# element = chrome.find_element_by_xpath('//td[@colid="col_198"]')
# element.click()
# sleep(6)
# chrome.execute_script("document.getElementsByClassName('awsui-input-number-right')[0].value='8'")
# sleep(2)
# lock = threading.Lock()
# lock.acquire()
#方案一============================开始
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('时间到了')
start = time.clock()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
break
# 方案一============================结束
#方案二===============开始
if type==2:
m=get_time_m() #当前时间的分钟
m1=get_submit_time(m)#计划提交时间的分钟
print('调拨计划提交时间',m1)
while True:
m2=get_time_m() #循环获取当前的分
# sleep(30)
if (m2==m1):
start = time.clock()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
break
#方案二===============结束
while True:
try:
if chrome.find_element_by_xpath('//p[text()="共享任务创建成功"]').is_displayed() == True:
# print('订单完成了')
break
except:
continue
# lock.release()
# sleep(5)
# 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(20)
while True:
try:
if chrome.find_element_by_xpath('(//span[text()="%s"])[2]'%orderno).is_displayed()==True:
print('//span[text()="%s"]'%orderno)
break
except:
continue
print('调拨出库单创建完成')
end = time.clock()
print(start, end)
print('CPU执行时间: ', end - start)
time1=end - start
imgInfo = getErrorPhoto(chrome)
imgName = imgInfo[0]
image_path = imgInfo[1]
info=orderno+',耗时'+str(time1)
now = get_time()
pro_path = get_pro_path()
writeFile_append(pro_path + '/logs/catalina.out', 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中的类
pro_path = get_pro_path()
try:
for i in range(1):
t = threading.Thread(target=job)
t.start()
# t.join()
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)
# print(threading.active_count())
# print("程序执行结束.....")
# create_salesorder()
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 mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def create_salesorder(type=1):
try:
import time
pro_path = get_pro_path()
start = time.clock()
# 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.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"])[3]').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"])[4]').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('杨春刚')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,业务部门编码,部门类型编码"]').send_keys(Keys.ENTER)
chrome.find_element_by_xpath('(//div[text()="杨春刚"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[4]').click()
#其他信息页签
chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
chrome.find_element_by_xpath('//div[@cid="AWSUI.SwitchButton"]//div/div/div/div/span[1]').click()
# 子表信息录入
chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
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)
for i in range(1,11):
element=chrome.find_element_by_xpath('(//td[@colid="col_177"])[%s]'%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(1)
chrome.find_element_by_xpath('(//td[@colid="col_178"])[%s]'%i).click()
sleep(2)
#滚动条右拉
# 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");
for i in range(1, 11):
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()
#方案一============================开始
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('时间到了')
chrome.find_element_by_xpath('//span[text()="提交"]').click()
break
# 方案一============================结束
#方案二===============开始
if type==2:
m=get_time_m() #当前时间的分钟
m1=get_submit_time(m)#计划提交时间的分钟
print('销售订单计划提交时间的分钟',m1)
while True:
m2=get_time_m() #循环获取当前的分
# sleep(30)
if (m2==m1):
chrome.find_element_by_xpath('//span[text()="提交"]').click()
break
#方案二===============结束
# 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(20)
while True:
try:
if chrome.find_element_by_xpath('//span[text()="%s"]'%orderno).is_displayed()==True:
print('//span[text()="%s"]'%orderno)
break
except:
continue
print('销售订单创建完成')
end = time.clock()
print(start, end)
print('CPU执行时间: ', end - start)
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)
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=1
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()
This diff is collapsed.
This diff is collapsed.
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 mail1 import send_email1
from public.tools import *
# chrome = webdriver.Chrome(chrome_options=opt)
def job():
print("这是一个需要执行的任务。。。。。")
create_salesorder()
print("当前线程的个数:", threading.active_count())
time.sleep(1)
print("当前线程的信息:", threading.current_thread())
def add_goods(goodsname,chrome):
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys(
goodsname)
chrome.find_element_by_xpath(
'//input[@placeholder="模糊检索:商品编码,商品名称,规格型号,主计量单位,销售计量单位,厂家物料编码,存储条件说明,生产企业编码,供应商编码,行类型,商品性质,批发价,进口/国产/港澳台,件包数,产品备注,是否免备案,产品描述"]').send_keys(
Keys.ENTER)
#获取页数
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_229 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
#翻页
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):
try:
import time
pro_path = get_pro_path()
# start = time.clock()
# 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.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"])[3]').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"])[4]').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('杨春刚')
chrome.find_element_by_xpath('//input[@placeholder="模糊检索:业务员名称,业务员编码,业务部门名称,业务部门编码,部门类型编码"]').send_keys(Keys.ENTER)
chrome.find_element_by_xpath('(//div[text()="杨春刚"])[3]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])[4]').click()
#其他信息页签
chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
chrome.find_element_by_xpath('//div[@cid="AWSUI.SwitchButton"]//div/div/div/div/span[1]').click()
# 子表信息录入
chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
# 点击添加商品弹出添加商品子窗口
chrome.find_element_by_xpath('//button[text()="导入"]').click()
sleep(1)
# chrome.find_element_by_xpath('//span[text()="上传Excel文件"]').click()
sleep(1)
element = chrome.find_element_by_class_name('upload__text')
chrome.execute_script("arguments[0].click();", element)
sleep(1)
chrome.find_element_by_class_name('el-upload__text').send_keys(r'D:\PycharmProjects\骨科库存占用专项测试\testcase\od\销售订单明细8.xls')
sleep(1)
# 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)
# 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)
for i in range(1,101):
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()
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)
sleep(2)
#滚动条右拉
# 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");
for i in range(1,101):
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_time(m)#计划提交时间的分钟
print('销售订单计划提交时间的分钟',m1)
while True:
m2=get_time_m() #循环获取当前的分
# sleep(30)
if (m2==m1):
start = time.clock()
chrome.find_element_by_xpath('//span[text()="提交"]').click()
break
#方案二===============结束
# 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(20)
while True:
try:
if chrome.find_element_by_xpath('(//span[text()="%s"])[2]'%orderno).is_displayed()==True:
print('//span[text()="%s"]'%orderno)
break
except:
continue
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=1
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()
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment