解决AngularJS编写页面自动化用例时的JS跨域有关问题

解决AngularJS编写页面自动化用例时的JS跨域问题

用HTML调用angularjs写页面自动化用例时,遇到JS跨域问题,提示错误如下:

 

  • 488ms 001: hideroot为false属性验证

    1. 482ms
      browser navigate to 'http://127.0.0.1:8080'
      http://localhost:8080/AngularJSTest/lib/angular-scenario.js:34468:5
      
      Permission denied to access property 'angular'
      angular.scenario.Application.prototype.navigateTo/<@http://localhost:8080/AngularJSTest/lib/angular-scenario.js:33693:1
      jQuery.event.dispatch@http://localhost:8080/AngularJSTest/lib/angular-scenario.js:5096:1
      jQuery.event.add/elemData.handle@http://localhost:8080/AngularJSTest/lib/angular-scenario.js:4767:

   解决办法:

 

   在测试页面和被测页面设置document.domain,如

  <script>     
            /**
            *   此处作用为批量执行用例时解决跨域访问的问题,请勿去除
            *   document.location.hostname获取ip地址
            */
            document.domain = document.location.hostname;      
            
    </script>

 

再次调用后问题解决。

 

参考文档:http://blog.****.net/macky0668/article/details/6247803