机器人框架:使用造假者生成帐户数据的前缀字符串 [英] Robot framework: Using faker to generate a prefix string for account data

查看:94
本文介绍了机器人框架:使用造假者生成帐户数据的前缀字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写测试用例,以测试添加帐户的功能.这意味着我需要为该帐户生成数据:名称,电子邮件,参考号和订单号.我当时在想,对于每个这些字段,我都可以生成一个带有前缀的随机单词或数字,以便可以使用脚本定期从数据库中删除这些条目.

I'm writing test cases that test the functionality of adding an account. This means that I need to generate data for the Account's: Name, email, reference no and order no. I was thinking that for each of these fields I could just generate a random word or number with a prefix so that I can use a script to delete these entries from the database regularly.

问题是,我不确定如何添加前缀或实际上只是使用大多数伪造者的关键字.

The issue is, I'm not sure how to add prefixes or indeed just use most of faker's keywords.

在我使用md5关键字来创建可用于测试用例的每个实例的字符串的那一刻,我已经在资源文件中创建了一个变量:

At the minute I'm using the md5 keyword to create a string that I can use for each instance of my test case, I've done so by creating a variable in my resource file:

*** Variables ***
${md5}                MD 5

然后我每当要编写前缀时都调用此变量(我在各个字段的末尾调用它,例如电子邮件:email+${md5}@gmail.com,引用:test $ {md5}等

I then call this variable whenever I wish to write my prefix (I call it at the end of various fields eg. email: email+${md5}@gmail.com, reference: test ${md5} etc

*** Keywords ***
Write username
    Input Text    a11y-username    test ${md5}

我不确定在Robot Framework中使用伪造者的实际文档在哪里,我在使用 http://fake-factory.readthedocs.org/en 来查找我要使用的提供程序,然后努力使它们在RF内部工作.

I'm not sure where the actual documentation is for using faker from within Robot Framework, I'm using http://fake-factory.readthedocs.org/en to find the providers I want to use and then struggle to get them working from within RF.

任何人都可以帮助我使random_int()正常工作,或指向RF中有关 ALL 伪造者提供商的相关文档.

Can anyone either help me get random_int() working, or point me to the relevant documentation for ALL faker providers in RF.

谢谢.

推荐答案

概述

使用伪造的关键字只需要调用它们,并将结果保存在变量中即可.您不能在变量表中使用伪造的关键字,您需要在测试用例或关键字中使用它们.但是,您可以使用python变量文件直接调用faker命令.

Overview

Using faker keywords requires nothing more than to call them, and save the results in a variable. You cannot use faker keywords in the variable table, you need to use them within a testcase or keyword. However, you can directly call the faker commands from with a python variable file.

例如,要获取地址,您可以调用Address关键字.由于fakerr关键字太笼统,我建议对关键字进行完全限定,以清楚地表明您正在生成虚假数据.

To get an address, for example, you would call the Address keyword. Because the faker keywords are so generic, I recommend fully qualifying the keywords to make it clear you're generating fake data.

例如:

*** Settings ***
| Library | FakerLibrary | WITH NAME | faker

*** Test Cases ***
| Example of using faker
| | ${address}= | faker.Address
| | log | address: ${address}

使用Random Int关键字

要获取随机整数,请使用Random Integer关键字:

Using the Random Int keyword

To get a random integer, use the Random Integer keyword:

| Example of using faker to get a random integer
| | ${number}= | faker.Random Int
| | log | my number is ${number}

初始化整个套件的变量

如果您想对整个套件使用相同的值,则可以编写一个关键字,该关键字使用例如:

*** Settings ***
| Library | FakerLibrary | WITH NAME | faker
| Suite Setup | Initialize Test Data

*** Test Cases ***
| Example of using faker to initialize suite variables
| | log | The suite address is ${address}
| | log | The suite md5 is ${md5}
| | log | The suite number is ${number}


*** Keywords ***
| Initialize test data
| | ${address}= | faker.Address
| | ${md5}= | faker.MD5
| | ${number}= | faker.Random Int
| | 
| | Set suite variable | ${address}
| | Set suite variable | ${md5}
| | Set suite variable | ${number}

文档

FakerLibrary关键字文档可从 https://guykisel.github.io/robotframework-faker/<获得/a>.

Documentation

FakerLibrary keyword documentation is available at https://guykisel.github.io/robotframework-faker/.

这篇关于机器人框架:使用造假者生成帐户数据的前缀字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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