【问题标题】:How to return multiple variables from one test case to another using Katalon如何使用 Katalon 将多个变量从一个测试用例返回到另一个测试用例
【发布时间】:2018-05-25 02:18:44
【问题描述】:

TC1:01_UserManagement/登录

String u = WebUI.getAttribute(findTestObject('SignInPage/txt_username'), 'placeholder')

WebUI.setText(findTestObject('SignInPage/txt_username'), username)

String p = WebUI.getAttribute(findTestObject('SignInPage/txt_password'), 'placeholder')

CustomKeywords.'com.fcm.utilities.ClearTextField.ClearText'(findTestObject('SignInPage/txt_password'))

WebUI.setText(findTestObject('SignInPage/txt_password'), password)

WebUI.click(findTestObject('SignInPage/btn_signinButton'))

Map map = [:]
map.put('inlinetextofusername',u)
map.put('inlinetextofpassword',p)
map.each{ k, v -> println "${k}:${v}" }
return map;

测试用例2:

Map TC_1_called = WebUI.callTestCase(findTestCase('01_UserManagement/Login'), [('username') : 'Anna', ('password') : 'Analyst_2017',('inlinetextofusername'):'',('inlinetextofpassword'):''], 
    FailureHandling.STOP_ON_FAILURE)

println(TC_1_called[inlinetextofusername])

println(TC_1_called[inlinetextofpassword]

我收到以下错误:-

2017 年 12 月 11 日下午 4:31:40 - [错误] - 测试用例/01_UserManagement/注销失败,因为没有为测试用例定义变量“inlinetextofusername”。

如何在测试用例 1 中获取存储在 Map 中的值并在测试用例 2 中使用。

【问题讨论】:

    标签: katalon-studio


    【解决方案1】:
    Map TC_1_called = WebUI.callTestCase(findTestCase('01_UserManagement/Login'), [('username') : 'Anna', ('password') : 'Analyst_2017',('map'):''], 
        FailureHandling.STOP_ON_FAILURE)
    

    这会返回值..

    【讨论】:

      【解决方案2】:

      如果您想在 Katalon Studio 中将值从一个测试用例传递到另一个,您应该将这些值从 Test Case A 传递到 Test Case B

      假设您有这些测试用例Log in testDashboard test,您需要将usernameemailLog in test 传递到Dashboard test

      Log in test 中进入脚本模式,并在脚本末尾添加这行代码

      WebUI.callTestCase( findTestCase('Test Cases/dashboard test')  , [('username'): username, ('email'):email]  )
      

      这会将局部变量 usernameemailLog in test 脚本传递到 dashboard test

      注意:在应用此方法之前,您应该在测试用例编辑器下方的script 选项卡旁边的variables 选项卡中为第二个测试用例dashboard test 创建测试用例变量。

      希望这能派上用场

      【讨论】:

        【解决方案3】:

        我在将具有随机值的变量传递给另一个测试用例时遇到问题。

        解决方案:我用空字符串创建了一个全局变量,然后在我的 testCase_1 上设置了一个随机值的全局变量。我现在可以在不调用 testCase_1 的情况下将该全局变量调用到我的 testCase_2。但是您必须先在您的测试套件上执行 testCase_1。

        testCase_1:

        GlobalVariable.randomString = yourRandomValue

        testCase_2:

        String variableFromTestCase_1 = GlobalVariable.randomString

        Screenshot

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-25
          • 2020-05-21
          • 2020-06-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多