WEB UI自动化之旅(一)

发表于:2010-1-18 14:13

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:wuyingminhui    来源:51Testing软件测试博客

  随着敏捷实践的引入,越来越多的公司注重产品的回归自动化测试

  这里简单的介绍一下关于SELENIUM的用法,Selenium是由THOUGHWORKS公司开发的基于WEB层面的自动化测试工具。它是由JAVASCRIPT开发的,支持PYTHON,RUBY,C#,JAVA,PHP,PERL 等多种语言。它有三部分组成,Selenium-IDE:应用层录制工具;Selenium-RC(Remote Controller):支持不同语言的客户端驱动,包含Selenium-SERVER;Selenium-core,主要为JAVASCRIPT核心代码,对于selenium的功能扩展有帮助。

  一般使用selenium选择TestNG or Junit框架,因为这两个框架都能和selenium,ANT很好的结合,并且都提供ResultReport的功能。准备好Selenium-RC,Junit(TestNG),我们的自动化之旅开始了。

  这里有个之后会影响测试的BUG先解决掉,在Selenium1.0中对网页弹出窗口无法捕捉,我们怎么做呢?

  在selenium-server.jar中core文件夹下scripts文件下的selenium-browerbot.js中修改如下的JS代码:

var newOpen = function(url, windowName, windowFeatures, replaceFlag) {
       var myOriginalOpen = originalOpen;
       if (isHTA) {
           myOriginalOpen = this[originalOpenReference];
       }
       if (windowName == "" || windowName == "_blank") {
           windowName = "selenium_blank" + Math.round(100000 * Math.random());
           LOG.warn("Opening window '_blank', which is not a real window name. Randomizingtarget to be: " + windowName);
       }
       var penedWindow = myOriginalOpen(url, windowName, windowFeatures, replaceFlag);
       LOG.debug("window.open call intercepted; window ID (which you can use with selectWindow()) is \"" + windowName + "\"");
       if (windowName!=null) {
           openedWindow["seleniumWindowName"] = windowName;
       }
       selenium.browserbot.openedWindows[windowName] = openedWindow;
       return openedWindow;
   };

  转为:

var newOpen = function(url, windowName, windowFeatures, replaceFlag) {
       // var myOriginalOpen = originalOpen;
       //var myOriginalOpen = window.open;
         if (isHTA) {
           // myOriginalOpen = this[originalOpenReference];
         }
         if( !windowFeatures )
         {
         windowFeatures = null;
         }
         if( !replaceFlag )
         {
         replaceFlag = null;
         }

         var penedWindow = null;
         if( !windowFeatures && !replaceFlag )
         {
           openedWindow = this.window.open(url, windowName);
         }
         else
         {
         openedWindow = this.window.open(url, windowName, windowFeatures, replaceFlag);
         }
         LOG.debug("window.open call intercepted; window ID (which you can use withselectWindow()) is \"" + windowName + "\"");
         if (windowName!=null) {
             openedWindow["seleniumWindowName"] = windowName;
         }

         if(openedWindow != null)
         {
             selenium.browserbot.openedWindows[windowName] = openedWindow;
             return openedWindow;
         }
         return null;
       
     };

  这样您就能开始WEB自动化了。

31/3123>
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • yayagepei
    2010-1-18 17:13:42

    copy这么多代码有意思吗?测试的原理功能一点没有!

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号