Is it possible to access an already open browser with robot framework?

2.2k views Asked by At

For test cases using robot framework and Selenium2Library, we normally start with opening the browser and then doing actions on that browser.

But for the purpose of quickly testing steps within my test case (for testing my test itself) it would be nice if I could just run for example 'click button' on an already existing browser session.

This saves a lot of time if my AUT has to be in a certain screen and state to perform a certain action. That way I can automate and test a certain step in isolation without needing the script to perform all the steps required before that first.

Is there any selenium2libary keyword or some other way I might do this?

Thank you!

1

There are 1 answers

0
Shubham Jain On

You do not need robotframe for same. You can check WindowHandles. If the windowHandle having value more then 0 then there is more window open then default one.

The code looks something like below. You can make changes in below if the window is more than 1. Try the following code:

String subWindowHandler;
Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
int i=handles.size();
while (iterator.hasNext()){
    subWindowHandler = iterator.next();
}
if(i>0) {
    driver.switchTo().window(subWindowHandler); // switch to popup window
    driver.close();
}

Hope it will help you :)