如何做自动化的项目封装

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,还会有同行一起技术交流

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值