Skip to content

Commit

Permalink
Bug 1339547 - Basic set of selenium tests for treeherder
Browse files Browse the repository at this point in the history
  • Loading branch information
wlach committed Feb 16, 2017
1 parent d2fe8d2 commit 70dadec
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
39 changes: 38 additions & 1 deletion .travis.yml
Expand Up @@ -88,7 +88,7 @@ matrix:
# 'https://' being in the site URL. In addition, we override the test environment's debug
# value so the tests pass. The real environment variable will be checked during deployment.
- SITE_URL='https://treeherder.dev' TREEHERDER_DEBUG='False' ./manage.py check --deploy --fail-level WARNING
- py.test tests/ --runslow --ignore=tests/e2e/ --ignore=tests/etl/ --ignore=tests/log_parser/ --ignore=tests/webapp/
- py.test tests/ --runslow --ignore=tests/e2e/ --ignore=tests/etl/ --ignore=tests/log_parser/ --ignore=tests/webapp/ --ignore=tests/selenium/

# Job 4: Python Tests Chunk B
- env: python-tests-e2e-etl-logparser
Expand Down Expand Up @@ -148,6 +148,43 @@ matrix:
script:
- py.test tests/webapp/ --runslow

# Job 6: Python Tests - Selenium integration
- env: python-tests-selenium
# TODO: Investigate switching back to the container infra, by setting `sudo: false`.
sudo: required
language: python
python: "2.7.13"
cache:
directories:
- ~/venv
addons:
firefox: latest
services:
- rabbitmq
before_install:
- curl -sSo ~/elasticsearch.deb https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb && sudo dpkg -i ~/elasticsearch.deb
- sudo service elasticsearch start
- sudo cp puppet/files/mysql/my.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo service mysql restart
# Create a clean virtualenv rather than using the one given to us,
# to work around: https://github.com/travis-ci/travis-ci/issues/4873
- if [[ ! -f ~/venv/bin/activate ]]; then virtualenv -p python ~/venv; fi
- source ~/venv/bin/activate
- pip install --disable-pip-version-check --upgrade pip==8.1.1
- ./bin/vendor-libmysqlclient.sh ~/venv
- mkdir -p $HOME/bin
- wget https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux64.tar.gz
- tar -xzf geckodriver-v0.14.0-linux64.tar.gz -C $HOME/bin
install:
- pip install --disable-pip-version-check --require-hashes -r requirements/common.txt -r requirements/dev.txt
before_script:
- while ! curl localhost:9200 &>/dev/null; do sleep 1; done
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script:
- py.test tests/selenium/ --runselenium --driver Firefox

notifications:
email:
on_success: never
Expand Down
8 changes: 8 additions & 0 deletions requirements/dev.txt
Expand Up @@ -14,6 +14,8 @@ responses==0.5.1 --hash=sha256:3a907f7aae2fd2286d06cfdf238957786c38bbcadc451adce

django-extensions==1.7.5 --hash=sha256:9e0ee15e6e8f88888898092c814f547fb2fb72332dd7982d6605e740cc5a7bd5

pytest-selenium==1.8.0 --hash=sha256:64ee80556502248d7cc4c827cae4b784a92843f1a2a39622d8205ab832365474

# Required by django-extension's runserver_plus command.
Werkzeug==0.11.15 --hash=sha256:c6f6f89124df0514d886782c658c3e12f2caaa94da34cee3fd82eebf4ebf052b

Expand Down Expand Up @@ -44,3 +46,9 @@ pycodestyle==2.2.0 --hash=sha256:60c4e1c36f301ac539a550a29e9d16862069ec240472d86
pyflakes==1.3.0 --hash=sha256:ad89dafee8ca32282116209a0ca4dff050bdc343af958721d5517d242c1215d5

pytest-django==3.1.2 --hash=sha256:00995c2999b884a38ae9cd30a8c00ed32b3d38c1041250ea84caf18085589662

# Required by pytest-selenium
selenium==3.0.2 --hash=sha256:33be5a03d87bf0e6c7a57d3f9bba5314cc66ce4acd44f003465386af2f5a7b4f
pytest-html==1.13.0 --hash=sha256:df423fb613e0e3e1f02b4a4f09e2a670f51f79051617c84545039ff817556bb8
pytest-variables==1.4 --hash=sha256:bd2e152e64c8f670e7969c76219a7842cf8ede795703127981ed71af38cfe08a
pytest-base-url==1.2.0 --hash=sha256:248dae2e3e7bb2c69d10101724b68fe756853e4ece4d9feb8bf09b38c027f65b
8 changes: 8 additions & 0 deletions tests/conftest.py
Expand Up @@ -25,6 +25,11 @@ def pytest_addoption(parser):
action="store_true",
help="run slow tests",
)
parser.addoption(
"--runselenium",
action="store_true",
help="run selenium tests",
)


def pytest_runtest_setup(item):
Expand All @@ -37,6 +42,9 @@ def pytest_runtest_setup(item):
if 'slow' in item.keywords and not item.config.getoption("--runslow"):
pytest.skip("need --runslow option to run")

if 'selenium' in item.keywords and not item.config.getoption("--runselenium"):
pytest.skip("need --runselenium option to run selenium tests")

increment_cache_key_prefix()


Expand Down
37 changes: 37 additions & 0 deletions tests/selenium/test_basics.py
@@ -0,0 +1,37 @@
import pytest
from django.core.management import call_command
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

pytestmark = pytest.mark.selenium


@pytest.fixture
def initial_data(transactional_db):
call_command('load_initial_data')


def test_treeherder_main(initial_data, live_server, selenium):
'''
Tests that the default treeherder page loads ok and we can
click the repository menu
'''
selenium.get(live_server.url)
repo_button = WebDriverWait(selenium, 10).until(
EC.presence_of_element_located((By.ID, 'repoLabel'))
)
repo_button.click()
assert selenium.find_element_by_id('repo-dropdown').is_displayed()


def test_perfherder_main(initial_data, live_server, selenium):
'''
This tests that the basic graphs view load and we can click the add tests button
'''
selenium.get(live_server.url + '/perf.html')
add_test_button = WebDriverWait(selenium, 10).until(
EC.presence_of_element_located((By.ID, 'add-test-data-button'))
)
add_test_button.click()
assert selenium.find_element_by_id('performance-test-chooser').is_displayed()

0 comments on commit 70dadec

Please sign in to comment.