使用 getDescription()时报错


#1

2019-05-22 17:45:29.719 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Login/testkeywordlogin
2019-05-22 17:45:29.813 ERROR c.k.k.core.context.internal.TestHooker - :x: java.lang.NullPointerException: Cannot invoke method getName() on null object


#2

So with the very minimal information you have provided theres something not right with the object, make sure that the path is correct for the object. It wont be able to complete the function if the object is NULL

Please provide more info so we can try find a solution


#3
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 WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.annotation.SetUp
import com.kms.katalon.core.annotation.SetupTestCase
import com.kms.katalon.core.annotation.TearDown
import com.kms.katalon.core.annotation.TearDownTestCase

/**
 * Some methods below are samples for using SetUp/TearDown in a test suite.
 */

/**
 * Setup test suite environment.
 */

@SetUp(skipped = false) // Please change skipped to be false to activate this method.

def setUp(TestCase testcase) {
	println testcase.getName()
	// Put your code here.
}

2019-05-22 18:06:25.544 ERROR c.k.katalon.core.main.TestSuiteExecutor  - ❌ Cannot invoke method getName() on null object

#4

How do you expect this to work? What are you expecting to happen? testcase.getName() is NULL becuase nothing has happend in the steps before for it to have stored anything for it to print.


#5

Thank you for your reply. I want to print the name of the current case. I have used this method but I am getting an error, so I will ask for help.


#6

Yea you may be right, im not sure. Ill step back and let someone else help you out with this one.


#7
import com.kms.katalon.core.configuration.RunConfiguration
println RunConfiguration.getExecutionSourceName()

#8

Thank you, perfect solution to my problem!