Keyword Driven framework- Handling multiple windows and Frames

105 views
Skip to first unread message

Nagendra Kuppala

unread,
Jun 26, 2018, 1:03:01 AM6/26/18
to Selenium Users
Hi guys,

I have a requirement where I have to Select window by Index (Similar to Selenium IDE). 
Where:              Parent window      = win_ser_local
                         Child window         = win_ser_1
                         Sub-child window  = win_ser_2
                         and so on....

Need help with the below code:

// Keyword : selectWindow,    identifier : win_ser_local / won_ser_1


public String selectWindow(int identifier, String data) {
 APP_LOGS
.debug("Handling selectWindow");
 
try {
 
/* Map<String,String> mapWindow = new HashMap<>();
 String parent = driver.getWindowHandle();
 mapWindow.put("win_ser_local", parent);
 int count =1;
 for (String s : driver.getWindowHandles()) {
 if(s.equals(parent)) continue;
 mapWindow.put("win_ser_" + count, s);
 count++;


 }
 
 System.out.println("windows :: "+mapWindow);
 System.out.println("to be select windows :: "+identifier);
 driver.switchTo().window(mapWindow.get(identifier)); */

 
 
Set < String > s = driver.getWindowHandles();  
     
Iterator < String > ite = s.iterator();
     
int i = 1;
     
while (ite.hasNext() && i < 10) {
         
String popupHandle = ite.next().toString();
         driver
.switchTo().window(popupHandle);
         
System.out.println("Window title is : "+driver.getTitle());
         
if (i == identifier) break;
         i
++;
     
}
 
}
 
catch (Exception e) {
 
return Constants.KEYWORD_FAIL + " Could not select window by name. " + e.getMessage();
 
}
 
return Constants.KEYWORD_PASS;
 
}



Test case:

Keyword                         Target                                                          Data

 open              http
://www.seleniumeasy.com/test/                                
 clickAt                     id
=target
 clickAt                     id
=target
 clickAt                     id
=target     (Opens child window)
 selectWindow                win_ser_1    
(Select new window)
 type                        id
=target                                                         Some text
 clickAt                     id
=target      (close child window)
 close                       win_ser_1
 selectWindow                win_ser_local  
(Select parent window)
 clickAt                     id
=target     (Opens 2 windows. )
 selectWindow                win_ser_2    
(select sub-child window)
 type                        id
=target                                                         some text
 close                       win_ser_2      
(close sub-child window)
 selectWindow                win_ser_local  
(Select parent window)
 close                       win_ser_local  
(close parent window)

 
Same for "close" keyword, as shown in the above test case.

Similar functionality required for selectFrames:
where:    parent frame =    relative:parent
               second frame =   index = 0
               third frame =        index=1
              and so on...


Any help appreciated. Thanks in advance



Serguei Kouzmine

unread,
Jul 21, 2018, 1:18:34 AM7/21/18
to Selenium Users
Hello Nagendra

Please consider defining your requirements in a more clear way and include  a detailed test scenario and multi window featuring web site url which apparently needs to be public for such helper method to be developed for you by enthusiasts

Thanks

Serguei Kouzmine
Reply all
Reply to author
Forward
0 new messages