#运行匹配代码
flag = isElementExist(driver,"//*[@text='articleType:81']")
while(flag==False):
time.sleep(2)
swipeUp(driver)
time.sleep(2)
flag = isElementExist(driver, "//*[@text='articleType:81']")
if flag:
time.sleep(2)
ArticleType81(driver)
#改进一下
#运行匹配代码
flag = isElementExist(driver,"//*[@text='articleType:81']")
while(flag==False):
time.sleep(2)
swipeUp(driver)
time.sleep(2)
flag = isElementExist(driver, "//*[@text='articleType:81']")
time.sleep(2)
ArticleType81(driver)
#随机获取一个虚构的手机号 num = 1 while num < 999: num += 1 body = copy.copy('0'*(8-len(str(num)))) res = '188' + body + str(num) print(res)
def generate_mobile():#随机获取一个真实的手机号,慎用 head = random.sample( ['130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '147', '150', '151', '152', '153', '155', '156', '157', '158', '159', '170', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189'], 1) res = str(head[0]) + str(random.randint(1000, 9999)) + str(random.randint(1000, 9999)) return res
def get_jenkins_JSESSIONID():#获取jenkins的JSESSIONID cookies2 = { "_ga": "GA1.2.961693238.1598349519", "_hjid": "11471495-a4eb-4435-a506-d30fa841b3d8", 'screenResolution': '1920x1080', 'JSESSIONID': '3A20570D7501D4CCF137AABBFB599EF5', 'jenkins-timestamper-offset': '=-28800000' } headers2 = { "Host": "tee.efivestar.com", "Connection": "keep-alive", # 'Content-Length':'98', 'Cache-Control': 'max-age=0', "X-Atlassian-Token": "no-check", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded", "Referer": "https://tee.efivestar.com/jenkins/login?from=%2Fjenkins%2F", 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', "Upgrade-Insecure-Requests": "1", } data = 'j_username=Testerone11&j_password=123qww112321456&from=%2Fjenkins%2F&Submit=%E7%99%BB%E5%BD%95&remember_me=on' session = requests.session() req2 = session.post(url='https://tee.efivestar.com/jenkins/j_acegi_security_check', data=data, allow_redirects=False, cookies=cookies2, headers=headers2) # allow_redirects=False 禁止重定向。 JSESSIONID = req2.cookies['JSESSIONID'] cookies = { "_ga": "GA1.2.961693238.1598349519", "_hjid": "11471495-a4eb-4435-a506-d30fa841b3d8", 'screenResolution': '1920x1080', 'JSESSIONID': JSESSIONID, 'jenkins-timestamper-offset': '=-28800000' } return cookies
当前时间和当前时间减一秒:
Screentime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
print(Screentime)
tm = datetime.datetime.strptime(Screentime, "%Y-%m-%d %H:%M:%S")
time_offset = tm - datetime.timedelta(seconds=1)
print(time_offset.strftime("%Y-%m-%d %H:%M:%S"))
#取值
articletypes = driver.find_elements_by_id('artcle_type')
myprint(articletypes)
_tpye = []
for var in articletypes:
# title = var.text
time.sleep(1)
text = var.get_attribute("text")
myprint(text)
if text not in _tpye:
myprint('这是取到的text')
myprint(text)
_tpye.append(text)
myprint(_tpye)
time.sleep(2)
if text == 'articleType:81':
ArticleType81(driver)
if text in _tpye:
time.sleep(2)
swipeUp(driver)
#这个ok我要留着
print(' * * * ')
print(' * * * * ')
print(' * * * * ')
print(' * * * * ')
print(' * * * * ')
print(' * * * *')
print(' * * * ')
#coding=utf-8
import sys
# import imp
# imp.reload(sys)
import os
from sys import path
import random
path.append(r'C:\Program Files\Appium\\resources\app\node_modules\appium\build\lib')
#列出系统现在所安装的所有输入法
#os.system(command0)
#打印系统当前默认的输入法
#os.system(command1)
#切换latin输入法为当前输入法
#os.system(command2)
#切换appium输入法为当前输入法
#os.system(command3)
command0 ='adb shell ime list -s'
command1 ='adb shell com.android.inputmethod.latin/.LatinIME'
command2 ='adb shell ime set com.android.inputmethod.latin/.LatinIME'
command3 ='adb shell ime set io.appium.android.ime/.UnicodeIME'
command4 ='adb shell ime set com.nuance.swype.emui/com.nuance.swype.input.HuaweiIME'
command5 ='adb uninstall hongze.app.jsbc'
#可调试
# _list = []
# command0 = 'adb shell ime list -s'
# f = os.popen(command0)
# t = f.read()
# # print(t)
# _list = t.splitlines()
# _list.remove('io.appium.settings/.UnicodeIME')
# print(_list)
# method = _list[random.randint(0, len(_list) - 1)]
# print(method)
# command4 = 'adb shell ime set' + ' ' + method
# print(command4)
class InputMethod:
#切换appium输入法为当前输入法
def enableAppiumUnicodeIME(self):
_list = []
command0 = 'adb shell ime list -s'
f = os.popen(command0)
t = f.read()
# print(t)
_list = t.splitlines()
_list.remove('io.appium.settings/.UnicodeIME')
# print(_list)
method = _list[random.randint(0, len(_list) - 1)]
# print(method)
command4 = 'adb shell ime set' + ' ' + method
# print(command4)
os.system(command4)
#删除已存在的包
def uninstallhost(host):
command4 ='adb uninstall' + ' ' + str(host)
os.system(command4)
# 启动appium
def start_appium(host):
start = "start /b node (r'C:\Program Files\Appium\\resources\app\node_modules\appium\build\lib\')" + 'main.js --address 127.0.0.1 --port 4723'
os.system(start)
import json,requests
import os,re,time,datetime,yaml
import subprocess
def getjson(url):
#解析json,写入json.yaml
json_path = os.path.dirname(__file__) + "/json.yaml"
jsdate = requests.get(url).content
js = json.loads(jsdate)
with open(json_path, "w", encoding="utf-8") as f:
yaml.dump(js, f, Dumper=yaml.Dumper,allow_unicode=True)
def gettabs(**kwargs):
# 获取app配置中tabs列表
tab = kwargs['tabs']
tabs = []
for i in tab:
tabs.append(i['title'])
return tabs
def gettabs_moudle_name(**kwargs):
# 获取app tabs列表的moudleName
tab = kwargs['tabs']
tabs = []
for i in tab:
tabs.append(i['moduleName'])
tabs = [x for x in tabs if x != '']
return tabs
def getmoudles(**kwargs):
# 获取app moudles
module = kwargs['modules']
modules = []
for i in module:
modules.append(i['title'])
return modules
#取当前连接手机的名称和系统版本
import subprocess
def attached_devices():
device=[]
formate = ["deviceName","platformVersion"]
n = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines()
for i in n:
l = []
t = i.decode().split("\t")
if len(t) >= 2:
l.append(t[0])
s = "adb -s %s shell getprop ro.build.version.release"%t[0]
v = subprocess.Popen(s, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines()
for i in v:
a = i.decode().split("\n")
l.append(a[0].replace("\r",''))
d = dict(zip(formate,l))
# device.append(d)
return d
from PIL import Image
from PIL import ImageChops
def compare_images(driver, path_one, lu):
img_folder = os.fspath('D:\\screenshots') + '\\' + str(lu) + "\ERROR" + lu
Screentime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
screen_save_path = img_folder + Screentime + '.png'
driver.get_screenshot_as_file(screen_save_path)
# myprint(screen_save_path)
"""
比较图片,如果有不同则生成展示不同的图片
@参数一: path_one: 第一张图片的路径
@参数二: path_two: 第二张图片的路径
@参数三: diff_save_location: 不同图的保存路径
"""
# diff_save_location = 'D:\\screenshots\\mumu\\' + str(department) + Screentime + '.png'
image_one = Image.open(path_one)
image_two = Image.open(screen_save_path)
try:
diff = ImageChops.difference(image_one, image_two)
if diff.getbbox() is None:
# 图片间没有任何不同则删除图片
os.remove(screen_save_path)
return True
else:
myprint(diff)
#存不同
# diff.save(diff_save_location)
#存第二张图
# image_two.save(diff_save_location)
return screen_save_path
except ValueError as e:
text = ("图片不一致")
print("【{0}】{1}".format(e, text))