我们如何设置一个变量以便它可以在不同的测试套件中使用? [英] How can we set a variable such that it can be used in a different test suite?

查看:52
本文介绍了我们如何设置一个变量以便它可以在不同的测试套件中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 testSuite#1 中设置一个变量.在 testSuite#2 中使用上述变量.

I need to set an variable in testSuite#1. Use the above variable in testSuite#2.

我们是否有任何关键字可以做到这一点?我们可以在命令行中导出吗?

Do we have any keywords to do it? Can we export it at command line?

推荐答案

这不是一个好主意,因为您最终会在两个套件之间产生依赖关系,并且依赖于套件的运行顺序.

This is not a very good idea, because you end up with a dependency between two suites, and a dependency on the order that the suites are run.

话虽如此,您可以通过多种方式实现这一目标.

That being said, there are a couple of ways you can accomplish this.

第一种方法是使用设置全局变量 来自内置库的关键字.

The first method is to use the Set Global Variable keyword from the built-in library.

| | Set global variable | ${foobar} | this is foobar

设置环境变量

第二种方法是设置一个环境变量使用 OperatingSystem 库在两个套件之间共享.

Setting an environment varible

The second way would be to set an environment variable that can be shared between two suites, using the OperatingSystem library.

suite1.robot

suite1.robot

*** Settings ***
| Library | Operating System

*** Test Case ***
| Save a variable that other suites can see
| | Set environment variable | foobar | this is foobar

suite2.robot

suite2.robot

*** Settings ***
| Library | OperatingSystem

*** Test Cases ***
| Use a variable from another suite
| | Should be equal | %{foobar} | this is foobar

注意使用 % 而不是 $ 来访问变量.您还可以使用 Get Environment Variable 来获取值一个或多个变量.

Notice the use of % instead of $ to access the variable. You can also use Get Environment Variable to get the value of one or more variables.

这篇关于我们如何设置一个变量以便它可以在不同的测试套件中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