Skip to content

Commit 7cf8096

Browse files
authored
Merge pull request #63 from spyoungtech/release/0.2.0
Release/0.2.0
2 parents d085d22 + 4a441af commit 7cf8096

29 files changed

+603
-338
lines changed

.travis.yml

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,63 @@
1-
sudo: false
1+
dist: xenial
22
language: python
3+
4+
35
python:
46
- "2.7"
5-
- "3.5"
67
- "3.6"
7-
- "nightly"
8+
9+
env:
10+
global:
11+
- BEHAVE_WEBDRIVER_HEADLESS=1
12+
matrix:
13+
- BEHAVE_WEBDRIVER=Chrome
14+
- BEHAVE_WEBDRIVER=Firefox
815

916
addons:
1017
chrome: stable
18+
firefox: latest
19+
20+
matrix:
21+
include:
22+
- os: osx
23+
language: generic
24+
python:
25+
env:
26+
- BEHAVE_WEBDRIVER=Safari
27+
- python: "3.5"
28+
env:
29+
- BEHAVE_WEBDRIVER=Chrome
30+
- python: "3.7"
31+
env:
32+
- BEHAVE_WEBDRIVER=Chrome
33+
34+
35+
fast_finish: true
36+
allow_failures:
37+
- os: osx
38+
1139
install:
12-
- wget -N http://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip -P ./
13-
- unzip ./chromedriver_linux64.zip -d ./
14-
- rm ./chromedriver_linux64.zip
15-
- chmod +x ./chromedriver
16-
- pip install -r ./requirements.txt
17-
- pip install coveralls pytest mock
40+
- ./ci/install.sh
1841

1942
script:
2043
- cd tests/demo-app
2144
- python ./runserver.py > /dev/null 2>&1 &
2245
- cd ../..
46+
- export ENV_BASE_URL=http://127.0.0.1:8000/
2347
- coverage run -m behave tests/features
2448
- coverage run -a -m pytest tests/unittests
2549

26-
2750
after_success:
2851
- coveralls
2952

30-
3153
deploy:
3254
provider: pypi
55+
distributions: "sdist bdist_wheel"
3356
user: "spyoungtech"
3457
password:
3558
secure: "oj3Yvv150E+ExDCxYkeXdwH3+jXmrQbJFK9ic+DHwFBmN8wb0IbjcjtBTu+VOotiEfHZjUuK8Ok44bYvsLIka0Zzt8pY52KREFXEwLh63IYottccerE9VmzQUvC87GWCsiLkmVR5O4ATM31byOFk9MmxIrWy3qhoNNJvQSTcW/HMDIweJUnqHQ10KS/7IkxHZiW1Efe3KKIr9cjOWiXAX/xjmSD7DzEVpENT4BvvwrBnDO2JY+CROHmsO8X2FqjriNn2BCLZK1rd3FXS/hcb698V4nZdTNd63f8twmuPk/owr2dQiexiAhZPQKHj8KBZ6fyn80uOuHHc/44U4rWf+699Q4nq2vYDCaLA2drl3PAPZg65HjWumVQKKYCddY1by52iumJ0fFdPqB7dERqWIvHzCERkwJvsZtzxQ8QV7CUENyS5v398/wUdaOqhRD+MMHG6ZS4Zuhr/wurrJrcX3KjAffY3dVN6uEzTq57JoYX9zrMysKQRyUsGUiNC7e008vRm8rSIEoX4Kc/NqqY+em+wKLuhvxGyDZ9Sd731BgtCQPNj+DFBvk55taXKw78NlCwl03pFCRXKTWoy1nZKYoStQmizy9d44dqua12NV2EOYHzK6+WddM6xJnuVFaWxqcV/vesL/6ekJw8wZI3Q0ud3d0Ws1zSxfyjJt4OchZQ="
3659
on:
3760
tags: true
3861
python: 3.6
62+
env: BEHAVE_WEBDRIVER=Chrome
3963

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE
2+
include README.rst

README.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,23 @@ options to run headless. This is useful, for example in headless testing environ
8484
def before_all(context):
8585
context.behave_driver = behave_webdriver.Chrome.headless()
8686
87-
In the future, behave-webdriver will provide `fixtures`_ for the setup and teardown of webdrivers.
88-
See the behave tutorial for more information about `environment controls`_ .
87+
88+
Using a fixture
89+
^^^^^^^^^^^^^^^
90+
91+
*New in 0.1.1*
92+
93+
You may also find it convenient to use a fixture to setup your driver as well. For example, to use our fixture with Firefox
94+
95+
.. code-block:: python
96+
97+
from behave_webdriver.fixtures import fixture_browser
98+
def before_all(context):
99+
use_fixture(fixture_browser, webdriver='Firefox')
100+
101+
This will also ensure that the browser is torn down at the corresponding `cleanup point`_.
102+
103+
.. _cleanup point: http://behave.readthedocs.io/en/stable/fixtures.html#fixture-cleanup-points
89104

