javascript - Selenium's PhantomJS webdriver not loading page in reactjs -


i'm trying test new feature of website. page far built in react. when attempt run test in selenium phantomjs page index loads, full page load never triggers.

the page body is:

<body>     <main id="content"></main>     <script type="text/javascript">         function loadbundlejs( jssource){             var bundlejsscripttag=document.createelement('script')             bundlejsscripttag.setattribute("type","text/javascript")             bundlejsscripttag.setattribute("src", jssource)             if (typeof bundlejsscripttag != 'undefined'){                 document.getelementsbytagname('head')[0].appendchild(bundlejsscripttag);             }         }         var paramsarray = window.location.search.substring(1).split("&");         object.keys(paramsarray).foreach(function(key){             var param = paramsarray[key];             if (param.indexof("/")>-1){                 param = param.substring(0, param.indexof("/"))             }         })         loadbundlejs('js/bundle.0.0.2.js')     </script> </body> 

when site runs in browser content appended main tag. however, in phantomjs content never gets appended , phantomjs loads blank page.

the problem not in code, in webkit browser phantomjs runs. phantomjs run old version of webkit engine use older version of ecmascript.
reactjs use function.bind method ecmascript 5.
solution pretty simple, need define function.prototype.bind in code if not exist.

** make sure code loaded before including react.js.

if (!function.prototype.bind) { function.prototype.bind = function(othis) {     if (typeof !== 'function') {         throw new typeerror('function.prototype.bind - trying bound not callable');     }      var aargs   = array.prototype.slice.call(arguments, 1),         ftobind = this,         fnop    = function() {},         fbound  = function() {             return ftobind.apply(this instanceof fnop                     ?                     : othis,                 aargs.concat(array.prototype.slice.call(arguments)));         };      if (this.prototype) {         fnop.prototype = this.prototype;     }     fbound.prototype = new fnop();      return fbound; }; 

}

code taken from: https://developer.mozilla.org/en/docs/web/javascript/reference/global_objects/function/bind#polyfill


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -