我有2个不同的测试用例,它们具有不同的URL。
两个URL之间的共同之处是唯一ID。我已经捕获了一个测试用例的URL,并拆分了该测试用例的URL,并将ID存储在变量中。我将该变量设置为全局变量,并尝试在第二个测试用例中使用它。
现在,我想在第二个测试用例中使用从第一个测试用例获得的ID。
我收到以下错误:
**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'))
]
如何在不同的测试案例中使用JourneyID的值?
答案 0 :(得分:3)
您可以使用一个全局变量来存储值,如下所示。
testOptions {
unitTests.all {
setIgnoreFailures(true)
}
}
但是在使用此变量之前,请创建一个名为“ JourneyID”的全局变量,并将一些静态值传递给它。 现在,您可以在其他测试用例中使用它。
希望这会对您有所帮助。