Skip to content

Commit 9ac53fa

Browse files
committed
Migrate python tests to pytest with Tox
1 parent 987d1a3 commit 9ac53fa

File tree

74 files changed

+3659
-4899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3659
-4899
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ java/client/build/
4545
java/client/log.txt
4646
java/client/iedriver.log
4747
java/server/build/
48+
__pycache__
49+
.tox
4850
*.pyc
4951
dist/
5052
py/selenium/webdriver/firefox/amd64/
@@ -71,6 +73,7 @@ ipch/
7173
/iedriver.log
7274
/phantomjsdriver.log
7375
geckodriver.log
76+
ghostdriver.log
7477
.tags
7578
.ruby-version
7679
GPATH

.travis.yml

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
language: java
22
sudo: required
3-
4-
jdk:
5-
- oraclejdk8
6-
3+
jdk: oraclejdk8
74
notifications:
85
email: false
96
irc:
@@ -13,53 +10,79 @@ notifications:
1310
on_failure: always
1411
use_notice: true
1512
skip_join: true
16-
13+
env:
14+
global:
15+
- DISPLAY=:99.0
16+
matrix:
17+
- TASK=build
18+
- TASK=rb TARGET=unit-test
19+
- TASK=rb TARGET=chrome-test
20+
- TASK=rb TARGET=firefox-test
21+
- TASK=rb TARGET=phantomjs-test
22+
- TASK=py TOXENV=py27-chrome
23+
- TASK=py TOXENV=py27-firefox
24+
- TASK=py TOXENV=py27-marionette
25+
- TASK=py TOXENV=py27-phantomjs
26+
matrix:
27+
fast_finish: true
28+
allow_failures:
29+
- env: TASK=rb TARGET=firefox-test
30+
- env: TASK=rb TARGET=phantomjs-test
31+
- env: TASK=py TOXENV=py27-chrome
32+
- env: TASK=py TOXENV=py27-firefox
33+
- env: TASK=py TOXENV=py27-marionette
1734
before_script:
18-
- "export DISPLAY=:99.0"
19-
- "sh -e /etc/init.d/xvfb start"
20-
35+
- sh -e /etc/init.d/xvfb start
2136
script:
22-
- export CHROME_REVISION=`curl -s http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE`
23-
- export CHROMEDRIVER_VERSION=`curl -s http://chromedriver.storage.googleapis.com/LATEST_RELEASE`
24-
25-
- curl -L -O "http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/${CHROME_REVISION}/chrome-linux.zip"
26-
- unzip chrome-linux.zip
27-
28-
- curl -L -O "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
29-
- unzip chromedriver_linux64.zip
30-
31-
- chmod +x chromedriver
32-
- mv chromedriver chrome-linux/chromedriver
33-
- export PATH=$PATH:$PWD/chrome-linux
34-
35-
- export CHROME_BINARY=$PWD/chrome-linux/chrome
36-
- export CHROMEDRIVER=$PWD/chrome-linux/chromedriver
37-
38-
- export PY_FILES_CHANGED=`git diff --name-only $TRAVIS_COMMIT_RANGE | grep ^py/`
39-
- echo "PY_FILES_CHANGED: $PY_FILES_CHANGED"
40-
- export RB_FILES_CHANGED=`git diff --name-only $TRAVIS_COMMIT_RANGE | grep ^rb/`
41-
- echo "RB_FILES_CHANGED: $RB_FILES_CHANGED"
42-
43-
- ./go clean build
4437
- |
45-
if [[ $PY_FILES_CHANGED == py/* ]]; then
46-
pip install --user virtualenv
47-
export PATH=$PATH:$HOME/.local/bin
48-
./go py_prep_for_install_release //py:phantomjs_test:run
49-
else
50-
echo 'no Python files changed - skipping Python test suite'
51-
fi
38+
if [[ $TARGET+$TOXENV == *"chrome"* ]]; then
39+
sudo apt-get -y purge chromium-browser
40+
export CHROME_REVISION=`curl -s http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE`
41+
curl -L -O "http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/${CHROME_REVISION}/chrome-linux.zip"
42+
unzip chrome-linux.zip
43+
sudo ln -sf $PWD/chrome-linux/chrome-wrapper /usr/local/bin/chrome
44+
export CHROMEDRIVER_VERSION=`curl -s http://chromedriver.storage.googleapis.com/LATEST_RELEASE`
45+
curl -L -O "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
46+
unzip chromedriver_linux64.zip && chmod +x chromedriver && sudo mv chromedriver /usr/local/bin
47+
fi
5248
- |
53-
if [[ $RB_FILES_CHANGED == rb/* ]]; then
54-
export PHANTOMJS_NAME=phantomjs-2.1.1-linux-x86_64
55-
curl -L -O "https://cnpmjs.org/mirrors/phantomjs/${PHANTOMJS_NAME}.tar.bz2"
56-
tar -xvjf $PHANTOMJS_NAME.tar.bz2
57-
chmod +x $PHANTOMJS_NAME/bin/phantomjs
58-
mv $PHANTOMJS_NAME/bin/phantomjs chrome-linux/phantomjs
59-
export PHANTOMJS_BINARY=$PWD/chrome-linux/phantomjs
60-
rvm install 2.2.3
61-
rvm use 2.2.3
62-
./go //rb:unit-test //rb:firefox-test //rb:phantomjs-test //rb:chrome-test
63-
else
64-
echo 'no Ruby files changed - skipping Ruby test suite'
65-
fi
49+
if [[ $TOXENV == *"firefox"* ]]; then
50+
sudo apt-get -y purge firefox
51+
pip install --user mozdownload mozinstall
52+
mozdownload --version 47.0.1 --destination firefox.tar.bz2
53+
mozinstall firefox.tar.bz2
54+
fi
55+
- |
56+
if [[ $TARGET == *"firefox"* ]] || [[ $TOXENV == *"marionette"* ]]; then
57+
export GECKODRIVER_VERSION=v0.10.0
58+
curl -L -o geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz
59+
gunzip -c geckodriver.tar.gz | tar xopf -
60+
chmod +x geckodriver && sudo mv geckodriver /usr/local/bin
61+
sudo apt-get -y purge firefox
62+
pip install --user mozdownload mozinstall
63+
mozdownload --version latest --destination firefox.tar.bz2
64+
mozinstall firefox.tar.bz2
65+
fi
66+
- |
67+
if [[ $TARGET+$TOXENV == *"phantomjs"* ]]; then
68+
export PHANTOMJS_NAME=phantomjs-2.1.1-linux-x86_64
69+
curl -L -O "https://cnpmjs.org/mirrors/phantomjs/${PHANTOMJS_NAME}.tar.bz2"
70+
tar -xvjf $PHANTOMJS_NAME.tar.bz2
71+
chmod +x $PHANTOMJS_NAME/bin/phantomjs
72+
fi
73+
- |
74+
if [[ $TASK == "build" ]]; then
75+
./go build
76+
fi
77+
- |
78+
if [[ $TASK == "py" ]]; then
79+
./go py_prep_for_install_release
80+
pip install --user tox-travis
81+
tox -- --verbose --instafail
82+
fi
83+
- |
84+
if [[ $TASK == "rb" ]]; then
85+
rvm install 2.2.3
86+
rvm use 2.2.3
87+
./go //rb:$TARGET
88+
fi

conftest.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import pytest
19+
20+
from selenium import webdriver
21+
from selenium.webdriver import DesiredCapabilities
22+
23+
drivers = (
24+
'BlackBerry',
25+
'Chrome',
26+
'Edge',
27+
'Firefox',
28+
'Ie',
29+
'Marionette',
30+
'PhantomJS',
31+
'Remote',
32+
'Safari',
33+
)
34+
35+
36+
def pytest_addoption(parser):
37+
parser.addoption(
38+
'--driver',
39+
action='append',
40+
choices=drivers,
41+
dest='drivers',
42+
metavar='DRIVER',
43+
help='driver to run tests against ({0})'.format(', '.join(drivers)))
44+
45+
46+
def pytest_ignore_collect(path, config):
47+
_drivers = set(drivers).difference(config.getoption('drivers') or drivers)
48+
return len([d for d in _drivers if d.lower() in str(path)]) > 0
49+
50+
51+
@pytest.yield_fixture(scope='function')
52+
def driver(request):
53+
kwargs = {}
54+
55+
try:
56+
driver_class = request.param
57+
except AttributeError:
58+
raise Exception('This test requires a --driver to be specified.')
59+
60+
skip = request.node.get_marker('ignore_{0}'.format(driver_class.lower()))
61+
if skip is not None:
62+
reason = skip.kwargs.get('reason') or skip.name
63+
pytest.skip(reason)
64+
65+
if driver_class == 'BlackBerry':
66+
kwargs.update({'device_password': 'password'})
67+
if driver_class == 'Firefox':
68+
kwargs.update({'capabilities': {'marionette': False}})
69+
if driver_class == 'Marionette':
70+
driver_class = 'Firefox'
71+
kwargs.update({'capabilities': {'marionette': True}})
72+
if driver_class == 'Remote':
73+
# TODO start remote server
74+
# request.getfuncargvalue('server')
75+
kwargs.update({'desired_capabilities': DesiredCapabilities.FIREFOX})
76+
driver = getattr(webdriver, driver_class)(**kwargs)
77+
yield driver
78+
driver.quit()

py/build.desc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
py_test(
1212
name = "firefox_test",
13-
ff_specific_tests = [ "test/selenium/webdriver/firefox/ff_*_tests.py" ],
1413
deps = [ ":test_ff" ],
1514
resources = [
1615
{ "//javascript/firefox-driver:webdriver_prefs" : "selenium/webdriver/firefox/webdriver_prefs.json" },
@@ -20,13 +19,11 @@ py_test(
2019

2120
py_test(
2221
name = "marionette_test",
23-
marionette_specific_tests = [ "test/selenium/webdriver/firefox/mn_*_tests.py" ],
2422
deps = [ ":test_marionette" ],
2523
browsers = [ "marionette" ])
2624

2725
py_test(
2826
name = "phantomjs_test",
29-
gd_specific_tests = [ "test/selenium/webdriver/phantomjs/*_tests.py" ],
3027
deps = [ ":test_phantomjs" ],
3128
browsers = [ "phantomjs" ])
3229

@@ -37,7 +34,6 @@ py_test(
3734

3835
py_test(
3936
name = "chrome_test",
40-
chrome_specific_tests = [ "test/selenium/webdriver/chrome/*_tests.py" ],
4137
deps = [ ":test_chrome" ],
4238
browsers = [ "chrome" ])
4339

@@ -53,7 +49,6 @@ py_test(
5349

5450
py_test(
5551
name = "remote_firefox_test",
56-
remote_firefox_specific_tests = [ "test/selenium/webdriver/remote/*_tests.py" ],
5752
deps = [ ":test_remote_firefox" ],
5853
browsers = [ "remote_firefox" ])
5954

@@ -62,20 +57,8 @@ py_test(
6257
deps = [ ":test_safari" ],
6358
browsers = [ "safari" ])
6459

65-
py_env(
66-
name = "test_env",
67-
packages = [
68-
"third_party/py/py-1.4.31-py2.py3-none-any.whl",
69-
"third_party/py/pytest-2.8.6-py2.py3-none-any.whl",
70-
],
71-
dest = "build/python")
72-
7360
py_test(
7461
name = "test",
75-
common_tests = [
76-
"test/selenium/webdriver/common/*_tests.py",
77-
"test/selenium/webdriver/support/*_tests.py"
78-
],
7962
browsers = [
8063
"chrome",
8164
"ff",

py/conftest.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import pytest
19+
20+
from test.selenium.webdriver.common.webserver import SimpleWebServer
21+
from test.selenium.webdriver.common.network import get_lan_ip
22+
23+
24+
@pytest.yield_fixture(autouse=True, scope='session')
25+
def webserver():
26+
webserver = SimpleWebServer(host=get_lan_ip())
27+
webserver.start()
28+
yield webserver
29+
webserver.stop()
30+
31+
32+
@pytest.fixture
33+
def pages(driver, webserver):
34+
class Pages(object):
35+
def url(self, name):
36+
return webserver.where_is(name)
37+
38+
def load(self, name):
39+
driver.get(self.url(name))
40+
return Pages()

py/test/selenium/test_default_server.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)