Skip to content

Commit 1a2c03d

Browse files
authored
Merge pull request #579 from diemol/new-tests
New tests
2 parents ad2cac4 + 812148c commit 1a2c03d

File tree

7 files changed

+430
-9
lines changed

7 files changed

+430
-9
lines changed

.gitignore

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,126 @@ node_modules/
88
*.swp
99

1010
docker-selenium.iml
11+
12+
# Created by https://www.gitignore.io/api/virtualenv
13+
14+
### VirtualEnv ###
15+
# Virtualenv
16+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
17+
.Python
18+
[Bb]in
19+
[Ii]nclude
20+
[Ll]ib
21+
[Ll]ib64
22+
[Ll]ocal
23+
[Ss]cripts
24+
pyvenv.cfg
25+
.venv
26+
pip-selfcheck.json
27+
28+
# End of https://www.gitignore.io/api/virtualenv
29+
tests/tests/*
30+
31+
# Created by https://www.gitignore.io/api/python
32+
33+
### Python ###
34+
# Byte-compiled / optimized / DLL files
35+
__pycache__/
36+
*.py[cod]
37+
*$py.class
38+
39+
# C extensions
40+
*.so
41+
42+
# Distribution / packaging
43+
.Python
44+
env/
45+
build/
46+
develop-eggs/
47+
dist/
48+
downloads/
49+
eggs/
50+
.eggs/
51+
lib/
52+
lib64/
53+
parts/
54+
sdist/
55+
var/
56+
wheels/
57+
*.egg-info/
58+
.installed.cfg
59+
*.egg
60+
61+
# PyInstaller
62+
# Usually these files are written by a python script from a template
63+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
64+
*.manifest
65+
*.spec
66+
67+
# Installer logs
68+
pip-log.txt
69+
pip-delete-this-directory.txt
70+
71+
# Unit test / coverage reports
72+
htmlcov/
73+
.tox/
74+
.coverage
75+
.coverage.*
76+
.cache
77+
nosetests.xml
78+
coverage.xml
79+
*,cover
80+
.hypothesis/
81+
82+
# Translations
83+
*.mo
84+
*.pot
85+
86+
# Django stuff:
87+
*.log
88+
local_settings.py
89+
90+
# Flask stuff:
91+
instance/
92+
.webassets-cache
93+
94+
# Scrapy stuff:
95+
.scrapy
96+
97+
# Sphinx documentation
98+
docs/_build/
99+
100+
# PyBuilder
101+
target/
102+
103+
# Jupyter Notebook
104+
.ipynb_checkpoints
105+
106+
# pyenv
107+
.python-version
108+
109+
# celery beat schedule file
110+
celerybeat-schedule
111+
112+
# SageMath parsed files
113+
*.sage.py
114+
115+
# dotenv
116+
.env
117+
118+
# virtualenv
119+
.venv
120+
venv/
121+
ENV/
122+
123+
# Spyder project settings
124+
.spyderproject
125+
.spyproject
126+
127+
# Rope project settings
128+
.ropeproject
129+
130+
# mkdocs documentation
131+
/site
132+
133+
# End of https://www.gitignore.io/api/python

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
---
1+
language: python
2+
23
sudo: required
34

45
services:
56
- docker
67

7-
language: bash
8-
98
notifications:
109
slack: seleniumhq:Kx5MB7T51SPMpbBMYfvxNW4q
1110

1211
before_install:
1312
- docker info
1413
- VERSION="$TRAVIS_BRANCH" make build
15-
- docker build -t test:local ./Test
1614

1715
script:
1816
- VERSION="$TRAVIS_BRANCH" make test

Makefile

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,43 @@ release: tag_major_minor
228228
docker push $(NAME)/standalone-chrome-debug:$(MAJOR_MINOR_PATCH)
229229
docker push $(NAME)/standalone-firefox-debug:$(MAJOR_MINOR_PATCH)
230230

231-
test:
232-
VERSION=$(VERSION) ./test.sh
233-
VERSION=$(VERSION) ./sa-test.sh
234-
VERSION=$(VERSION) ./test.sh debug
235-
VERSION=$(VERSION) ./sa-test.sh debug
231+
test: test_chrome \
232+
test_firefox \
233+
test_chrome_debug \
234+
test_firefox_debug \
235+
test_chrome_standalone \
236+
test_firefox_standalone \
237+
test_chrome_standalone_debug \
238+
test_firefox_standalone_debug
239+
240+
241+
test_chrome:
242+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeChrome
243+
244+
test_chrome_debug:
245+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeChromeDebug
246+
247+
test_chrome_standalone:
248+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneChrome
249+
250+
test_chrome_standalone_debug:
251+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneChromeDebug
252+
253+
test_firefox:
254+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeFirefox
255+
256+
test_firefox_debug:
257+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodeFirefoxDebug
258+
259+
test_firefox_standalone:
260+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneFirefox
261+
262+
test_firefox_standalone_debug:
263+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneFirefoxDebug
264+
265+
test_phantomjs:
266+
VERSION=$(VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh NodePhantomJS
267+
236268

237269
.PHONY: \
238270
all \

tests/SeleniumTests/__init__.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import unittest
2+
from selenium import webdriver
3+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
4+
5+
6+
class SeleniumGenericTests(unittest.TestCase):
7+
def test_title(self):
8+
self.driver.get('https://the-internet.herokuapp.com')
9+
self.assertTrue(self.driver.title == 'The Internet')
10+
11+
# https://github.com/tourdedave/elemental-selenium-tips/blob/master/03-work-with-frames/python/frames.py
12+
def test_with_frames(self):
13+
driver = self.driver
14+
driver.get('http://the-internet.herokuapp.com/nested_frames')
15+
driver.switch_to.frame('frame-top')
16+
driver.switch_to.frame('frame-middle')
17+
self.assertTrue(driver.find_element_by_id('content').text == "MIDDLE", "content should be MIDDLE")
18+
19+
# https://github.com/tourdedave/elemental-selenium-tips/blob/master/04-work-with-multiple-windows/python/windows.py
20+
def test_with_windows(self):
21+
driver = self.driver
22+
driver.get('http://the-internet.herokuapp.com/windows')
23+
driver.find_element_by_css_selector('.example a').click()
24+
driver.switch_to_window(driver.window_handles[0])
25+
self.assertTrue(driver.title != "New Window", "title should not be New Window")
26+
driver.switch_to_window(driver.window_handles[-1])
27+
self.assertTrue(driver.title == "New Window", "title should be New Window")
28+
29+
# https://github.com/tourdedave/elemental-selenium-tips/blob/master/13-work-with-basic-auth/python/basic_auth_1.py
30+
def test_visit_basic_auth_secured_page(self):
31+
driver = self.driver
32+
driver.get('http://admin:[email protected]/basic_auth')
33+
page_message = driver.find_element_by_css_selector('.example p').text
34+
self.assertTrue(page_message == 'Congratulations! You must have the proper credentials.')
35+
36+
def tearDown(self):
37+
self.driver.quit()
38+
39+
40+
class ChromeTests(SeleniumGenericTests):
41+
def setUp(self):
42+
self.driver = webdriver.Remote(
43+
desired_capabilities=DesiredCapabilities.CHROME
44+
)
45+
46+
47+
class FirefoxTests(SeleniumGenericTests):
48+
def setUp(self):
49+
self.driver = webdriver.Remote(
50+
desired_capabilities=DesiredCapabilities.FIREFOX
51+
)

tests/SmokeTests/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import unittest
2+
import urllib2
3+
import time
4+
import json
5+
6+
7+
class SmokeTests(unittest.TestCase):
8+
def smoke_test_container(self, port):
9+
current_attempts = 0
10+
max_attempts = 3
11+
sleep_interval = 3
12+
status_fetched = False
13+
status_json = None
14+
15+
while current_attempts < max_attempts:
16+
current_attempts = current_attempts + 1
17+
try:
18+
response = urllib2.urlopen('http://localhost:%s/wd/hub/status' % port)
19+
status_json = json.loads(response.read())
20+
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)
21+
status_fetched = True
22+
except Exception as e:
23+
time.sleep(sleep_interval)
24+
25+
self.assertTrue(status_fetched, "Container status was not fetched on port %s" % port)
26+
self.assertTrue(status_json['status'] == 0, "Wrong status value for container on port %s" % port)
27+
self.assertTrue(status_json['value']['ready'], "Container is not ready on port %s" % port)
28+
29+
30+
class NodeTest(SmokeTests):
31+
def test_hub_and_node_up(self):
32+
self.smoke_test_container(4444)
33+
self.smoke_test_container(5555)
34+
35+
36+
class StandaloneTest(SmokeTests):
37+
def test_standalone_up(self):
38+
self.smoke_test_container(4444)

tests/bootstrap.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
cd tests
3+
pip install selenium===3.5.0 \
4+
docker===2.5.1 \
5+
| grep -v 'Requirement already satisfied'
6+
7+
python test.py $1 $2

0 commit comments

Comments
 (0)