Closed and Open Browser session. Re-Establishing session

HI @“Katalon Studio” cool tool.

however i got this issue which is blocking me perhaps some guidance from you guys is needed.

i am running a IE browser session where it automatically closed and then re-started ( i guess its for security purposes ) so it loses the IEdriver session.

11-24-2017 02:49:45 PM - [INFO] - Finding web element with id: ‘Object Repository/frame_main’ located by ‘By.xpath: //frame[count(. | //[@src = ‘bottom.asp’]) = count(//[@src = ‘bottom.asp’])][count(. | //[@name = ‘main’]) = count(//[@name = ‘main’])]’ in ‘30’ second(s)
11-24-2017 02:49:45 PM - [WARNING] - Timeout ‘0’ is invalid. Using default page load timeout: ‘30’
Nov 24, 2017 2:49:45 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: ‘400’ → incorrect JSON status mapping for ‘no such window’ (404 expected)
Nov 24, 2017 2:49:45 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: ‘400’ → incorrect JSON status mapping for ‘no such window’ (404 expected)
11-24-2017 02:49:45 PM - [WARNING] - Cannot take screenshot
11-24-2017 02:49:45 PM - [FAILED] - Unable to wait for object ‘Object Repository/input_B1’ to be clickable (Root cause: org.openqa.selenium.NoSuchWindowException: Unable to find elements on closed window
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘PJ-D3BYTC2’, ip: ‘10.69.1.139’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_102’
Driver info: com.kms.katalon.selenium.driver.CInternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:45480/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true}
Session ID: a042e5b1-ce30-4acb-8c19-8b0eb0c3f342
*** Element info: {Using=xpath, value=//frame[count(. | //[@src = ‘bottom.asp’]) = count(//[@src = ‘bottom.asp’])][count(. | //[@name = ‘main’]) = count(//[@name = ‘main’])]})
11-24-2017 02:49:45 PM - [FAILED] - Test Cases/ABC FAILED because (of) Unable to wait for object ‘Object Repository/input_B1’ to be clickable (Root cause: org.openqa.selenium.NoSuchWindowException: Unable to find elements on closed window
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘PJ-D3BYTC2’, ip: ‘10.69.1.139’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_102’
Driver info: com.kms.katalon.selenium.driver.CInternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:45480/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true}
Session ID: a042e5b1-ce30-4acb-8c19-8b0eb0c3f342

is there a way for Web keyword or a workaround to re-use/renew a running session? i cant see any existing keyword that can be used.

thanks Katalon

@“Vinh Nguyen” or someone whom can help.

i am trying to re-establish the session on IE

public class reusesession{

@Keyword
def Reusesession(String a) {
	
	DriverFactory.getWebDriver()
	
	WebDriver driver = DriverFactory.getWebDriver()
	
	Actions action = new Actions(driver)
	
	driver.get("www.google.com")
	
	}

}

but i got this :

Unable to get browser
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘PJ-D3BYTC2’, ip: ‘10.69.1.139’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_102’
Driver info: com.kms.katalon.selenium.driver.CInternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:3552/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true}
Session ID: a467a333-a00e-4ac8-8077-1c8954dd68c8

i am not sure if this is correct , can someone help and i do appreciate if you do.

i did notice if i were to try to Run on an existing browser it isnt there as well.

hmmm… how does katalon save or store cookies?
if i were to use this as an example , aint sure if this works for IE driver.

public void useStoredSessionInNewWindow() {
// initiate web driver and go to an website
_webDriver = new FirefoxDriver();
_webDriver.navigate().to(“www.abc.com”);

// add code to login in the website

// store the current session
Set cookiesInstance1 = _webDriver.manage().getCookies();
System.out.println("Coockies = "+cookiesInstance1);

// close the web driver instance
_webDriver.close();

// again initiate web driver and go to the same website. This will open the login page
_webDriver = new FirefoxDriver();
_webDriver.navigate().to(“www.abc.com”);

// add the stored session in the bew web driver instance
for(Cookie cookie : cookiesInstance1)
{
_webDriver.manage().addCookie(cookie);
}

// re-visit the page
_webDriver.navigate().to(“www.abc.com”);

// get the current session of new web driver instance
Set cookiesInstance2 = _webDriver.manage().getCookies();
System.out.println("Coockies = "+cookiesInstance2);

// notice that session of previous web driver instanse is achieved
Assert.assertEquals(cookiesInstance1, cookiesInstance2);

}

Can you tell me why do you need to do this?

@“Bernard Tan Jenn Haur” I modified your sent code to work on Katalon as below:


import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.ie.InternetExplorerDriver
import org.testng.Assert
import org.openqa.selenium.Cookie;
import org.junit.After
import org.openqa.selenium.By
import org.openqa.selenium.Capabilities
import org.openqa.selenium.remote.RemoteWebDriver


WebUI.openBrowser('')
WebUI.navigateToUrl("http://demo.guru99.com/selenium/cookie/selenium_aut.php")
WebDriver driver = DriverFactory.getWebDriver()
Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();
String browserName = cap.getBrowserName()
driver.findElement(By.name("username")).sendKeys("abc123");
driver.findElement(By.name("password")).sendKeys("123xyz");
driver.findElement(By.name("submit")).click();
WebUI.delay(2)
// store the current session
Set<Cookie> cookies1 = driver.manage().getCookies()
System.out.println("Coockies = "+cookies1);
// close the web driver instance
driver.close();
// Reinitiate web driver and go to website
WebDriver driver2
if (browserName == 'firefox') {
System.setProperty("webdriver.gecko.driver", "D:\\BrowserDriver\\geckodriver.exe")
driver2 = new FirefoxDriver();
driver2.get("http://demo.guru99.com")
}else{
WebUI.openBrowser('')
WebUI.navigateToUrl("http://demo.guru99.com")
driver2 = DriverFactory.getWebDriver()
}
// add the stored session in the bew web driver instance
for(Cookie cookie : cookies1)
{
driver2.manage().addCookie(cookie);
}
// re-visit the page, login information should be placed
driver2.get("http://demo.guru99.com/selenium/cookie/selenium_aut.php");
// get the current session of new web driver instance
Set cookiesInstance2 = driver2.manage().getCookies();
System.out.println("Coockies = "+cookiesInstance2);
// notice that session of previous web driver instanse is achieved
Assert.assertEquals(cookies1, cookiesInstance2);

@nhi @Vinh Nguyen

Vinh,Nhi

Merry Xmas and a Happy New Year to everyone at @“Katalon Studio”

Thanks for this sample , its a bit of an edge case situation of an legacy asp.net web where it somehow closes the existing IE browser and loads up a new one before a login ( in IE8 !!! ) so i am testing it on compatibility mode on IE11. I don’t think there is much web app currently which does such a thing but mine is one of those exceptions. Will try this out.