Himanshu Jain
Himanshu Jain

Reputation: 55

Katalon: How to use the result of one test case in an another test case?

I have 2 different test cases which have different URL's.

Common thing between two URL's is the unique ID. I have captured the URL of one test case and split the URL of that test case and stored the ID in a variable. I made that variable a global variable and tried to use it in 2nd test case.

Now, I want to use that ID obtained from 1st test case in 2nd test case.

I got the error below:

**Test Case FAILED because (of) org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ba0eed2c-cba8-11e8-86a5-02e9072e0d95' with class 'java.lang.String' to class 'internal.GlobalVariable'**

**Code for Test Case A is as follows:**

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

WebUI.click(findTestObject('PO_ID_Details_Passport/label_Select Document Type'))

WebUI.click(findTestObject('PO_ID_Details_Passport/li_Passport'))

WebUI.setText(findTestObject('PO_ID_Details_Passport/input_PO_PASSPORT_NUMBER'), 'Test123456')

WebUI.setText(findTestObject('PO_ID_Details_Passport/input'), '25')

WebUI.setText(findTestObject('PO_ID_Details_Passport/input_1'), '05')

WebUI.setText(findTestObject('PO_ID_Details_Passport/input_2'), '2025')

// Capture the current URL and split the URL to get the unique ID.
String url = WebUI.getUrl()
String getQueryString = url.split("\\?")[1]
String[] getFields = getQueryString.split("&")
Map<String, String> fieldValueMap = new HashMap<String, String>()

for(String field : getFields) {
    fieldValueMap.put(field.split("=")[0], field.split("=")[1])
}

println fieldValueMap.get("JID")

GlobalVariable JourneyID=fieldValueMap.get("JID")

//return JourneyID

Thread.sleep(5000)

WebUI.click(findTestObject('PO_ID_Details_Passport/Upload_File'))

Thread.sleep(3000)

//Sample path. Change it to your saved location of autoIT script
Runtime.getRuntime().exec('ABC')

Thread.sleep(5000)

WebUI.click(findTestObject('PO_ID_Details_Passport/i'))
]

How can I use the value of JourneyID in different test case?

Upvotes: 3

Views: 3064

Answers (1)

Ankit Gupta
Ankit Gupta

Reputation: 116

you can use A global variable to store value as shown below.

GlobalVariable.JourneyID=fieldValueMap.get("JID")

But before using this variable, create a Global Variable named 'JourneyID' and pass some static value to it. Now you can use it in other test cases.

Hope this will help you.

Upvotes: 3

Related Questions