Skip to content

Commit abf26ef

Browse files
committed
Merge remote-tracking branch 'origin/embedded_views_test' into development
2 parents 1506af7 + 1a376ea commit abf26ef

File tree

7 files changed

+143
-13
lines changed

7 files changed

+143
-13
lines changed

Dockerfile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@ FROM ubuntu:12.04
44
# TODO: add MAINTAINER
55

66
# Install requirements and their dependencies
7-
RUN apt-get update && apt-get install -y \
7+
RUN apt-get update -y
8+
RUN apt-get install -y \
9+
gcc \
10+
libffi-dev \
811
python \
9-
python-setuptools
12+
python-dev \
13+
python-setuptools \
14+
openssl \
15+
mailutils \
16+
ssmtp \
17+
sharutils
1018

1119
RUN easy_install pip
12-
RUN pip install -U setuptools
20+
RUN pip install --upgrade pip
21+
#RUN pip install -U setuptools
1322

1423
# Add source code and install dependencies
1524
RUN mkdir -p /opt/codebender
1625
ADD . /opt/codebender/seleniumTests
26+
1727
WORKDIR /opt/codebender/seleniumTests
18-
RUN pip install -r requirements-dev.txt
28+
29+
RUN pip install -r requirements.txt
30+
31+
COPY ssmtp.conf /etc/ssmtp/
1932

2033
# Specify a default command for the container.
2134
# Right now we simply run bash. TODO: add ENTRYPOINT for running tests.
22-
WORKDIR /opt/codebender/seleniumTests
23-
CMD ["/bin/bash"]
35+
36+
#CMD ["/bin/bash"]

codebender_testing/utils.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from selenium.webdriver.common.keys import Keys
1515
from selenium.webdriver.support import expected_conditions
1616
from selenium.webdriver.support.ui import WebDriverWait
17+
from selenium.webdriver.support import expected_conditions as EC
1718
import pytest
1819

1920
from codebender_testing.config import BASE_URL
@@ -330,6 +331,15 @@ def execute_script(self, script, *deps):
330331
dom_properties_defined(*deps))
331332
return self.driver.execute_script(script)
332333

334+
def check_iframe(self):
335+
"""Returns the contents of an iframe [project_name, user_name, sketch_contents]"""
336+
self.driver.switch_to_frame(driver.find_element_by_tag_name('iframe'))
337+
project_name = self.driver.find_element_by_class_name('projectName').text
338+
user_name = self.driver.find_element_by_class_name('userName').text
339+
sketch_contents = self.driver.execute_script("return editor.getValue();")
340+
self.driver.switch_to_default_content()
341+
return [project_name, user_name, sketch_contents]
342+
333343

334344
class SeleniumTestCase(CodebenderSeleniumBot):
335345
"""Base class for all Selenium tests."""
@@ -358,6 +368,62 @@ def tester_logout(self):
358368
"""A fixture to guarantee that we are logged out before running a test."""
359369
self.logout()
360370

371+
class CodebenderIframeTestCase(SeleniumTestCase):
372+
"""base class for testing iframes"""
373+
374+
@pytest.fixture(scope="class")
375+
def get_iframe(self, selector, iframe):
376+
self.driver.switch_to_frame(self.driver.find_element_by_css_selector(selector))
377+
378+
project_name = self.driver.find_element_by_class_name('projectName').text
379+
assert project_name == iframe['project_name']
380+
381+
if iframe['user_name']:
382+
user_name = self.driver.find_element_by_class_name('userName').text
383+
assert user_name == iframe['user_name']
384+
385+
edit_button = self.driver.find_element_by_id('edit-button').text
386+
assert edit_button == 'Edit'
387+
388+
clone_link = self.driver.find_element_by_class_name('clone-link').text
389+
assert clone_link == 'Clone & Edit'
390+
391+
download_link = self.driver.find_element_by_class_name('download-link').text
392+
assert download_link == 'Download'
393+
394+
editor_contents = self.driver.execute_script("return editor.aceEditor.getValue();")
395+
assert editor_contents.split('\n')[0] == iframe['sketch_contents']
396+
397+
assert self.check_element_exists('#cb_cf_flash_btn') == True
398+
assert self.check_element_exists('#cb_cf_boards') == True
399+
assert self.check_element_exists('#cb_cf_ports') == True
400+
401+
boards_list = WebDriverWait(self.driver, 10).until(
402+
EC.text_to_be_present_in_element((By.ID, "cb_cf_boards"), "Please select a board")
403+
)
404+
405+
self.driver.switch_to_default_content()
406+
407+
@pytest.fixture(scope="class")
408+
def get_serial_monitor(self, selector):
409+
self.driver.switch_to_frame(self.driver.find_element_by_css_selector(selector))
410+
411+
title = self.driver.find_element_by_css_selector('.well > h4').text.strip()
412+
assert title == 'Serial Monitor:'
413+
414+
ports_label = self.driver.find_element_by_css_selector('.well > span').text.strip()
415+
assert ports_label == 'Port:'
416+
417+
assert self.check_element_exists('#cb_cf_ports') == True
418+
assert self.check_element_exists('#cb_cf_baud_rates') == True
419+
assert self.check_element_exists('#cb_cf_serial_monitor_connect') == True
420+
421+
def check_element_exists(self, css_path):
422+
try:
423+
element = self.driver.find_element_by_css_selector(css_path)
424+
return True
425+
except NoSuchElementException:
426+
return False
361427

