-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to set user-agent to use
#58 This change allows users to specify the user agent a driver should use via the `config.yml`. This will only apply to the **Firefox**, **Chrome** and **PhantomJS** drivers. The changes involved taking the argument passed in and correctly configuring the underlying driver to use it. In the case of **Firefox** this involved updating the profile. For **Chrome** it was simply adding an additional flag. **PhantomJS** proved to be more of a problem. You have to add a header via **Poltergiest**, however it only last for the current session i.e test. This means before every scenario you have to keep adding it back in. This meant a new `before()` hook was added to handle this. Other changes include tests and documentation.
- Loading branch information
1 parent
28c7587
commit acab4eb
Showing
7 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'quke/configuration' | ||
|
||
Before('~@nonweb') do | ||
# We have to make a special case for phantomjs when it comes to implementing | ||
# the ability to override the user agent. Unlike the selinium backed drivers | ||
# specifying the user agent is not part of the arguments we pass in when | ||
# initialising the driver. Instead its something we call on the driver once | ||
# its been instantiated | ||
# https://github.com/teampoltergeist/poltergeist#manipulating-request-headers | ||
# That might not have been so bad, the folks behind poltergeist have also | ||
# made it so that custom changes to the header only last for as long as the | ||
# test is running. Once a test finishes, the changes are lost. | ||
# Hence the only way we can ensure its set across all tests is by making use | ||
# of the Before hook, and adding the User-Agent header each time. | ||
if Quke::Quke.config.driver == 'phantomjs' | ||
unless Quke::Quke.config.user_agent.empty? | ||
page.driver.add_header( | ||
'User-Agent', | ||
Quke::Quke.config.user_agent, | ||
permanent: true | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
user_agent: "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters