Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option for adding key/values to phjs' page.customHeaders #21

Closed
wants to merge 6 commits into from

Conversation

pconerly
Copy link

Yo,

I added an option to add custom headers to phantomjs.

Additionally I added:

  • The tests to prove it works (including a small expressjs server to bounce headers).
  • A listener in the Gruntfile.js to print debug info. (Not required, just useful.)
  • Some documentation about options for the README.md

@cowboy
Copy link
Member

cowboy commented Apr 10, 2013

Can you reformat headers_server.js to follow the established convention for variable declarations?

Also, I'm a slightly concerned about the precedent for specifying custom options here. Should this option that directly maps to the underlying customHeaders property be called customHeaders ?

What if we structure the options differently, such that there's a page option with a customHeaders sub-property? Then every property in the page object could (maybe) be enumerated and "passed through" to page.

Thoughts?

@pconerly
Copy link
Author

Re: established convention for var declarations: Definitely. (I prefer coffeescript so I just ran it through js2coffee)

I agree with the change to make it an option format like:

options: {
    timeout: 1234,
    inject: 'fdsf',
    page: {
        customHeaders: {
            'x-custom': '1234'
         }
     }

I'll do both those changes. I'll also make the page option attempt to pass in all properties set in it.

Did you have any thoughts about the tiny expressjs server sitting in the test/ directory? I suspect that future tests may also need to use a tiny express server and I wasn't sure if there was a better way to re-organize it.

Thanks for the quick response!

@pconerly
Copy link
Author

Pushed those changes.

page[prop] = options.page[prop];
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_.extend()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@pconerly
Copy link
Author

Thanks @sindresorhus, I made those changes.

@jakerella
Copy link

Hmm, adding the code to add arbitrary properties on the page object may also take care of my PR which explicitly added the viewportSize option to the page object (see PR #31).

@pconerly, could you verify that the page.viewportSize is set correctly using your code changes? If so, I'll cancel my PR. Thanks!!

@pconerly
Copy link
Author

Hi @jakerella, Yup, it does pass on any page properties listed here: https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage

I added a test for viewport size so you can be assured. You can close #31. You're welcome!

@jakerella
Copy link

Bump... May I ask why this one is waiting to be merged? We use this functionality for viewportSize on the page in every project (useful for responsive testing).

@dklischies
Copy link

Just in case somebody is looking for a more unobtrusive way to do this (e.g. no extra libraries required): https://github.com/Nostraa/grunt-lib-phantomjs/commit/54b4cc693e22e47836484a7d193d3001c7c851a2
It doesn't have any testing, but I guess that isn't required at all since stuff is only passed to phantomjs, not sure what should go wrong in 4 lines of code.

@ssafejava
Copy link
Contributor

Could this please be merged? I have tests that rely on document.getElementAtPoint() that are failing because the viewport size is too small.

@pconerly
Copy link
Author

@cowboy @sindresorhus , can we merge?

@ssafejava
Copy link
Contributor

By the way, rather than include lodash, this can be simply fixed by adding options.page to the page constructor.

I pulled this fork & removed the lodash code and the tests still pass. Let me know if I can help get this fix into master.

@bdowling
Copy link
Contributor

Curious if there is any concerns holding this PR from merging. I noticed some tests jQuery-ui was doing that could benefit from the ability to extend viewportSize as well. Their dialog tests are disabled in grunt/phantomjs I'm guessing in part because these won't pass..

bdowling added a commit to bdowling/grunt-lib-phantomjs that referenced this pull request Nov 28, 2013
@bdowling
Copy link
Contributor

bdowling commented Dec 1, 2013

Fwiw, I made a couple minor mods to this pull request in my branch here. bdowling@1593476

bdowling added a commit to bdowling/jquery-ui that referenced this pull request Dec 2, 2013
I noticed some unit tests were disabled in phantomjs.  dialog and draggable depend
on a larger viewPort.  tooltip just seemed to work, so I reenebaled that as well.

Changing the viewportSize depends on a not yet merged feature in gruntjs/grunt-lib-phantomjs#21
bdowling added a commit to bdowling/jquery-ui that referenced this pull request Dec 2, 2013
Note, this depends on the new phantomjs/main.js in the not yet merged feature
in gruntjs/grunt-lib-phantomjs#21
bdowling added a commit to bdowling/grunt-lib-phantomjs that referenced this pull request Dec 7, 2013
Merged in from STRML/grunt-lib-phantomjs@e356ada
(Essentially merged and squashed commits of gruntjs#21 and gruntjs#47 together)
@jzaefferer
Copy link
Member

Closing in favor of #21, which improves on this.

@jzaefferer jzaefferer closed this Jan 16, 2014
bdowling added a commit to bdowling/jquery-ui that referenced this pull request Jan 17, 2014
I noticed some unit tests were disabled in phantomjs.  dialog and draggable depend
on a larger viewPort.  tooltip just seemed to work, so I reenebaled that as well.

Changing the viewportSize depends on a not yet merged feature in gruntjs/grunt-lib-phantomjs#21
bdowling added a commit to bdowling/jquery-ui that referenced this pull request Jan 17, 2014
Note, this depends on the new phantomjs/main.js in the not yet merged feature
in gruntjs/grunt-lib-phantomjs#21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants