Protractor: Polyfill .prototype.bind function in PhantomJS. Can't make it work, is it possible?

I spent a day on this and have not made progress, I am really starting to wonder if this is possible.

I use Angular with Headroom to handle a menu that disappears when scrolling down. My testing is done using Protractor using PhantomJS, and here the fun begins.

PhantomJS does not support .bind() , but Headroom uses it everywhere, which means I need to polyfill it. This should not be a problem, but I cannot get it to work.

I think my problem is that no matter where I run the polyfill function, PhantomJS and the tested page are already loaded, so it's already too late, the Headroom will not be loaded due to lack of .bind() .

Is there a way to run these methods before the page loads? I know that I can add them to my application using the script tag in my head, but I would prefer not to add something to the whole application, which will be used only by the testing environment.

+7
angularjs phantomjs polyfills protractor angularjs-e2e
source share
2 answers

I think I have a workaround for this. (at least give him a chance, and we'll see if this works or not). The best you can do is fix your phantomJS browser to support this method. Basically, u should run a script before each specification so that it can be applied to the global scope and will be available for your specifications.

Just try expanding your specifications. Here is an example:

 ... specs: ['my_phantomjs_bind_patch.js', 'webtests/**/*.js'] ... 
0
source share

You cannot run scripts before the page actually loads, as they are part of the dom tree. What you can do: `

 window.onload = function() { //do something }; 

but even when the onload event is fired, the tag should be displayed. Therefore, you should try your idea and add one script tag in front of all other elements in your html and run the code there if it is just for a trial run. `

`

0
source share

All Articles