惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)
腾讯CDC
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
N
News | PayPal Newsroom
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
A
Arctic Wolf
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cyber Attacks, Cyber Crime and Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AI
AI
S
Security @ Cisco Blogs
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
爱范儿
爱范儿
罗磊的独立博客
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
T
Threatpost
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
Security Latest
Security Latest
P
Proofpoint News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
Intezer
H
Heimdal Security Blog
Blog — PlanetScale
Blog — PlanetScale
S
Securelist
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19) 使用 Velero 备份 Kubernetes 集群 Kubernetes Cheat Sheet 开发 Tips(18) 如何构建一个 Java 工程 开发 Tips(17) KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses 基于 Kubernetes 和 Jenkins 搭建自动化测试系统 在 Kubernetes 上动态创建 Jenkins Slave 使用 Jenkins 进行服务拨测 开发 Tips(16) Kubernetes 签发 Ingress 证书及日常故障运维 Kubernetes 中 Deployment 的基本操作 Kubernetes 中的证书 如何使用 KubeBuilder 开发一个 Operator Kubernetes 1.6.0 安装问题汇总 镜像管理工具 -- Harbor 开发 Tips(15) Docker 如何拉取镜像 开发 Tips(14) 使用 Helm 安装 harbor 开发 Tips(13) 使用 S2I 构建云原生应用 在 Kubernetes 中使用 emptyDir、hostPath、localVolume 开发 Tips(12) 开发 Tips(11) 代码质量分析工具 SonarQube 使用 Kubeadm 安装 Kubernetes 集群 一起来学 Go --(4)常用函数 Kubernetes 中的 Ceph Kubernetes 之 Volumes Kubernetes 之 Labels、Selectors 开发 Tips(10) 开源正在重构商业模式 Kubernetes 之网络 Kubernetes 之 API 使用 Helm 和 Operator 快速部署 Prometheus Kubernetes 复杂有状态应用管理框架 -- Operator Kubernetes 的包管理器 -- Helm 一起来学 Go --(3)Go Modules 如何一步一步地优化博客方案 kubectl 实用指南 Kubernetes 中的基本概念 搭建远程 Kubernetes 开发环境 大公司和小公司的 ToB 思路 开发 Tips(9) Go 入门指南 一起来学 Go --(2)数据与逻辑结构 如何预防 Web 富文本中的 XSS 攻击 django-xss-cleaner 云工作时代 一起来学 Go --(1)背景与特点 SaaS 开发团队的不同阶段 你不知道的 Git 使用技巧 输出既服务 微服务设计 继续奔跑 开发 Tips(8) 从账户安全到二次验证 Django 性能之数据库查询优化 Django 性能之分库分表 敏捷开发之研发流程 打造一致性的团队 开发 Tips(7) Pytest 进阶学习之 Mock PaaS 部署之 buildpack Go 开发配置 领域输出才是 PaaS 的核心竞争力 Pytest 入门学习 开发 Tips(6) 如何使用 Jenkins、Docker、GitLab 搭建 Django 自动化部署流程
Robot Framework 进阶 (1)
微信公众号 · 2018-08-15 · via 陈少文的网站

Please enable Javascript to view the contents

pybot 命令

  • 执行所有测试用例
  • 执行某个测试套件
  • 执行某个测试套件中的测试用例
1
pybot --test case_name testsuit.txt
  • 将测试结果输出到固定路径
1
pybot --ouputdir your_ouput_dir testsuit.txt
  • 执行包含某个 tag 的测试用例
1
pybot --include tag_name testsuit.txt

关于日志

默认情况下,Robot Framework 中低于 INFO 级别的日志消息不会写日志。这个阈值可以通过命令行选项 --loglevel 修改。

在 Robot Framework 中有五种日志级别:

  • FAIL

当关键字失败时使用,只能由Robot Framework自己使用

  • WARN

用来展示警告, 警告消息同样会出现在 控制台以及日志文件的测试执行错误区,,不过它们不会影响到测试用例的状态

  • INFO

默认的消息级别,默认情况下日志文件中不会显示低于此级别的消息

  • DEBUG

