概述
使用faker关键字只需要调用它们,并将结果保存在变量中。不能在变量表中使用faker关键字,需要在testcase或关键字中使用它们。但是,可以使用python变量文件直接从中调用faker命令。在
例如,要获得地址,可以调用Address关键字。因为伪造的关键字是如此通用,我建议完全限定这些关键字,以清楚地表明你正在生成虚假数据。在
例如:*** Settings ***
| Library | FakerLibrary | WITH NAME | faker
*** Test Cases ***
| Example of using faker
| | ${address}= | faker.Address
| | log | address: ${address}
使用Random Int关键字
要获取随机整数,请使用random integer关键字:
^{pr2}$
初始化整个套件的变量
如果要对整个套件使用相同的值,可以编写一个关键字,使用Set Suite Variable关键字设置某些套件级别的变量。在
例如:*** 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}
文件