GUI测试横盘必须配置各种目的。测试工程师可能希望配置测试,以便将特定的测试数据用作被测应用程序的输入。或者必须使用程序参数的变体执行测试本身的应用程序。

虽然许多测试是自包含的,但是存在在外部完成配置的情况,例如通过驱动测试执行的调度器,例如连续积分服务器。在这些情况下,squishrunner 可执行文件可用于将参数传递给测试脚本。测试脚本可以访问这些参数并根据值采用其行为。

将脚本参数传递给SquishRunner

The squishrunner option that supports this is called --scriptargs. It has to be specified at the very end of the complete squishrunner command call. All arguments which are specified after --scriptargs are passed to the executed script.

The following example shows a squishrunner call that passes two arguments to the test script:

./squishrunner --testsuite /path/to/suite --testcase tst_case1 --reportgen xml3.2,/path/to/result --scriptargs argument1 argument2

Accessing these arguments in the test script depends on the scripting language that is used. Assuming that Python is used, we need to use the sys module which provides a list of command line arguments through the argv variable. The following snippet shows how to log all arguments to the Squish Test Result. Visit the Squish documentation to learn 如何访问JavaScript测试脚本中的参数。

import sys
def main():
    test.log('Number of arguments:' + str(len(sys.argv)) + 'arguments.')
    test.log('Argument List: ' + str(sys.argv))

When executing the snippet above, you will notice that the first field, argv[0], holds the name of the script itself. This is common practice in many scripting languages. The first argument we pass to the squishrunner --scriptargs option can be accessed through argv[1].

通过脚本参数配置示例应用程序

让’返回到最初的示例之一:我们希望通过程序参数来配置AUT。让’s assume this argument is called --nolauncher --autoconnect. The command for such an application startup could look like this:

./exampleApplication --nolauncher --autoconnect

To pass these arguments to the test script, the squishrunner call would look like this:

./squishrunner --testsuite /path/to/suite --testcase tst_case1 --reportgen xml3.2,/Users/flo/tmp/result --scriptargs --nolauncher --autoconnect

Finally, we need to access the arguments in the test script itself, and pass it to the startApplication call:

import names
import sys

def main():
    autCommand = "exampleApplication"
    for i in range(1, len(sys.argv)):
        autCommand = autCommand + " " + sys.argv[i]
        startApplication(autCommand)
        ...

2 Comments

好的。
是否有一种方法可以将参数传递给测试脚本,从鳞片IDE运行时?

    目前,鳞片IDE不支持这一点。因此’S建议实现一个倒退分支,以确保即使没有传递脚本参数,也可以确保脚本工作,例如通过设置默认值。无论如何,我将此转发为产品管理的功能请求。非常感谢您的反馈!

发表评论

您的电子邮件地址不会被公开。 必需的地方已做标记 *

复制链接