From 0f488bf7fc60748472d6f0988bcfaaaf695881e5 Mon Sep 17 00:00:00 2001 From: justinpotts Date: Thu, 4 Aug 2016 16:27:30 -0700 Subject: [PATCH 1/9] Add tox support for running UI tests --- tests/ui/README.md | 6 +++--- tests/ui/setup.py | 22 ++++++++++++++++++++++ tests/ui/tox.ini | 11 +++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tests/ui/setup.py create mode 100644 tests/ui/tox.ini diff --git a/tests/ui/README.md b/tests/ui/README.md index 7e9234d43ac..61d5da73bc5 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -31,20 +31,20 @@ $ pip install -Ur requirements.txt ``` ### Run the tests -Tests are run using the command line. Below are a couple of examples of running the tests: +Tests are run using tox on the command line. Below are a couple of examples of running the tests: Before running, ensure the [GeckoDriver executable][geckodriver] (rename to wires) is in your path. Note: The tests must be run in Firefox 48 or later, and geckodriver (wires) must be 0.9.0. ```bash -$ py.test --firefox-path= test_discopane.py +$ tox -e ui-tests ``` To run against a different environment, pass in a value for `--base-url`, like so: ```bash -$ py.test --base-url https://discovery.addons.mozilla.org --firefox-path= test_discopane.py +$ tox -e ui-tests -- --base-url https://discovery.addons.mozilla.org ``` The pytest plugin that we use for running tests has a number of advanced diff --git a/tests/ui/setup.py b/tests/ui/setup.py new file mode 100644 index 00000000000..6130ea53deb --- /dev/null +++ b/tests/ui/setup.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from setuptools import setup + + +setup( + name='addons-frontend', + version='0.1.0', + description='This is https://addons.mozilla.org (AMO)', + author='The Mozilla Team', + author_email='amo-developers@mozilla.org', + url='https://addons.mozilla.org/', + test_suite='.', + zip_safe=False, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Web Environment', + 'License :: OSI Approved :: Mozilla Public License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + ], +) diff --git a/tests/ui/tox.ini b/tests/ui/tox.ini new file mode 100644 index 00000000000..d0b1ad1b711 --- /dev/null +++ b/tests/ui/tox.ini @@ -0,0 +1,11 @@ +# content of: tox.ini , put in same dir as setup.py +[tox] +envlist = ui-tests +[testenv] +basepython = python2.7 +install_command = pip install --no-deps {packages} +[testenv:ui-tests] +passenv = DISPLAY +install_command = pip install {packages} +deps = -rrequirements.txt +commands = py.test --verify-base-url --driver=Firefox test_discopane.py {posargs} From 70d4ddd5d2a8ecbca53d43765f955277aeed9ec1 Mon Sep 17 00:00:00 2001 From: justinpotts Date: Sun, 7 Aug 2016 22:06:00 -0700 Subject: [PATCH 2/9] Update to run with setup.py, update readme, and update tox instructions --- tests/ui/README.md | 16 ---------------- tests/ui/requirements.txt | 3 --- tests/ui/setup.cfg | 2 +- tests/ui/setup.py | 22 ---------------------- tests/ui/tox.ini | 11 ----------- tox.ini | 10 ++++++++++ 6 files changed, 11 insertions(+), 53 deletions(-) delete mode 100644 tests/ui/requirements.txt delete mode 100644 tests/ui/setup.py delete mode 100644 tests/ui/tox.ini create mode 100644 tox.ini diff --git a/tests/ui/README.md b/tests/ui/README.md index 61d5da73bc5..e5a6368d338 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -14,22 +14,6 @@ If you think you would like to contribute to the tests by writing or maintaining it would be a good idea to create a fork of this repository first, and then clone that. GitHub also has great instructions for [forking a repository][git-fork]. -### Create or activate a Python virtual environment -You should install this project's dependencies (which is described in the next step) into a virtual environment -in order to avoid impacting the rest of your system, and to make problem solving easier. -If you already have a virtual environment for these tests, then you should activate it, -otherwise you should create a new one. -For more information on working with virtual environments see our -[summary][virtualenv]. - -### Install dependencies -Install the Python packages that are needed to run our tests using pip. In a terminal, -from the the project root, issue the following command: - -```bash -$ pip install -Ur requirements.txt -``` - ### Run the tests Tests are run using tox on the command line. Below are a couple of examples of running the tests: diff --git a/tests/ui/requirements.txt b/tests/ui/requirements.txt deleted file mode 100644 index 605f9de89b0..00000000000 --- a/tests/ui/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -PyPOM==1.0 -pytest==2.9.2 -pytest-selenium==1.3.1 diff --git a/tests/ui/setup.cfg b/tests/ui/setup.cfg index a6cc148ba08..ed4850b8cee 100644 --- a/tests/ui/setup.cfg +++ b/tests/ui/setup.cfg @@ -1,3 +1,3 @@ [pytest] base_url=https://discovery.addons.mozilla.org -addopts=--driver=Firefox +addopts=--driver=Firefox --verify-base-url diff --git a/tests/ui/setup.py b/tests/ui/setup.py deleted file mode 100644 index 6130ea53deb..00000000000 --- a/tests/ui/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from setuptools import setup - - -setup( - name='addons-frontend', - version='0.1.0', - description='This is https://addons.mozilla.org (AMO)', - author='The Mozilla Team', - author_email='amo-developers@mozilla.org', - url='https://addons.mozilla.org/', - test_suite='.', - zip_safe=False, - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Web Environment', - 'License :: OSI Approved :: Mozilla Public License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - ], -) diff --git a/tests/ui/tox.ini b/tests/ui/tox.ini deleted file mode 100644 index d0b1ad1b711..00000000000 --- a/tests/ui/tox.ini +++ /dev/null @@ -1,11 +0,0 @@ -# content of: tox.ini , put in same dir as setup.py -[tox] -envlist = ui-tests -[testenv] -basepython = python2.7 -install_command = pip install --no-deps {packages} -[testenv:ui-tests] -passenv = DISPLAY -install_command = pip install {packages} -deps = -rrequirements.txt -commands = py.test --verify-base-url --driver=Firefox test_discopane.py {posargs} diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000000..d760b1e94d2 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +skipsdist = true +envlist = discopane-ui-tests + +[testenv:discopane-ui-tests] +deps = + PyPOM + pytest-selenium + pytest +commands = py.test tests/ui/test_discopane.py {posargs} From 561e8f39c568677c492a97c6d43c7fe562da9257 Mon Sep 17 00:00:00 2001 From: justinpotts Date: Tue, 9 Aug 2016 11:10:19 -0700 Subject: [PATCH 3/9] Pin version numbers to dependencies --- tox.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index d760b1e94d2..ce2e83cd3cc 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = discopane-ui-tests [testenv:discopane-ui-tests] deps = - PyPOM - pytest-selenium - pytest + PyPOM==1.0 + pytest==2.9.2 + pytest-selenium==1.3.1 commands = py.test tests/ui/test_discopane.py {posargs} From 7cb03f49da19f08a88608f7b24e76001b35e8206 Mon Sep 17 00:00:00 2001 From: justinpotts Date: Thu, 11 Aug 2016 09:06:25 -0700 Subject: [PATCH 4/9] Add .travis.yml --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d0afff2d74b..98ad7031060 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ env: - TASK=lint - TASK=unittest GUI=1 - TASK=servertest + - TASK=tox TOXENV=discopane-ui-tests cache: directories: - node_modules @@ -15,6 +16,7 @@ before_install: before_script: - if [ $GUI ]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start && sleep 3; fi script: -- npm run $TASK +- if [[ $TASK == 'tox' ]]; then tox -- --base-url http://localhost:4000; fi +- if [[ $TASK != 'tox' ]]; then npm run $TASK; fi addons: firefox: latest From 5a21b950ce25fb1db267b4c8fa15326fe4f96d89 Mon Sep 17 00:00:00 2001 From: justinpotts Date: Thu, 11 Aug 2016 09:23:44 -0700 Subject: [PATCH 5/9] Add tox install to .travis.yml --- .travis.yml | 14 ++++++++++++-- tests/ui/setup.cfg | 2 +- tests/ui/test_discopane.py | 3 +++ tox.ini | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 98ad7031060..c89a4cadea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ +sudo: required +services: + - docker +addons: + firefox: "latest" language: node_js node_js: - '4' @@ -6,17 +11,22 @@ env: - TASK=lint - TASK=unittest GUI=1 - TASK=servertest - - TASK=tox TOXENV=discopane-ui-tests + - TASK=tox TOXENV=discopane-ui-tests GUI=1 cache: directories: - node_modules before_install: - npm install -g npm@3 - npm --version +- sudo pip install tox +- wget "https://github.com/mozilla/geckodriver/releases/download/v0.9.0/geckodriver-v0.9.0-linux64.tar.gz" +- gunzip -c geckodriver-v0.9.0-linux64.tar.gz | tar xopf - +- chmod +x geckodriver +- sudo mv geckodriver /usr/local/bin/wires before_script: - if [ $GUI ]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start && sleep 3; fi script: -- if [[ $TASK == 'tox' ]]; then tox -- --base-url http://localhost:4000; fi +- if [[ $TASK == 'tox' ]]; then docker run -d -p 4000:4000 -e NODE_APP_INSTANCE=disco -e NODE_ENV=uitests $(docker build -q .) /bin/sh -c "npm run build && npm run start" && sleep 60 && tox -- --driver Firefox --base-url http://localhost:4000; fi - if [[ $TASK != 'tox' ]]; then npm run $TASK; fi addons: firefox: latest diff --git a/tests/ui/setup.cfg b/tests/ui/setup.cfg index ed4850b8cee..c7022ead914 100644 --- a/tests/ui/setup.cfg +++ b/tests/ui/setup.cfg @@ -1,3 +1,3 @@ [pytest] base_url=https://discovery.addons.mozilla.org -addopts=--driver=Firefox --verify-base-url +xfail_strict=true diff --git a/tests/ui/test_discopane.py b/tests/ui/test_discopane.py index 8ebef402d71..985379f9300 100644 --- a/tests/ui/test_discopane.py +++ b/tests/ui/test_discopane.py @@ -32,6 +32,9 @@ def discovery_pane(selenium, base_url): return DiscoveryPane(selenium, base_url).open() +@pytest.mark.skipif( + 'localhost' in pytest.config.getoption('base_url'), + reason='Add-ons cannot be installed without SSL on local') @pytest.mark.nondestructive def test_that_discovery_pane_loads(discovery_pane): assert discovery_pane.is_discopane_visible diff --git a/tox.ini b/tox.ini index ce2e83cd3cc..4af3220b308 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ skipsdist = true envlist = discopane-ui-tests [testenv:discopane-ui-tests] +passenv = DISPLAY deps = PyPOM==1.0 pytest==2.9.2 From b6b9eebf58fb077b4410e6143e6f6557d48b99bc Mon Sep 17 00:00:00 2001 From: justinpotts Date: Fri, 12 Aug 2016 13:58:44 -0700 Subject: [PATCH 6/9] Change skip to xfail in test_discopane --- tests/ui/test_discopane.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/test_discopane.py b/tests/ui/test_discopane.py index 985379f9300..d3f2da6aad7 100644 --- a/tests/ui/test_discopane.py +++ b/tests/ui/test_discopane.py @@ -32,7 +32,7 @@ def discovery_pane(selenium, base_url): return DiscoveryPane(selenium, base_url).open() -@pytest.mark.skipif( +@pytest.mark.xfail( 'localhost' in pytest.config.getoption('base_url'), reason='Add-ons cannot be installed without SSL on local') @pytest.mark.nondestructive From ec3081c9a07e7dffdd5c24a718c82527e68ae213 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 15 Aug 2016 11:04:57 -0700 Subject: [PATCH 7/9] Set default driver to Firefox --- .travis.yml | 2 +- tests/ui/setup.cfg | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c89a4cadea8..364a29d2594 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ before_install: before_script: - if [ $GUI ]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start && sleep 3; fi script: -- if [[ $TASK == 'tox' ]]; then docker run -d -p 4000:4000 -e NODE_APP_INSTANCE=disco -e NODE_ENV=uitests $(docker build -q .) /bin/sh -c "npm run build && npm run start" && sleep 60 && tox -- --driver Firefox --base-url http://localhost:4000; fi +- if [[ $TASK == 'tox' ]]; then docker run -d -p 4000:4000 -e NODE_APP_INSTANCE=disco -e NODE_ENV=uitests $(docker build -q .) /bin/sh -c "npm run build && npm run start" && sleep 60 && tox -- --base-url http://localhost:4000; fi - if [[ $TASK != 'tox' ]]; then npm run $TASK; fi addons: firefox: latest diff --git a/tests/ui/setup.cfg b/tests/ui/setup.cfg index c7022ead914..94475329eca 100644 --- a/tests/ui/setup.cfg +++ b/tests/ui/setup.cfg @@ -1,3 +1,4 @@ [pytest] +addopts=--driver=Firefox base_url=https://discovery.addons.mozilla.org xfail_strict=true From 5aaa1bd3250c9b6618cb9a34294787b0a3014439 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 15 Aug 2016 11:16:15 -0700 Subject: [PATCH 8/9] Remove space in pytest command to fix ancestor path discovery --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 364a29d2594..a1682fc6564 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ before_install: before_script: - if [ $GUI ]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start && sleep 3; fi script: -- if [[ $TASK == 'tox' ]]; then docker run -d -p 4000:4000 -e NODE_APP_INSTANCE=disco -e NODE_ENV=uitests $(docker build -q .) /bin/sh -c "npm run build && npm run start" && sleep 60 && tox -- --base-url http://localhost:4000; fi +- if [[ $TASK == 'tox' ]]; then docker run -d -p 4000:4000 -e NODE_APP_INSTANCE=disco -e NODE_ENV=uitests $(docker build -q .) /bin/sh -c "npm run build && npm run start" && sleep 60 && tox -- --base-url=http://localhost:4000; fi - if [[ $TASK != 'tox' ]]; then npm run $TASK; fi addons: firefox: latest From 5672e2d05cbd72890f7e5f5aa0d70a828870c49f Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Mon, 15 Aug 2016 11:28:26 -0700 Subject: [PATCH 9/9] Upgrade to GeckoDriver 0.10.0 and Selenium 3.0.0b2 --- .travis.yml | 6 +++--- tox.ini | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1682fc6564..1f5d47c858e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,10 @@ before_install: - npm install -g npm@3 - npm --version - sudo pip install tox -- wget "https://github.com/mozilla/geckodriver/releases/download/v0.9.0/geckodriver-v0.9.0-linux64.tar.gz" -- gunzip -c geckodriver-v0.9.0-linux64.tar.gz | tar xopf - +- wget "https://github.com/mozilla/geckodriver/releases/download/v0.10.0/geckodriver-v0.10.0-linux64.tar.gz" +- gunzip -c geckodriver-v0.10.0-linux64.tar.gz | tar xopf - - chmod +x geckodriver -- sudo mv geckodriver /usr/local/bin/wires +- sudo mv geckodriver /usr/local/bin before_script: - if [ $GUI ]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start && sleep 3; fi script: diff --git a/tox.ini b/tox.ini index 4af3220b308..9d389cef223 100644 --- a/tox.ini +++ b/tox.ini @@ -8,4 +8,5 @@ deps = PyPOM==1.0 pytest==2.9.2 pytest-selenium==1.3.1 + selenium==3.0.0b2 commands = py.test tests/ui/test_discopane.py {posargs}