鬼吹灯之精绝古城 迅雷下载,超级位面当铺,玩野王粤语06
android终端产品系统或app测试,涉及输入框边界值测试,
比如wifi热点设置热点名称, 或者搜索输入框,
需要验证该文本输入框是否最多可以输入256个字符,
如何快速实现进准的256个字符的输入呢?
# coding=utf-8 import os import string import random chars_num = 256 # chars num字符数量 random_list = random.sample((string.ascii_letters + string.digits) * 5, chars_num - 8) random_str = ''.join(random_list) random_str = "start" + random_str + "end" print(random_str) os.system("adb shell input text %s" % random_str) print("inputed %s chars, please check the \"start\" and \"end\" keyword" % chars_num) os.system("pause")
random.sample需要确保数组“池”里的数据足够多,所以需要:
(string.ascii_letters + string.digits) * 5
# coding=utf-8 import os import string import random def input_text(chars_num): if chars_num > 8: random_list = random.sample((string.ascii_letters + string.digits) * 5, chars_num - 8) random_str = ''.join(random_list) random_str = "start" + random_str + "end" print(random_str) os.system("adb shell input text %s" % random_str) print("inputed %s chars, please check the \"start\" and \"end\" keyword" % chars_num) else: print("chars num too short...") input_text(256) os.system("pause")
# coding=utf-8 import os import string import random class textinputer(): def __init__(self): pass def input_text(self, chars_num): if chars_num > 8: random_list = random.sample((string.ascii_letters + string.digits) * 5, chars_num - 8) random_str = ''.join(random_list) random_str = "start" + random_str + "end" print(random_str) # os.system("adb shell input text %s" % random_str) print("inputed %s chars, please check the \"start\" and \"end\" keyword" % chars_num) else: print("chars num too short...") t_obj = textinputer() t_obj.input_text(256) os.system("pause")
确保android设备通过usb线与电脑连接了,adb设备有效连接,
以上代码的3种实现形式都可以直接运行,比如保存为input_text.py并放在桌面,
建议python input_text.py运行,当然也可以双击运行。
运行效果如下:
更多更好的原创文章,请访问官方网站:
自拍教程(自动化测试python教程,武散人编著)
原文链接:
也可关注“武散人”微信订阅号,随时接受文章推送。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论