网站建设有些什么流程,五大建设的主要内容,app怎么制作多少钱,上海比较好的外包公司对于web应用程序来讲#xff0c;处于安全性考虑#xff0c;在登录的时候#xff0c;都会设置验证码#xff0c; 验证码的类型种类繁多#xff0c;有图片中辨别数字字母的#xff0c;有点击图片中指定的文字的#xff0c;也有算术计算结果的#xff0c;再复杂一点就是滑…对于web应用程序来讲处于安全性考虑在登录的时候都会设置验证码 验证码的类型种类繁多有图片中辨别数字字母的有点击图片中指定的文字的也有算术计算结果的再复杂一点就是滑动验证的。
诸如此类的验证码对我们的系统增加了安全性的保障但是对于我们测试人员来讲在自动化测试的过程中无疑是一个棘手的问题。 1、Web 自动化验证码解决方案
一般在我们测试过程中登录遇到上述的验证码的时候有以下种解决方案
第一种、让开发去掉验证码第二种、设置一个万能的验证码第三种、通过 cookie 绕过登录第四种、自动识别技术识别验证码
2、验证码解决方案 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 # coding:utf-8 import os import subprocess from PIL import Image def get_captcha(driver, captcha_id, full_screen_img_path, captcha_img_path, captcha_final_path, txt_path, ocr_path): # 浏览器界面截图 driver.save_screenshot(full_screen_img_path) # 找到验证码图片得到它的坐标 element driver.find_element_by_id(captcha_id) left element.location[x] top element.location[y] right element.location[x] element.size[width] bottom element.location[y] element.size[height] left, top, right, bottom int(left), int(top), int(right), int(bottom) img Image.open(full_screen_img_path) img img.crop((left, top, right, bottom)) # 得到验证码图片 img.save(captcha_img_path) # 打开验证码图片 img Image.open(captcha_img_path) # 颜色直方图255种颜色255为白色 # 新建一张图片(大小和原图大小相同背景颜色为255白色) img_new Image.new(P, img.size, 255) for x in range(img.size[1]): for y in range(img.size[0]): # 遍历图片的xy坐标像素点颜色 pix img.getpixel((y, x)) # print(pix) # 自己调色r0g0b0为蓝色 if pix[0] 20 and pix[1] 20 and pix[2] 50: # 把遍历的结果放到新图片上0为透明度不透明 img_new.putpixel((y, x), 0) img_new.save(captcha_final_path, formatpng) # 通过tesseract工具解析验证码图片生成文本 os.system(ocr_path) # 读取txt文件里面的验证码 with open(txt_path, r) as f: if f.read(): t f.read().strip() # 去掉中间空格 if in t: t t.replace( , ) if t.isdigit() and len(t) 4: return t else: return fail def check_resp(result, msg): if msg in result: return pass else: return failed # 接口 - 识别验证码 def get_captcha(captcha_img_path, captcha_final_path, txt_path, ocr_path): # 打开验证码图片 img Image.open(captcha_img_path) # 新建一张图片(大小和原图大小相同背景颜色为255白色) img_new Image.new(P, img.size, 55) for x in range(img.size[1]): for y in range(img.size[0]): # 遍历图片的xy坐标像素点颜色 pix img.getpixel((y, x)) # print(pix) # 自己调色r0g0b0为蓝色 if pix[0] 20 and pix[1] 20 and pix[2] 50: # 把遍历的结果放到新图片上0为透明度不透明 img_new.putpixel((y, x), 0) img_new.save(captcha_final_path, formatpng) # 通过tesseract工具解析验证码图片生成文本【Tesseract-OCR必须和jpg的根目录必须相同如C盘、D盘】 os.system(ocr_path) # 读取txt文件里面的验证码 with open(txt_path, r) as f: if r.read(): t f.read().strip() # 去掉中间空格 if in t: t t.replace( , ) # 如果是数字且长度为4就返回数字如果不是就返回 fail if t.isdigit() and len(t) 4: return t else: return fail
现在我也找了很多测试的朋友做了一个分享技术的交流群共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源没人解答问题坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化性能安全测试开发等等方面有一定建树的技术大牛
分享他们的经验还会分享很多直播讲座和技术沙龙
可以免费学习划重点开源的
qq群号485187702【暗号csdn11】
最后感谢每一个认真阅读我文章的人看着粉丝一路的上涨和关注礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走 希望能帮助到你【100%无套路免费领取】