90105
Writing the feature file
91106
------------------------
@@ -337,24 +352,24 @@ Then Steps ✔️
337352
Acknowledgements ❤️
338353
===================
339354

340-
Special thanks to the authors of the `webdriverio/cucumber-boilerplate`_ project
355+
Special thanks to the authors and contributors of the `webdriverio/cucumber-boilerplate`_ project
341356

342-
Special thanks to the authors of `behave`_
357+
Special thanks to the authors and contributors of `behave`_
343358

344359

345360

346361

347362
.. _selenium-requests: https://github.com/cryzed/Selenium-Requests
348363

349-
.. _environment controls: http://behave.readthedocs.io/en/latest/tutorial.html#environmental-controls
364+
.. _environment controls: http://behave.readthedocs.io/en/stable/tutorial.html#environmental-controls
350365

351-
.. _fixtures: http://behave.readthedocs.io/en/latest/fixtures.html
366+
.. _fixtures: http://behave.readthedocs.io/en/stable/fixtures.html
352367

353-
.. _step implementations: http://behave.readthedocs.io/en/latest/tutorial.html#python-step-implementations
368+
.. _step implementations: http://behave.readthedocs.io/en/stable/tutorial.html#python-step-implementations
354369

355370
.. _driver installation notes: http://selenium-python.readthedocs.io/installation.html#drivers
356371

357-
.. _behave-webdriver documentation: http://behave-webdriver.readthedocs.io/en/latest/
372+
.. _behave-webdriver documentation: http://behave-webdriver.readthedocs.io/en/stable/
358373

359374
.. _selenium: https://github.com/SeleniumHQ/selenium
360375

@@ -364,8 +379,8 @@ Special thanks to the authors of `behave`_
364379

365380

366381

367-
.. |docs| image:: https://readthedocs.org/projects/behave-webdriver/badge/?version=latest
368-
:target: http://behave-webdriver.readthedocs.io/en/latest/
382+
.. |docs| image:: https://readthedocs.org/projects/behave-webdriver/badge/?version=stable
383+
:target: http://behave-webdriver.readthedocs.io/en/stable/
369384

370385
.. |status| image:: https://travis-ci.org/spyoungtech/behave-webdriver.svg?branch=master
371386
:target: https://travis-ci.org/spyoungtech/behave-webdriver

appveyor.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: 1.0.{build}
2+
3+
environment:
4+
BEHAVE_WEBDRIVER: IE
5+
6+
matrix:
7+
allow_failures:
8+
- BEHAVE_WEBDRIVER: IE
9+
10+
services:
11+
- iis
12+
13+
install:
14+
- regedit /s .\ci\bfcache.reg
15+
- cmd: .\ci\install.bat
16+
17+
build: off
18+
19+
test_script:
20+
- cmd: .\ci\runtests.bat
21+
- ps: |
22+
$wc = New-Object 'System.Net.WebClient';
23+
Get-ChildItem .\reports |
24+
Foreach-Object {
25+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $_.FullName))
26+
}

behave_webdriver/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
'Remote',
1212
'from_env',
1313
'from_string',
14-
'fixture_browser',
15-
'before_all_factory',
16-
'before_feature_factory',
17-
'before_scenario_factory',
1814
]
1915
from behave_webdriver.driver import (Chrome,
2016
Firefox,
@@ -32,3 +28,6 @@
3228
before_all_factory,
3329
before_feature_factory,
3430
before_scenario_factory)
31+
from behave_webdriver.fixtures import use_fixture_tag
32+
from behave_webdriver import transformers
33+

