Several questions
This invites several questions:
- how many test cases are in your test suite?
- why is
Logout one of the test cases in the test suite?
- what are you trying to accomplish by refreshing the browser after the test case is done?
It also seems like none of these test cases are runnable on their own…
To answer YOUR specific question
It is not the question that you asked, but it is one that is obvious from reading your screenshots, and @Russ_Thomas suggested it: use a Test Listener. To that, I will suggest that what you’re tryna do, refresh the browser window after each Test Case, is a YAGNI (You Ain’t Gonna Need It).
How to use Test Listener
In your specific case, I would advise you set up and close the WebDriver before and after each test case, respectively…
I yoinked this from my project, and took out the SetUpDriver() instance. May it guide you…
package com.xxx.utils
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import com.kms.katalon.core.webui.driver.DriverFactory
import internal.GlobalVariable
public final class SMDWebDriverUtils {
private static WebDriver driver;
public static void SetUpDriver() {
/**
* TODO: set up this.driver, in accordance to your use case.
* In our real project, we have two Global Variables it depends on:
* - pathToKatalon
* - pathToUserDataDir
**/
DriverFactory.changeWebDriver(this.driver);
}
public static void CloseDriver() {
if (this.driver != null)
this.driver.quit()
}
public static void DoWebAction(Closure onAction) {
this.SetUpDriver();
onAction();
this.CloseDriver();
}
}
Your Test Listener should look something like this:
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.context.TestCaseContext
import com.xxx.utils.SMDWebDriverUtils
class NewTestListener {
/*** Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
SMDWebDriverUtils.SetUpDriver();
}
@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
SMDWebDriverUtils.CloseDriver();
}
}
There! Now you don’t have to worry about refreshing your window after test case completion…or even opening the browser window for that matter…because you’re starting anew with each test case!
If you MUST do web action after test case completion…
Notice that I have given you, for free, a method in SMDWebDriverUtils called DoWebAction. In your tearDownTestCase(), simply use it like this:
SMDWebDriverUtils.DoWebAction {
// TODO: test-suite-specific teardown logic, involving the browser being open, goes here...
}
The browser window will open right back up, perform the actions you spell out in the callback (they’re called Closures in Groovy), and close the browser for you, all between the test cases!
Obviously, I would suggest this for reasons other than needing to refresh a browser window…
If you MUST do something AFTER a specific test case is used…
…My suggestion to you would be to do it in the test case itself, like this:
import com.kms.katalon.core.annotation.TearDown
// ...your test case logic...
@TearDown
void close() {
// TODO: perform your test-case teardown here...
}
You could get the name of the test case you’re tearing down, but only if the last step it touches isn’t running some child test case, with this keyword:
package com.xxx.utils
import com.kms.katalon.core.configuration.RunConfiguration
public final class SMDTestCaseUtils {
public static String CurrentTestCaseKey = "current_testcase";
public static final String GetTestCaseName() {
return RunConfiguration.getExecutionProperties().get(this.CurrentTestCaseKey);
}
}
If your test case doesn’t contain any child test cases, SMDTestCaseUtils.GetTestCaseName() will return the name of the test case you are tearing down, even in the tearDownTestCase() method.
Else, it will return the name of the child-most test case, if calling it is the last step in your test case. A Test Listener will get around that problem.