Robot Framework学习笔记(八)------ride标签使用

一、edit标签使用

1、导入库

点击 Edit 标签页右侧的“Library”按钮,来添加库。在添加库之前,首先库已经在 Python 下进行了安装。如,添加“Selenium2Library”库

如果添加的库不存在或库名错误,将会显示为红色,很色表示正常;

如果你是在“测试套件”中添加的库,那么这个库中所提供的关键字可以被当前测试套件下的用例使用;

如果你是在“测试项目”中添加的库,当前项目下的测试用例不能使用库中的关键字,需要在用例相应的“测试套件”中再次添加库。

按 F5 就可以查看库中所提供的关键字:

2、导入资源

点击 Edit 标签页右侧的“Resource”按钮来添加资源。这个资源一般为项目相关的文件。比如,项目
的自定义关键字文件。

(1)创建Resource

(2)定义和使用关键字

(3)导入ReSource

关于添加资源的作用域与库一样。我这里是添加到的测试套件中,那么它的作用域就是当前测试套件下的所有用例。

(4)使用关键字

3、定义变量

点击 Edit 标签页右侧的“Add Scalar”按钮来创建变量。这里创建的变量可以被整个测试套件中的用例所使用。也可以认为是一个“公共变量”。

(1)创建一个变量

Name 用于定义变量名:${hi},Value 用于给变量赋值。

(2)使用变量

 4、定义列表变量

列表变量可以用来定义一维或二维数组。下面我们就来创建一个列表变量。点击 Edit 标签页右侧的“Add List”按钮来创建变量

(1)定义列表变量

Name 定义变量名为:${student},Value 填写列表变量的值

(2)使用列表变量

二、Text Edit 标签

text edit中显示的是测试套件的txt,也就是所有的测试用例,切换到E: obot测试项目测试套件.txt也能看到这个文件。平时可以直接切换到text edit编写测试用例

 三、run标签

(1)运行与停止

在 Run 标签页提供了运行与停止的按钮,使用很简单。可是你知道到点击“运行”按钮的时候,RobotFramework 是怎么执行“测试套件.txt”文件的么?点击“停止”按钮的时候,Robot Framework 又做了什么操作来终止用例的执行的?

首先打开 C:Python27Libsite-packages obotide un 目录下的 process.py 文件。

import os
import time
import tempfile
import subprocess


class Process(object):

    def __init__(self, command):
        self._command = self._parse_command(command)
        self._process = None
        self._error = None
        self._out_file = None
        self._out_path = None
        self._out_fd = None

    def _parse_command(self, command):
        if isinstance(command, basestring):
            return [val.replace('<SPACE>', ' ') for val in command.split()]
        return command

    def start(self):
        self._out_fd, self._out_path = 
                        tempfile.mkstemp(prefix='rfproc_', suffix='.txt',
                                         text=True)
        self._out_file = open(self._out_path)
        if not self._command:
            self._error = 'The command is missing from this run configuration.'
            return
        try:
            self._process = subprocess.Popen(self._command, stdout=self._out_fd,
                                             stderr=subprocess.STDOUT)
        except OSError, err:
            self._error = str(err)

    def is_finished(self):
        return self._error is not None or self._process.poll() is not None

    def stop(self):
        self._process.kill()

    def wait(self):
        if self._process is not None:
            self._process.wait()

    def get_output(self, wait_until_finished=False):
        """Returns the output produced by the process.

        If ``wait_until_finished`` is True, blocks until the process is
        finished and returns all output. Otherwise the currently available
        output is returned immediately.

        Currently available output depends on buffering and might not include
        everything that has been written by the process.
        """
        if self._error:
            self._close_outputs()
            return self._error
        if wait_until_finished:
            self._process.wait()
        output = self._out_file.read()
        if self.is_finished():
            self._close_outputs()
        return output

    def _close_outputs(self):
        self._out_file.close()
        os.close(self._out_fd)
        self._remove_tempfile()

查看标红的部分即可:

首先看 start()方法,通过 tempfile 模块的 mkstemp()方法找到“txt”文件,也就是“测试套件.txt”文这类件。接着通过 open()方法打开。

在 get_output()方法中通过 read()方法来读取“txt”文件。最后把读取的文件的赋值给变量 output 并返回。

在_close_outputs()方法中通过 close()关闭打开的“txt”文件。

停止测试用例的执行非常单间,由 stop()方法实现,通过调用 kill()将用例的执行进程杀死。

 (2)报告与日志

当用例运行结束,Robot Framework 生成三个文件:output.xml、log.html 和 report.html。output.xml 记录的测试结果是 xml 文件,这个文件不够直观。相比较而言 log.html 和report.html 报告要直观得多,因为是 html 格式的嘛。

查看 log.html 文件,点击 Run 标签而上的“Log”按钮,通过默认浏览器打开。在 log.html 文件中可以查看用例执行的每一步,适合跟踪定义问题。



原文地址:https://www.cnblogs.com/pachongshangdexuebi/p/6709790.html