362428
class VerificationError(Exception):
363429
"""An exception representing a failed verification of a sketch."""

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ flake8
22
pytest
33
setuptools>=12.1
44
tox
5-
virtualenv
5+
virtualenv

requirements.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
flake8
2-
pytest==2.6.4
1+
pyopenssl
2+
ndg-httpsclient
3+
pyasn1
4+
cryptography
5+
tox
6+
virtualenv
37
pyyaml
4-
selenium==2.44.0
8+
pytest==2.6.4
9+
selenium==2.44.0

tests/embedded_views/__init__.py

Whitespace-only changes.

tests/embedded_views/test_embedded.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from codebender_testing.config import TEST_CREDENTIALS
2+
from codebender_testing.utils import CodebenderIframeTestCase
3+
from selenium.webdriver.common.keys import Keys
4+
from selenium.webdriver.common.by import By
5+
from selenium.webdriver.support.ui import WebDriverWait
6+
from selenium.webdriver.support import expected_conditions as EC
7+
8+
class TestHome(CodebenderIframeTestCase):
9+
def test_blog(self):
10+
""" tests codebender's blog """
11+
self.open('http://blog.codebender.cc/2014/03/07/lesson-1-inputs-and-outputs/')
12+
13+
assert "Lesson 1: Inputs and Outputs | codebender's blog" in self.driver.title
14+
15+
iframe = {
16+
'project_name': "Lesson 1 Analog Inputs Example",
17+
'user_name': "codebender_tutorials",
18+
'sketch_contents': "// Dummy example on reading Analog Inputs"
19+
}
20+
21+
self.get_iframe('iframe[src="https://codebender.cc/embed/sketch:31583"]', iframe)
22+
23+
def test_sparkfun(self):
24+
"""tests sparkfun"""
25+
self.open('https://www.sparkfun.com/news/1803')
26+
27+
iframe = {
28+
'project_name': "SIK_circuit01_blink",
29+
'user_name': "SparkFun SIK Examples",
30+
'sketch_contents': "/* SparkFun Inventor's Kit"
31+
}
32+
33+
self.get_iframe('iframe[src="https://codebender.cc/embed/sketch:77046"]', iframe)
34+
35+
def test_oneshield(self):
36+
"""tests one shield"""
37+
self.open('http://1sheeld.com/blog/announcing-4-new-shields-tasker-integration-partnership-with-codebender/')
38+
39+
iframe = {
40+
'project_name': "VoiceRecognition",
41+
'user_name': None,
42+
'sketch_contents': "/*"
43+
}
44+
45+
self.get_iframe('iframe[src="https://codebender.cc/embed/example/OneSheeld/VoiceRecognition"]', iframe)

tox.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
envlist = py27
33

44
[testenv]
5-
deps = -rrequirements.txt
6-
commands = flake8 --max-line-length=100
7-
py.test {posargs} # Pass all command line args from tox to py.test.
5+
install_command = pip install -U {opts} {packages} --no-cache
6+
deps = -r{toxinidir}/requirements.txt
7+
commands = py.test {posargs} # Pass all command line args from tox to py.test.
88
# e.g., `tox <foo>` will invoke `py.test <foo>`.
9+
passenv = CODEBENDER_SELENIUM_HUB_URL

0 commit comments

Comments
 (0)