Keyword Driven framework- Handling multiple windows and Frames

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Keyword Driven framework- Handling multiple windows and Frames

Nagendra Kuppala
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



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/929c70ac-d5c0-4eb6-a4f3-38d5e82a8007%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Keyword Driven framework- Handling multiple windows and Frames

Serguei Kouzmine
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

On Tuesday, June 26, 2018 at 1:03:01 AM UTC-4, Nagendra Kuppala wrote:
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
://<a href="http://www.seleniumeasy.com/test/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.seleniumeasy.com%2Ftest%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE37E4KorXc40XrXBWw61mxi3TeXw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.seleniumeasy.com%2Ftest%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE37E4KorXc40XrXBWw61mxi3TeXw&#39;;return true;">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



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/004a916c-3170-4072-8ddf-0b225782be39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.