behave_webdriver/driver.py

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from selenium import webdriver
77
from selenium.webdriver.chrome.options import Options as ChromeOptions
8+
from selenium.webdriver.firefox.options import Options as FirefoxOptions
89
from selenium.common.exceptions import NoSuchElementException, TimeoutException, WebDriverException
910
from selenium.webdriver.support.ui import WebDriverWait
1011
from selenium.webdriver.common.by import By
@@ -63,11 +64,18 @@ class BehaveDriverMixin(object):
6364
6465
6566
"""
67+
_driver_name = ''
6668
def __init__(self, *args, **kwargs):
6769
default_wait = kwargs.pop('default_wait', 1.5)
6870
super(BehaveDriverMixin, self).__init__(*args, **kwargs)
6971
self.default_wait = default_wait
7072

73+
74+
def wait(self, wait_time=None):
75+
if wait_time is None:
76+
wait_time = self.default_wait
77+
return WebDriverWait(self, wait_time)
78+
7179
@property
7280
def alert(self):
7381
"""
@@ -604,6 +612,7 @@ class Chrome(BehaveDriverMixin, webdriver.Chrome):
604612
"""
605613
Chrome driver class. Alternate constructors and browser-specific logic is implemented here.
606614
"""
615+
_driver_name = 'chromedriver'
607616
@classmethod
608617
def headless(cls, *args, **kwargs):
609618
chrome_options = kwargs.pop('chrome_options', None)
@@ -626,55 +635,92 @@ class Firefox(BehaveDriverMixin, webdriver.Firefox):
626635
"""
627636
Firefox driver class. Alternate constructors and browser-specific logic is implemented here.
628637
"""
638+
_driver_name = 'geckodriver'
639+
@classmethod
640+
def headless(cls, *args, **kwargs):
641+
firefox_options = kwargs.pop('firefox_options', None)
642+
if firefox_options is None:
643+
firefox_options = FirefoxOptions()
644+
firefox_options.add_argument('--headless')
645+
kwargs['firefox_options'] = firefox_options
646+
return cls(*args, **kwargs)
629647

630-
pass
648+
@property
649+
def secondary_handles(self):
650+
self.switch_to.window(self.current_window_handle)
651+
try:
652+
# FIXME: there must be a better way
653+
self.wait(1).until(EC.new_window_is_opened(self.window_handles))
654+
self.switch_to.window(self.current_window_handle)
655+
except TimeoutException:
656+
pass
657+
return super(Firefox, self).secondary_handles
658+
659+
@property
660+
def last_opened_handle(self):
661+
self.switch_to.window(self.current_window_handle)
662+
return super(Firefox, self).last_opened_handle
663+
664+
def click_element(self, element):
665+
self.scroll_to_element(element)
666+
super(Firefox, self).click_element(element)
667+
668+
def doubleclick_element(self, element):
669+
"""
670+
Overrides the doubleclick method to first scroll to element, and adds JS shim for doubleclick
671+
"""
672+
self.scroll_to_element(element)
673+
elem = self.get_element(element)
674+
script = ("var evObj = new MouseEvent('dblclick', {bubbles: true, cancelable: true, view: window}); "
675+
" arguments[0].dispatchEvent(evObj);")
676+
self.execute_script(script, elem)
677+
678+
def move_to_element(self, element, offset=None):
679+
self.scroll_to_bottom()
680+
self.scroll_to_element(element)
681+
super(Firefox, self).move_to_element(element, offset=offset)
631682

632683

633684
class Ie(BehaveDriverMixin, webdriver.Ie):
634685
"""
635686
Ie driver class. Alternate constructors and browser-specific logic is implemented here.
636687
"""
637-
pass
688+
_driver_name = 'IEDriverServer'
638689

639690

640691
class Edge(BehaveDriverMixin, webdriver.Edge):
641692
"""
642693
Edge driver class. Alternate constructors and browser-specific logic is implemented here.
643694
"""
644-
pass
645695

646696

647697
class Opera(BehaveDriverMixin, webdriver.Opera):
648698
"""
649699
Opera driver class. Alternate constructors and browser-specific logic is implemented here.
650700
"""
651-
pass
652701

653702

654703
class Safari(BehaveDriverMixin, webdriver.Safari):
655704
"""
656705
Safari driver class. Alternate constructors and browser-specific logic is implemented here.
657706
"""
658-
pass
707+
_driver_name = 'safaridriver'
659708

660709

661710
class BlackBerry(BehaveDriverMixin, webdriver.BlackBerry):
662711
"""
663712
BlackBerry driver class. Alternate constructors and browser-specific logic is implemented here.
664713
"""
665-
pass
666714

667715

668716
class Android(BehaveDriverMixin, webdriver.Android):
669717
"""
670718
Android driver class. Alternate constructors and browser-specific logic is implemented here.
671719
"""
672-
pass
673720

674721

675722
class Remote(BehaveDriverMixin, webdriver.Remote):
676723
"""
677724
Remote driver class. Alternate constructors and browser-specific logic is implemented here.
678725
"""
679-
pass
680726

0 commit comments

Comments
 (0)