用于调试目的.,当需要记录测试库内部执行过程时很有用。当关键字失败时,代码失败的地方会自动使用该级别打印 traceback 信息

  • TRACE

更详细的调试级别,使用该级别时,关键字的参数和返回值会自动写入日志

在测试用例中,可以调用内置关键字 log 输出相应的日志:

例如:

1
2
log    "this is my log"    warn
log    ${num}    warn

输出:

1
2
[ WARN ] "this is my log"
[ WARN ] 100

第一个参数是日志内容,第二个参数是日志级别,默认是 info。

声明变量

  • 变量

在测试套件中:

1
2
${num}    100
${string}   abcdef

在测试用例中:

1
2
${num}    Set Variable    100
${string}    Set Variable    abcdef
  • 列表

在测试套件中:

1
2
@{num_list}       1    2    3
@{string_list}    a    b    c

在测试用例中:

1
2
@{num_list}    Create  List    1        2         3
@{string_list}    Create  List    a       b          c

列表的访问方法有两种:

  1. @{变量名}[index]
  2. ${变量名[index]}
  • 字典

在测试套件中:

1
&{user}  name=admin    email=admin@admin.com

在测试用例中:

1
&{user}    Create Dictionary    name=admin    email=admin@admin.com

也可以使用标量符声明字典变量 ${user}

访问方法:

1
2
log    ${user.name}
log    ${user['name']}

条件表达式

语法结构:

1
2
3
4
5
Run Keyword If  判断条件  其他关键字  参数

...     ELSE IF   判断条件  其他关键字  参数

...     ELSE  判断条件  其他关键字  参数

例如:

1
2
3
4
5
testCase
    ${n}    Set Variable    3
    Run Keyword If    ${n}==100    log    num is 100
    ...    ELSE IF    ${n}>100    log    num is more than 100
    ...    ELSE    log    num is less than 100

需要注意的是,关键字不区别大小写,但是这里的 ELSE ,ELSE IF 严格区分大小。

循环表达式

语法结构:

1
2
3
4
5
6
7
:For 变量  IN  序列(or 列表)

     关键字 参数值

:For 变量  IN RANGE 循环限量

     关键字  参数值

例如:

1
2
3
4
testCase
    ${t}    create list    123    qwe    dfg
    : FOR    ${x}    IN    @{t}
    \    log    ${x}    warn

参数与返回值

在 Robot Framework 中给关键字传递参数,或者从关键字中获取返回值是很常见的操作。

在关键字定义中,通过 [Arguments] 定义参数,也可以设置默认值 ${version}=0 。具有默认值的参数,使用时可以不传,否则必须传递。传递参数时,可以使用默认位置传递,也可以使用 key/value 的形式。

在关键字定义中,通过 [Return] 返回值。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
*** Test Cases ***
testCase
    ${tem} =    获取完整版本    18
    log    ${tem}    warn

*** Keywords ***
获取完整版本
    [Arguments]    ${version}=0
    ${full_version}    set variable    Test-${version}
    [Return]    ${full_version}

Variables 方式扩展 Python 变量

在 Robot Framework 中,有时需要使用 Python 处理一些逻辑,获取运算值。这时,可以利用 Variable 来扩展 Python 变量。

test.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# -*- coding: utf-8 -*-
import random

class Test(object):
    def __init__(self):
        pass

    def random(self):
        return random.randint(1, 100)

myrand = Test()
*** Settings ***
Variables  test.py

*** Test Cases ***
testCase
    log    ${myrand.random()}    warn

Library 方式扩展 Python 函数作为关键字

在 Robot Framework 中,有时需要使用 Python 封装一些操作,比如发送邮件等。这时,可以利用 Library 的方式,引入 Python 函数作为 Robot Framework 中的关键字。

mylib.py

1
2
3
# -*- coding: utf-8 -*-
def myprint(name):
    return "Your name is :" + name
1
2
3
4
5
6
*** Settings ***
Library           ../lib/mylib.py
*** Test Cases ***
testCase
    ${name}=    my_print    haha
    log    ${name}    warn

微信公众号