Protractor: Polyfill Function.prototype.bind in PhantomJS. Can't make it work, is it even possible?
Asked Answered
K

2

7

I've spent the afternoon on this and am making no progress, I'm really starting to wonder if it's even possible.

I'm using Angular with Headroom to handle a menu disappearing when scrolling down. My testing is done with Protractor, using PhantomJS, and this is where the fun begins.

PhantomJS does not support .bind() and Headroom uses it all over the place, which means I need to polyfill it. It should be no problem, but I can't make it 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, Headroom will have failed to load due to .bind() not being available.

Is there any way to run those methods before the page is loaded? I know I could add them to my application via a script tag in the head, but I'd rather not add something to the whole app that will only be used by the testing framework.

Krohn answered 2/7, 2015 at 20:38 Comment(4)
Why PhantomJS in the first place? (https://mcmap.net/q/902418/-using-protractor-with-phantomjs)Gombroon
I know support isn't ideal, but it's what we're using. My boss' arguments mainly being that headless Chrome on the CI is a pain to maintain (I don't know how much it really is, I've never done it) and Sauce Labs would cost too much for the budgets we have right now. So PhantomJS it is.Krohn
Any chance you could provide some code or jsFiddle this? I'd be interested to see exactly what is happening here.Puente
github.com/angular/protractor/issues/2762Pemmican
E
0

I think I have a workaround for that. (at least give it a shot and we'll see if it's working or not) The best u can do is to patch your phantomJS browser to have this method supported. Basically u should run a script before every specs, so that it can apply to the global scope and will be available to your specs.

Just try to extend your specs configurations. Here is an example:

...
specs: ['my_phantomjs_bind_patch.js', 'webtests/**/*.js']
...
Ereshkigal answered 8/1, 2016 at 8:5 Comment(1)
It has been a really long time (I'm not even using Angular or Protractor anymore), but I think I did try that without success. If someone does try it and it works, I'll accept your answer.Krohn
C
0

You cant run scripts before the actual page load as they are a part of the dom tree .What you can do is : `

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

but even when the onload event is fired the tag must be rendered. So you should try your idea and add one script tag before all other elements to your html and run the code there, if it's just for a test run. `

`

Corrientes answered 8/1, 2016 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.