TestListener: execute before and after test method twice

Katalon V 7.02

I have this code implemented on my TestListener –

class TestListener {

@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
	println testCaseContext.getTestCaseId()
	println testCaseContext.getTestCaseVariables()
	
	WebUI.openBrowser('')
	
	WebUI.navigateToUrl("http://${GlobalVariable.url}/")
	
	CustomKeywords.'com.xxxxx.utils.commonMethod.login_InternalData'
              ("${GlobalVariable.username}","${GlobalVariable.password}")
	
}


@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
	
	CustomKeywords.'com.xxxxx.utils.commonMethod.logout'()
	
	WebUI.closeBrowser()
	
	println testCaseContext.getTestCaseId()
	println testCaseContext.getTestCaseStatus()

}

}
Note: I removed other method which does not have an issue.

While executing a single test case (from the scripts view page), I notice I am login in twice and only to first one stop at after login and then it close the browser open another browser login and finished the test case. Note the first case does report any failure. Also I notice in the log that samplebefore and after testcase method called twice.
And this the proof that sampleAfterTestCase method called twice. from console:
“Caused by: org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘ZELUS’, ip: ‘10.1.101.151’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: RemoteWebDriver”

So, not sure why samplebefore and after testcase method called twice? Bug?

1 Like

Hi @mohammad.zaman

Does this work as expected on version 6.x ? I could not reproduce this problem on 7.0.2

demo

Please provide the full console log, and the relevant test scripts, you can remove the sensitive information.

Also, (just in case) please close the project, go to its location then delete two directories /bin, /Libs and try again.

Hi,
Here is the simple test without calling custom keyword and see the result… I did delete the bin and lib folder but still same issue.

KatalonIssue

That is weird, can you try executing the test on earlier versions ? Does this happen across projects ?

here is the screenshot same result…
Katalon 6.3.3

Are you using/developing any plugins, either Custom Keywords or Katalon plugins ? Please reload plugins and let me see the list of plugins.

Plugins… re loaded. ran and same result!.

Please zip the project and post it here, I cannot reproduce this issue on my side.

thanks for your time here is the zip file…

TestCase.zip (28.4 KB)

Unfortunately I can’t still reproduce this issue. I noticed in your project there’s a folder Drivers which contain a MultiSourcedProperties-1.0.jar which was developed by @kazurayam

At this point we’re grasping at straws here, can you delete that file and re-run the test ?

@Russ_Thomas, @Brandon_Hein, @kazurayam

Call out to people who probably can offer different perspectives.

I removed that file and also import call in the TestListener class. I ran it …>same result.

One more try I guess. I am kind of stubborn. Can you add the test case into a test suite, and then execute that test suite from the command line ?

Just so we’re sure it is not curable by “refreshing” the project which command line execution will do.

1 Like

Weird indeed.

@mohammad.zaman

  1. Set a breakpoint in the beforeTextCase method.
  2. Launch the test case in the debugger.
  3. When the breakpoint is hit, take a screenshot of the execution stack (the Debug panel that appears on the left of the screen). Make sure you capture ALL of it!
  4. Click the debugger Resume button image
  5. Let the test run. When the breakpoint is hit again, take another screenshot of the Debug panel - Make sure you capture all of it.
  6. Post the screenshots here.

If you want to be super helpful, repeat the above procedure for the AfterTestCase method.

1 Like

@ThanhTo I assume the stacktrace will give you guys a clue as to where the second invocation originated.

1 Like



@mohammad.zaman

While you’re at, please try:

Sorry, @mohammad.zaman, I meant this panel:

image

Click the circled button and drag that panel to make it full size. Take a screenhot of it each time the breakpoint is hit.




CLI log:


Test Suites/Demo_Suite - Chrome - 20191028_155337…0/1(0%)

2019-10-28 15:53:39.031 INFO c.k.katalon.core.main.TestSuiteExecutor - START Test Suites/Demo_Suite
2019-10-28 15:53:39.063 INFO c.k.katalon.core.main.TestSuiteExecutor - hostName = xxxxxx
2019-10-28 15:53:39.065 INFO c.k.katalon.core.main.TestSuiteExecutor - os = Windows 10 64bit
2019-10-28 15:53:39.066 INFO c.k.katalon.core.main.TestSuiteExecutor - hostAddress = 10.1.101.151
2019-10-28 15:53:39.068 INFO c.k.katalon.core.main.TestSuiteExecutor - katalonVersion = 7.0.4.1
Test Suites/Demo_Suite
Test Suites/Demo_Suite
2019-10-28 15:53:39.275 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2019-10-28 15:53:39.275 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/TestCase1
Test Cases/TestCase1
[:]
Test Cases/TestCase1
[:]
2019-10-28 15:53:39.450 DEBUG testcase.TestCase1 - 1: println(“Hello world”)
Hello world
Test Cases/TestCase1
PASSED
Test Cases/TestCase1
PASSED
2019-10-28 15:53:39.504 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/TestCase1
Test Suites/Demo_Suite
2019-10-28 15:53:39.786 INFO com.kms.katalon.core.util.KeywordUtil - Start generating HTML report folder at: C:\Test\TestCase\Reports\20191028_155337\Demo_Suite\20191028_155337…
2019-10-28 15:53:39.818 INFO com.kms.katalon.core.util.KeywordUtil - HTML report generated
2019-10-28 15:53:39.819 INFO com.kms.katalon.core.util.KeywordUtil - Start generating CSV report folder at: C:\Test\TestCase\Reports\20191028_155337\Demo_Suite\20191028_155337…
2019-10-28 15:53:39.841 INFO com.kms.katalon.core.util.KeywordUtil - CSV report generated
Test Suites/Demo_Suite
2019-10-28 15:53:39.906 INFO c.k.katalon.core.main.TestSuiteExecutor - --------------------
2019-10-28 15:53:39.906 INFO c.k.katalon.core.main.TestSuiteExecutor - END Test Suites/Demo_Suite
2019-10-28 15:53:39.906 INFO c.k.katalon.core.main.TestSuiteExecutor - ====================
Launcher status after execution process completed: Running
Start writing execution.uuid file to folder: C:\Test\TestCase\Reports\20191028_155337\Demo_Suite\20191028_155337
Start generating JUnit report folder at: C:\Test\TestCase\Reports\20191028_155337\Demo_Suite\20191028_155337…
JUnit report were generated at folder: C:\Test\TestCase\Reports\20191028_155337\Demo_Suite\20191028_155337
For real-time monitoring and better reporting capabilities please integrate this project with Katalon TestOps (more details at https://docs.katalon.com/katalon-analytics/docs/integration-with-katalon-studio.html#enable-integration)


Test Suites/Demo_Suite - Chrome - 20191028_155337…1/1(100%)

Execution completed. Exit code: 0.
Start clean up session
End check license task
End clean up session
Start release license task
License released
End release license task
All launchers terminated