- I have some situations that need to take an action (like capture screenshot,…) after each step in a test case.
- I find out that default Test Event Listener of Katalon does not support this situation.
- I don’t want to create a step take screenshot manually after each step.
- Anyone have faced this issue or any idea can help me?
Yep thats works fine but still need more custom, its highlight the element before step its take an action any idea how to get the screenshot after step do an action?
def result
try {
result = delegate.metaClass.getMetaMethod(name, args).invoke(delegate, args)
if (name in influencedKeywords) {
com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.takeScreenshot()
}
} catch(Exception e) {
System.out.println("Handling exception for method $name")
}
return result
}
Every keyword in this list uses multiple parameters : a testObject and a value at least. You don’t have to care about how many parameters your method has, because they will all be passed to the desired “name” method using “args”.
So i just need to add list of action in influencedKeywords and everything will be screenshot (based on action in influence keywords ) without adding additional param?
and also i got this error when i run the script
2019-02-25 17:04:37.239 DEBUG testcase.SS - 3: verifyElementPresent(findTestObject(“Object Repository/Page_PetClinic a Spring Framework/a_Find owners”))
Handling exception for method verifyElementPresent
java.lang.NullPointerException: Cannot invoke method invoke() on null object
2019-02-25 17:04:37.280 DEBUG testcase.SS - 4: delay(1)
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.reflection.CachedMethod$invoke.call(Unknown Source)
…
3: verifyElementPresent(findTestObject(“Object Repository/Page_PetClinic a Spring Framework/a_Find owners”), 0)
2019-02-25 18:19:39.567 WARN c.kms.katalon.core.helper.KeywordHelper - Timeout ‘0’ is invalid. Using default page load timeout: ‘2’
Handling exception for method verifyElementPresent
java.lang.ArrayIndexOutOfBoundsException: 1
at org.codehaus.groovy.runtime.dgmimpl.arrays.ObjectArrayGetAtMetaMethod.invoke(ObjectArrayGetAtMetaMethod.java:41)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
i just realize its not only the warning but the screenshot is not taken the code goes into exception its not invoke my screenshot code
do you have any idea why its go into exception?
full error message is like this
2019-02-26 10:04:38.979 DEBUG testcase.SS - 3: verifyElementPresent(findTestObject(“Object Repository/Page_PetClinic a Spring Framework/a_Find owners”), 10)
TestObject - ‘Object Repository/Page_PetClinic a Spring Framework/a_Find owners’
Handling exception for method verifyElementPresent
java.lang.ArrayIndexOutOfBoundsException: 1
at org.codehaus.groovy.runtime.dgmimpl.arrays.ObjectArrayGetAtMetaMethod.invoke(ObjectArrayGetAtMetaMethod.java:41)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.invoke(PojoMetaMethodSite.java:51)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at com.ss.step.HighlightElement.screenshotAftermethod(HighlightElement.groovy:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at com.ss.step.HighlightElement$_pandemic_closure1.doCall(HighlightElement.groovy:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.Closure.call(Closure.java:414)
at org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod.invoke(ClosureStaticMetaMethod.java:62)
at groovy.lang.ExpandoMetaClass.invokeStaticMethod(ExpandoMetaClass.java:1136)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at Script1550474641931.run(Script1550474641931.groovy:19)
…
public static void screenshotAftermethod(String action, TestObject testObject){
String a = GlobalVariable.G_Step
String [] b = a.split("-")
int c = b[1].toInteger()
int d = c + 1
GlobalVariable.G_Step = ‘Step-’+d
new File(RunConfiguration.getReportFolder()+"/SS/")
GlobalVariable.RESULTS_DIR = RunConfiguration.getReportFolder()+"/SS/"
WebUI.takeScreenshot(GlobalVariable.RESULTS_DIR+GlobalVariable.G_Step+". “+action.toLowerCase().capitalize()+” - “+getScreenshotName(testObject)+”.png", FailureHandling.STOP_ON_FAILURE) //WebUI.takeScreenshot("+GlobalVariable.G_Step+". “+action.toLowerCase().capitalize()+” - “+getScreenshotName(testObject)+”.png")
}