Skip to content

New tests #579

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

Merged
merged 14 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,126 @@ node_modules/
*.swp

docker-selenium.iml

# Created by https://www.gitignore.io/api/virtualenv

### VirtualEnv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json

# End of https://www.gitignore.io/api/virtualenv
tests/tests/*

# Created by https://www.gitignore.io/api/python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# End of https://www.gitignore.io/api/python
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
---
language: python

sudo: required

services:
- docker

language: bash

notifications:
slack: seleniumhq:Kx5MB7T51SPMpbBMYfvxNW4q

before_install:
- docker info
- VERSION="$TRAVIS_BRANCH" make build
- docker build -t test:local ./Test

script:
- VERSION="$TRAVIS_BRANCH" make test
Expand Down
42 changes: 37 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,43 @@ release: tag_major_minor
docker push $(NAME)/standalone-chrome-debug:$(MAJOR_MINOR_PATCH)
docker push $(NAME)/standalone-firefox-debug:$(MAJOR_MINOR_PATCH)

test:
VERSION=$(VERSION) ./test.sh
VERSION=$(VERSION) ./sa-test.sh
VERSION=$(VERSION) ./test.sh debug
VERSION=$(VERSION) ./sa-test.sh debug
test: test_chrome \
test_firefox \
test_chrome_debug \
test_firefox_debug \
test_chrome_standalone \
test_firefox_standalone \
test_chrome_standalone_debug \
test_firefox_standalone_debug


test_chrome:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeChrome

test_chrome_debug:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeChromeDebug

test_chrome_standalone:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneChrome

test_chrome_standalone_debug:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneChromeDebug

test_firefox:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeFirefox

test_firefox_debug:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeFirefoxDebug

test_firefox_standalone:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneFirefox

test_firefox_standalone_debug:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneFirefoxDebug

test_phantomjs:
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodePhantomJS


.PHONY: \
all \
Expand Down
51 changes: 51 additions & 0 deletions tests/SeleniumTests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


class SeleniumGenericTests(unittest.TestCase):
def test_title(self):
self.driver.get('https://the-internet.herokuapp.com')
self.assertTrue(self.driver.title == 'The Internet')

# https://github.com/tourdedave/elemental-selenium-tips/blob/master/03-work-with-frames/python/frames.py
def test_with_frames(self):
driver = self.driver
driver.get('http://the-internet.herokuapp.com/nested_frames')
driver.switch_to.frame('frame-top')
driver.switch_to.frame('frame-middle')
self.assertTrue(driver.find_element_by_id('content').text == "MIDDLE", "content should be MIDDLE")

# https://github.com/tourdedave/elemental-selenium-tips/blob/master/04-work-with-multiple-windows/python/windows.py
def test_with_windows(self):
driver = self.driver
driver.get('http://the-internet.herokuapp.com/windows')
driver.find_element_by_css_selector('.example a').click()
driver.switch_to_window(driver.window_handles[0])
self.assertTrue(driver.title != "New Window", "title should not be New Window")
driver.switch_to_window(driver.window_handles[-1])
self.assertTrue(driver.title == "New Window", "title should be New Window")

# https://github.com/tourdedave/elemental-selenium-tips/blob/master/13-work-with-basic-auth/python/basic_auth_1.py
def test_visit_basic_auth_secured_page(self):
driver = self.driver
driver.get('http://admin:[email protected]/basic_auth')
page_message = driver.find_element_by_css_selector('.example p').text
self.assertTrue(page_message == 'Congratulations! You must have the proper credentials.')

def tearDown(self):
self.driver.quit()


class ChromeTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
desired_capabilities=DesiredCapabilities.CHROME
)


class FirefoxTests(SeleniumGenericTests):
def setUp(self):
self.driver = webdriver.Remote(
desired_capabilities=DesiredCapabilities.FIREFOX
)
38 changes: 38 additions & 0 deletions tests/SmokeTests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unittest
import urllib2
import time
import json


class SmokeTests(unittest.TestCase):
def smoke_test_container(self, port):
current_attempts = 0
max_attempts = 3
sleep_interval = 3
status_fetched = False
status_json = None

while current_attempts < max_attempts:
current_attempts = current_attempts + 1
try:
response = urllib2.urlopen('http://localhost:%s/wd/hub/status' % port)
status_json = json.loads(response.read())
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)
status_fetched = True
except Exception as e:
time.sleep(sleep_interval)

self.assertTrue(status_fetched, "Container status was not fetched on port %s" % port)
self.assertTrue(status_json['status'] == 0, "Wrong status value for container on port %s" % port)
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)


class NodeTest(SmokeTests):
def test_hub_and_node_up(self):
self.smoke_test_container(4444)
self.smoke_test_container(5555)


class StandaloneTest(SmokeTests):
def test_standalone_up(self):
self.smoke_test_container(4444)
7 changes: 7 additions & 0 deletions tests/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
cd tests
pip install selenium===3.5.0 \
docker===2.5.1 \
| grep -v 'Requirement already satisfied'

python test.py $1 $2
Loading