栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

robotframework自动化尝试

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

robotframework自动化尝试

robotframe插件安装

只能用TAB键

 基础模板和语法

*** Settings ***
Library     SeleniumLibrary

*** Variables ***
${url}          http://127.0.0.1:8047/mgr/sign.html
${username}     byhy
${password}     88888888
${add_user}     bobo
${add_phone_number}     18888999911

*** Keywords ***
使用用户名密码登陆
    Input Text    id:username    ${username}
    Input Text    id:password    ${password}
    Click Button    xpath://*[@type="submit"]
    Set Selenium Implicit Wait    2

添加用户
    Click Element    xpath://*[@type="button"]

输入添加客户的相关内容
    [Arguments]     ${name}     ${phone_number}
    Input Text    xpath://*[@id="root"]/div/section[2]/div[1]/div[1]/div[1]/input    ${name}
    Input Text    xpath://*[@id="root"]/div/section[2]/div[1]/div[1]/div[2]/input    ${phone_number}
    Click Button    xpath://*[@id="root"]/div/section[2]/div[1]/div[2]/button[1]


*** Test Cases ***
用例:登陆白月黑羽
    Open Browser    ${url}     googlechrome
    Maximize Browser Window
    使用用户名密码登陆
    添加用户
    输入添加客户的相关内容     lele        199009999




封装命名规则:                add_user.resource

*** Settings ***
Documentation       用户添加关键字
Library             SeleniumLibrary

*** Variables ***
${main_url}     http://127.0.0.1:8047/mgr/sign.html


*** Keywords ***
打开浏览器并到白月黑羽首页
    Open Browser    ${main_url}     chrome
    Maximize Browser Window
    Set Selenium Implicit Wait    5
使用用户名和密码登陆
    [Arguments]     ${username}     ${password}
    Input Text    id:username    ${username}
    Input Text    id:password    ${password}
    Click Button    xpath://*[@type="submit"]
登录失败的提示信息
    [Arguments]                 ${expect_alert}
    Alert Should Be Present     ${expect_alert}

截图
    Capture Page Screenshot
关闭浏览器
    Close All Browsers

用例执行:导入以及测试套件

*** Settings ***
Documentation       测试用户登录
Resource            ../testcase_robot_keywords/add_user.resource
Suite Setup         打开浏览器并到白月黑羽首页
Suite Teardown      关闭浏览器
Test Setup          截图
Test Teardown       截图

*** Test Cases ***
用户名密码为空,测试
    使用用户名和密码登陆  ${EMPTY}     88888888
    登录失败的提示信息    请输入用户名

错误的用户名密码登录失败
    使用用户名和密码登陆  123    88888888
    登录失败的提示信息    登录失败 : 用户名或者密码错误

错误的用户名密码登录失败
    使用用户名和密码登陆  byhy    8888888
    登录失败的提示信息    登录失败 : 用户名或者密码错误

python自定义关键字:加上时间戳,创建文件夹,截图

定义y_m=time.strftime("%Y_%m"),可放到一个文件夹里
import os
import time

class DiyKeywords:

    def get_screenshots_path(self):
        root_path=os.path.dirname(os.path.dirname(__file__))
        screenshots=os.path.join(root_path,"screenshots")
        if not os.path.exists(screenshots):
            os.mkdir(screenshots)
        y_m=time.strftime("%Y_%m_%d  %H_%M_%S")
        ym_dir=os.path.join(screenshots,y_m)
        if not os.path.exists(ym_dir):
            os.mkdir(ym_dir)
        return ym_dir

在robot.resource导入自定义python类:

Library             ../testcase_robot_diykeywords/DiyKeyWords.py
*** Settings ***
Documentation       用户添加关键字
Library             SeleniumLibrary
#python自定义类
Library       ../testcase_robot_diykeywords/DiyKeyWords.py


*** Variables ***
${main_url}     http://127.0.0.1:8047/mgr/sign.html


*** Keywords ***
打开浏览器并到白月黑羽首页
    Open Browser    ${main_url}     chrome
    Maximize Browser Window
    Set Selenium Implicit Wait    5
使用用户名和密码登陆
    [Arguments]     ${username}     ${password}
    Input Text    id:username    ${username}
    Input Text    id:password    ${password}
    Click Button    xpath://*[@type="submit"]
登录失败的提示信息
    [Arguments]                 ${expect_alert}
    Alert Should Be Present     ${expect_alert}

截图
    ${pngdir}=  Get Screenshots Path
    Set Screenshot Directory        ${pngdir}
    Capture Page Screenshot
关闭浏览器
    Close All Browsers

运行demo03.robot产生文件夹和截图

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/890447.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号