tasks\user_module.robot
*** Settings ***
Documentation 用户模块
... 用户购物车
... 用户订单
Resource ../resources/common.robot
*** Test Cases ***
我的购物车模块
用户登录 helloworld 123456
resouces\common.robot
*** Settings ***
Documentation 常用操作自定义为关键字
Library SeleniumLibrary
Library ../libs/baiduocr.py
Library ../libs/tools.py
*** Variables ***
${url} http://47.100.225.199/
*** Keywords ***
用户登录
[Arguments] ${username} ${passwd}
Open Browser ${url} chrome
Set Screenshot Directory screenshots
Set Selenium Implicit Wait 10
Maximize Browser Window
Click Element //div[@class="menu-hd"]/a[1]
Input Text //input[@name="accounts"] ${username}
Input Password //input[@name="pwd"] ${passwd}
FOR ${x} IN RANGE 9999
Click Element //*[@id="form-verify-img"] # 点击验证码刷新
Capture Element Screenshot //*[@id="form-verify-img"] filename=verify.png #验证码截图
${verify_code} get_image_text verify.png # ocr识别验证码
log to console ${verify_code}
Input Text //input[@name="verify"] ${verify_code}
Click Element //div[@class="am-form-group am-form-group-refreshing"]/button[@type="submit"]
sleep 2 ${current_url} Get Location ${bool} substr_contains_str
${current_url} logininfo.html
log to console ------${bool}------
Run Keyword If not ${bool} Exit For Loop
log to console hello world
END
libs\baiduocr.py
from aip import AipOcr
import os
""" 你的 APPID AK SK """
APP_ID = '16846489'
API_KEY = 'apQRGrB63twTq3nrD4UgFoFT'
SECRET_KEY = 'TISjXmN8KVCrToKRX4rggX0bONs05tNV'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
def get_image_text(pngname):
root_dir = os.path.dirname(os.path.dirname(os.path.
abspath(__file__))) #获取项目根目录
pngpath = os.path.join(root_dir,"screenshots",
pngname) # 获取文件路径
image = get_file_content(pngpath)
""" 调用高精度文字识别, 图片参数为本地图片 """
data = client.basicAccurate(image)
print(data)
text = data['words_result'][0]['words']
""" 将文本值去掉空格 """
text2 = text.replace(" ", "")
return text2
if __name__ == '__main__':
get_image_text('../verify.png')
创建了一个测试交流群,如果对软件测试、接口测试、自动化测试、面试经验交流感兴趣可以加测试交流群:829792258,还会有同行一起技术交流
网友评论