如何使用Katalon将多个变量从一个测试用例返回到另一个测试用例

时间:2017-12-11 14:21:43

标签: katalon-studio

TC1:01_UserManagement / Login

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;

TestCase2:

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]

我收到以下错误: -

  

12-11-2017 04:31:40 PM - [ERROR] - 测试用例/ 01_UserManagement / Logout FAILED因为(of)变量' inlinetextofusername'没有为测试用例定义。

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

3 个答案:

答案 0 :(得分:1)

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

想象一下,您有这些测试用例Log in testDashboard test,并且需要将username的{​​{1}}和email传递给Log in test

Dashboard test中进入脚本模式,并在脚本末尾添加以下代码行

Log in test

这会将WebUI.callTestCase( findTestCase('Test Cases/dashboard test') , [('username'): username, ('email'):email] ) 脚本中的局部变量usernameemail传递给Log in test

通知:在应用此方法之前,您应该从下部dashboard test标签旁边的dashboard test标签中的第二个测试案例variables创建测试案例变量测试用例编辑器部分。

希望这很方便

答案 1 :(得分:0)

salesline                   salesline;
ExecutePermission           perm;
Thread                      myThread;
ttsBegin;

perm = new ExecutePermission();

if (!perm)
return;

perm.assert();

while select salesid from salestable
    where salestable.FG_BookingReferenceID == "BRF-0001"
{
    myThread = new Thread();
    myThread.setInputParm([salestable.SalesId]);
    if (myThread)
    {
        myThread.removeOnComplete(true);
        myThread.run(classnum(FG_ConfirmationEngine), staticMethodStr(FG_ConfirmationEngine,process));
    }
}

CodeAccessPermission::revertAssert();

返回值..

答案 2 :(得分:0)

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

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

testCase_1:

GlobalVariable.randomString = yourRandomValue

testCase_2:

String variableFromTestCase_1 = GlobalVariable.randomString

Screenshot

相关问题