【问题标题】:How do I create dynamic user credentials and then use them in later REST requests in soapui pro?如何创建动态用户凭据,然后在 soapui pro 中的后续 REST 请求中使用它们?
【发布时间】:2013-08-28 18:35:14
【问题描述】:

总的来说,我对后端测试和所有脚本编写都很陌生,但这是我在使用 selenium IDE 进行前端测试时很容易做到的事情。基本上,在我的自动化中,我想在每次运行自动化时创建一个新的动态用户名/电子邮件和密码,并在该套件的所有进一步测试中使用这些凭据。

我创建了一个凭据测试步骤,用户名和密码设置如下:

用户名:testemail{Math.round (Math.random() * 100000)}@example.com 密码:woof{Math.round (Math.random() * 100000)}

在Registration API REST请求中,我输入了以下json

{

"email": "${Credentials#Username}" ,

"password": "${Credentials#Password}" ,

"country": "us" ,

"firstname": "John" ,

"lastname": "Smith" ,

"lang": "C"

}

但它似乎是这样通过的:

{

"email": "testemail{Math.round (Math.random() * 100000)}@example.com" ,

"password": "woof{Math.round (Math.random() * 100000)}" ,

"country": "us" ,

"firstname": "John" ,

"lastname": "Smith" ,

"lang": "C"

}

我做错了什么?感谢所有帮助!

【问题讨论】:

    标签: json api rest soapui


    【解决方案1】:

    随机值生成和设置属性应该在 groovy 脚本测试步骤中完成。在 groovy 脚本中这样写:

    import java.util.Random
    
    //generating random values
    Random rand = new Random()
    String username = "testmail" + rand.nextInt(100000) + "@example.com"
    String password = "woof" + rand.nextInt(100000)
    
    //setting test case properties
    testRunner.testCase.setPropertyValue("username", username);
    testRunner.testCase.setPropertyValue("password", password);
    

    在测试用例中,您可以通过 ${#testcase_name#property_name} 访问此属性。

    这里有更多关于房产的信息:
    http://www.soapui.org/Scripting-Properties/tips-a-tricks.html#1-accessing-properties-settings-and-names

    关于脚本在这里:
    http://www.soapui.org/Scripting-Properties/scripting-and-the-script-library.html

    【讨论】:

      猜你喜欢
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2021-05-12
      • 1970-01-01
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多