-
Notifications
You must be signed in to change notification settings - Fork 32
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
Configure browser capabilities through YAML #36
Open
danni
wants to merge
8
commits into
bbangert:master
Choose a base branch
from
infoxchange:browser-yaml
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ffd491e
Fix django steps
d63351f
Configure browser capabilities in a yaml file
3896171
Update docs for YAML config support
1680ed3
Update requirements.txt
31c6ec0
Add support for app provided capabilities
0c589fe
Set the caps on the object so we can use them later
eadc0db
Merge branch 'master' into browser-yaml
60d1a0a
Add PyYAML to setup.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1 +1,125 @@ | ||
# | ||
""" | ||
Lettuce Webdriver | ||
""" | ||
|
||
import os | ||
import yaml | ||
|
||
import selenium.webdriver | ||
|
||
from lettuce import world, after | ||
|
||
import webdriver | ||
|
||
|
||
__all__ = ['initialize'] | ||
|
||
|
||
class ConfigError(Exception): | ||
""" | ||
A YAML config error | ||
""" | ||
|
||
pass | ||
|
||
|
||
# pylint:disable=too-many-branches, too-many-statements | ||
def initialize(config, default, capabilities=None): | ||
""" | ||
Initialize lettuce-webdriver using specified config. | ||
|
||
Config is specified in YAML. | ||
""" | ||
|
||
with open(config) as file_: | ||
data = yaml.load(file_) | ||
|
||
try: | ||
browser = os.environ.get('WEBDRIVER', default) | ||
browser = data[browser] | ||
except KeyError: | ||
raise ConfigError("Unknown browser '{browser}'".format( | ||
browser=browser)) | ||
|
||
remote = browser.get('remote', False) | ||
config = {} | ||
|
||
# determine base capabilities | ||
try: | ||
if browser['webdriver'] == 'ie': | ||
caps_str = 'INTERNETEXPLORER' | ||
else: | ||
caps_str = browser['webdriver'].upper() | ||
|
||
caps = getattr(selenium.webdriver.DesiredCapabilities, caps_str) | ||
except KeyError: | ||
raise ConfigError("Must specify 'driver'") | ||
except AttributeError: | ||
raise ConfigError("Unknown driver: {driver}".format( | ||
browser['driver'])) | ||
|
||
# merge capabilities overrides | ||
caps.update(browser.get('capabilities', {})) | ||
|
||
if remote: | ||
hub = None | ||
hub_fmt = 'http://{host}:4444/wd/hub' | ||
|
||
if 'WEBDRIVER_HUB' in os.environ: | ||
hub = os.environ['WEBDRIVER_HUB'] | ||
elif 'WEBDRIVER_HOST' in os.environ: | ||
hub = hub_fmt.format(host=os.environ['WEBDRIVER_HOST']) | ||
elif 'hub' in browser: | ||
hub = browser['hub'] | ||
elif 'host' in browser: | ||
hub = hub_fmt.format(host=browser['host']) | ||
elif 'command_executor' in browser: | ||
hub = browser['command_executor'] | ||
else: | ||
raise ConfigError("Must specify a hub or host to connect to") | ||
|
||
config['command_executor'] = hub | ||
|
||
if capabilities: | ||
caps.update(capabilities) | ||
|
||
if remote or \ | ||
browser['webdriver'] == 'chrome' or \ | ||
browser['webdriver'] == 'phantomjs': | ||
config['desired_capabilities'] = caps | ||
else: | ||
config['capabilities'] = caps | ||
|
||
# determine WebDriver | ||
if remote: | ||
driver = selenium.webdriver.Remote | ||
else: | ||
driver = browser['webdriver'] | ||
|
||
if driver == 'phantomjs': | ||
driver = 'PhantomJS' | ||
else: | ||
driver = driver.capitalize() | ||
|
||
driver = getattr(selenium.webdriver, driver) | ||
|
||
driver = driver(**config) | ||
driver.config = config | ||
driver.requested_capabilities = caps | ||
|
||
return driver | ||
|
||
|
||
@after.each_scenario # pylint:disable=no-member | ||
def disable_beforeunload(scenario): | ||
""" | ||
Disable before unload after a scenario so that the next scenario can | ||
reload the site. | ||
""" | ||
|
||
world.browser.execute_script(""" | ||
try { | ||
$(window).off('beforeunload'); | ||
} catch (e) { | ||
} | ||
""") |
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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
# pylint:disable=invalid-name,missing-docstring | ||
import os | ||
|
||
from lettuce import world | ||
|
||
import lettuce_webdriver | ||
|
||
here = os.path.dirname(__file__) | ||
html_pages = os.path.join(here, 'html_pages') | ||
|
||
def setUp(): | ||
from selenium import webdriver | ||
world.browser = webdriver.Firefox() | ||
world.browser = lettuce_webdriver.initialize( | ||
os.path.join(here, 'browsers.yaml'), | ||
'firefox') | ||
|
||
|
||
def tearDown(): | ||
world.browser.quit() |
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,2 @@ | ||
firefox: | ||
webdriver: firefox |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
PyYAML==3.10 | ||
fuzzywuzzy==0.2 | ||
lettuce==0.2.19 | ||
nose==1.3.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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this depends on JQuery being installed in and exported by the target site. I'm not really comfortable making that a requirement for lettuce_webdriver; is there a better or easier way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. We can do it through raw JS. Although I've never been clear how
the multiple ways to set/unset events interact with each other in different
browsers. I'll investigate.
On 2 October 2013 04:50, Nicholas Pilon [email protected] wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may also want to add a callback to selenium that checks on each page load to see if JQuery is exposed and, if it isn't, imports and exposes it...