selenium自动化测试框架-选择窗口篇

来源:互联网 发布:单片机脉冲计数器 编辑:程序博客网 时间:2024/05/22 20:28

 

1.selectWindow问题。 selectWindow TestOpenWindow

如果程序打开了新窗口,那么就要转到新窗口 执行一些操作,这时需要首先选中该新窗口,在selenium中选中新窗口使用selectWindow命令,根据windowID来选择窗口,但是它有一些限制:

a. 只能检测到使用window.open(url, windowName, windowFeatures, replaceFlag)方法打开的窗口。

b. 如果在onLoad事件之前发生的打开窗口,并不能检测到。使用以下命令注册窗口后就能选择。 openWindow   TestOpenWindow

源代码如下:

 

<!--File: TestOpenWindowDuringOnLoad.html-->
<html>
<head>
  
<title>Test Local</title>
</head>
<body>

<table cellpadding="1" cellspacing="1" border="1">
  
<tbody>
    
<tr>
      
<td rowspan="1" colspan="3">Test Local<br>
      
</td>
    
</tr>
    
<tr>
        
<td>open</td>
            
<td>http://10.202.15.118:8080/myapp/test_open_window_during_onload.jsp</td>
      
<td>&nbsp;</td>
    
</tr>  
    
<tr>
      
<td>openWindow</td>
            
<td></td>
      
<td>TestOpenWindowDuringOnLoad</td>
    
</tr>
    
<tr>
      
<td>waitForPopUp</td>
            
<td>TestOpenWindowDuringOnLoad</td>
      
<td>5000</td>
    
</tr>
    
<tr>
      
<td>selectWindow</td>
            
<td>TestOpenWindowDuringOnLoad</td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td>verifyTitle</td>
            
<td>Test HTML</td>
      
<td>&nbsp;</td>
    
</tr>

  
</tbody>
</table>
</body>
</html>

<!--File: test_open_window_during_onload.jsp-->
<html>
<head>
  <title>Test Open Window</title>
</head>
<body>
<center>
<text id=text1>Hello, Open a new Window During OnLoad!</text>
</center>
</body>
</html>
<script language=javascript>
 myLoad();
 function myLoad(){
  window.open("test.html","TestOpenWindowDuringOnLoad");
 }
</script>

 


 

c.如果使用window.open(url),未指定窗口ID,那么使用undefined标志窗口ID来选择窗口。 selectWindow undefined

源代码如下:

 

<!--File: TestOpenWindowWithoutID.html-->
<html>
<head>
  
<title>Test Local</title>
</head>
<body>

<table cellpadding="1" cellspacing="1" border="1">
  
<tbody>
    
<tr>
      
<td rowspan="1" colspan="3">Test Local<br>
      
</td>
    
</tr>
    
<tr>
        
<td>open</td>
            
<td>http://10.202.15.118:8080/myapp/test_open_window_without_id.jsp</td>
      
<td>&nbsp;</td>
    
</tr>  
    
<tr>
      
<td>click</td>
            
<td>testopenwindow</td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td>waitForPopUp</td>
            
<td>undefined</td>
      
<td>5000</td>
    
</tr>
    
<tr>
      
<td>selectWindow</td>
            
<td>undefined</td>
      
<td>&nbsp;</td>
    
</tr>
    
<tr>
      
<td>verifyTitle</td>
            
<td>Test HTML</td>
      
<td>&nbsp;</td>
    
</tr>

  
</tbody>
</table>
</body>
</html>
<!--File: test_open_window_without_id.jsp-->
 <html>
 <head>
   <title>Test Open Window</title>
 </head>
 <body>
 <center>
 <text id=text1>Hello, Open a new Window Without ID!</text>
 <button id="testopenwindow" onclick='javascript:myLoad()'>TestOpenWindowWithoutID</button>
 </center>
 </body>
 </html>
 <script language=javascript>
  function myLoad(){
   window.open("test.html");
  }
 </script>
原创粉丝点击