Reusing active browser for every test case


#1

I need help on reusing active browser whenever I run my test cases. I already done this Check if browser is already opened but seems to be working when running only one test case but when running all test cases in test suite it doesn’t work

class ReusingActiveBrowser {
@BeforeTestCase
def onTestCaseStart() {
	try
	{
		WebUI.comment('Browser is still active')
	}
	catch(BrowserNotOpenedException)
	{
		WebUI.openBrowser(GlobalVariable.Bitpunter)
		WebUI.maximizeWindow()
	}
}

}


#2

Hi @aldrine.reynon

Please post the console log when it doesn’t work in a test suite. I think it is supposed to work.


#3

here @ThanhTo :


#4

Hi, please copy and paste the entire text


#5

2019-11-29 12:44:39.947 INFO c.k.katalon.core.main.TestSuiteExecutor - START Test Suites/Landing
Pages/Bitpunter pages
2019-11-29 12:44:39.991 INFO c.k.katalon.core.main.TestSuiteExecutor - hostName = Aldrine Reynon -
ARVINGALMAN_PC
2019-11-29 12:44:39.992 INFO c.k.katalon.core.main.TestSuiteExecutor - os = Windows 10 64bit
2019-11-29 12:44:39.993 INFO c.k.katalon.core.main.TestSuiteExecutor - hostAddress = 10.14.11.6
2019-11-29 12:44:39.994 INFO c.k.katalon.core.main.TestSuiteExecutor - katalonVersion = 7.1.0.1
2019-11-29 12:44:40.307 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2019-11-29 12:44:40.307 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Bitpunter Landing page/As a Guest ISBAT change page content language
2019-11-29 12:44:40.560 INFO c.k.k.c.keyword.builtin.CommentKeyword - Browser is still active
2019-11-29 12:44:40.931 DEBUG Guest ISBAT change page content language - 1: driver = getWebDriver()
2019-11-29 12:44:40.998 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Bitpunter Landing page/As a Guest ISBAT change page content language FAILED.
Reason:
com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘ARVINGALMAN_PC’, ip: ‘10.14.11.6’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: DriverFactory$getWebDriver
at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriverIsOpen(DriverFactory.java:786)
at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriver(DriverFactory.java:771)
at com.kms.katalon.core.webui.driver.DriverFactory.getWebDriver(DriverFactory.java:757)
at com.kms.katalon.core.webui.driver.DriverFactory$getWebDriver.call(Unknown Source)
at As a Guest ISBAT change page content language.run(As a Guest ISBAT change page content language:26)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1575002677023.run(TempTestSuite1575002677023.groovy:36)

2019-11-29 12:44:41.017 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/Bitpunter Landing page/As a Guest ISBAT change page content language
2019-11-29 12:44:41.025 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2019-11-29 12:44:41.025 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Bitpunter Landing page/As a Guest ISBAT view Contact page
2019-11-29 12:44:41.047 INFO c.k.k.c.keyword.builtin.CommentKeyword - Browser is still active
2019-11-29 12:44:41.452 DEBUG t.As a Guest ISBAT view Contact page - 1: click(findTestObject(“PageBitpunter/a_contact”))
2019-11-29 12:44:41.691 WARN c.k.k.c.w.h.s.WebUIScreenCaptor - Cannot take screenshot
2019-11-29 12:44:41.701 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to click on object ‘Object Repository/PageBitpunter/a_contact’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/PageBitpunter/a_contact’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:103)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click.call(Unknown Source)
at As a Guest ISBAT view Contact page.run(As a Guest ISBAT view Contact page:18)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1575002677023.run(TempTestSuite1575002677023.groovy:36)
Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘ARVINGALMAN_PC’, ip: ‘10.14.11.6’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: unknown
at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriverIsOpen(DriverFactory.java:786)
at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriver(DriverFactory.java:771)
at com.kms.katalon.core.webui.driver.DriverFactory.getWebDriver(DriverFactory.java:757)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:712)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1109)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:68)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:103)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click.call(Unknown Source)
at Script1573797541126.run(Script1573797541126.groovy:18)
… 13 more
)
2019-11-29 12:44:41.708 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Bitpunter Landing page/As a Guest ISBAT view Contact page FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/PageBitpunter/a_contact’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:103)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click.call(Unknown Source)
at As a Guest ISBAT view Contact page.run(As a Guest ISBAT view Contact page:18)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1575002677023.run(TempTestSuite1575002677023.groovy:36)
Caused by: com.kms.katalon.core.webui.exception.BrowserNotOpenedException: Browser is not opened
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘ARVINGALMAN_PC’, ip: ‘10.14.11.6’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: unknown
at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriverIsOpen(DriverFactory.java:786)
at com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriver(DriverFactory.java:771)
at com.kms.katalon.core.webui.driver.DriverFactory.getWebDriver(DriverFactory.java:757)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:712)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1109)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:68)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 19 more

2019-11-29 12:44:41.717 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/Bitpunter Landing page/As a Guest ISBAT view Contact page


#6

This line does not throw error if the browser is not opened. Comment keyword doesn’t use a web driver, it just prints stuffs. Please try to replace it with WebUI.click on a dummy Test Object instead.


#7

Thanks @ThanhTo, will try it


#8

Thanks @ThanhTo it works now