Skip to content

Commit 8ffa7eb

Browse files
author
Brandon Duffany
committed
Add test for ports dropdown and flashing
Note: these tests currently fail, as Selenium is not (yet) playing well with browser extensions.
1 parent 5d7530a commit 8ffa7eb

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

codebender_testing/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717

1818
TEST_PROJECT_NAME = "test_project"
1919

20+
# How long we wait until giving up on trying to locate an element
21+
ELEMENT_FIND_TIMEOUT = 5

codebender_testing/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
from selenium import webdriver
44
from selenium.common.exceptions import NoSuchElementException
55
from selenium.webdriver.common.keys import Keys
6+
from selenium.webdriver.support import expected_conditions
7+
from selenium.webdriver.support.ui import WebDriverWait
68
import pytest
79

810
from codebender_testing.config import BASE_URL
11+
from codebender_testing.config import ELEMENT_FIND_TIMEOUT
912
from codebender_testing.config import TEST_CREDENTIALS
1013
from codebender_testing.config import TEST_PROJECT_NAME
1114
from codebender_testing.config import WEBDRIVERS
1215

1316

14-
1517
class SeleniumTestCase(object):
1618
"""Base class for all Selenium tests."""
1719

@@ -71,3 +73,10 @@ def login(self):
7173
# 'Log In' is not displayed, so we're already logged in.
7274
pass
7375

76+
def get_element(self, *locator):
77+
"""Waits for an element specified by *locator (a tuple of
78+
(By.<something>, str)), then returns it if it is found."""
79+
WebDriverWait(self.driver, ELEMENT_FIND_TIMEOUT).until(
80+
expected_conditions.presence_of_element_located(locator))
81+
return self.driver.find_element(*locator)
82+

tests/sketch/test_sketch.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
from codebender_testing.utils import SeleniumTestCase
1212

1313

14-
# How long to wait before we give up on the 'verify' command (in seconds)
14+
# How long to wait before we give up on trying to assess the result of commands
1515
VERIFY_TIMEOUT = 10
16-
17-
# How long to wait before we give up on finding an element on the page.
18-
ELEMENT_FIND_TIMEOUT = 5
16+
FLASH_TIMEOUT = 2
1917

2018
# Board to test for the dropdown selector.
2119
TEST_BOARD = "Arduino Fio"
@@ -32,7 +30,7 @@ def open_test_project(self, tester_login):
3230
# I get a StaleElementReferenceException without
3331
# this wait. TODO: figure out how to get around this.
3432
time.sleep(3)
35-
33+
3634
def test_verify_code(self):
3735
"""Ensures that we can compile code and see the success message."""
3836
compile_button = self.driver.find_element_by_id("compile")
@@ -46,15 +44,22 @@ def test_verify_code(self):
4644
def test_boards_dropdown(self):
4745
"""Tests that the boards dropdown is present, and that we can change
4846
the board successfully."""
49-
WebDriverWait(self.driver, ELEMENT_FIND_TIMEOUT).until(
50-
expected_conditions.presence_of_element_located(
51-
(By.ID, "boards"))
52-
)
53-
54-
boards_dropdown = Select(self.driver.find_element_by_id("boards"))
47+
boards_dropdown = Select(self.get_element(By.ID, "boards"))
5548

5649
# Click something other than the first option
5750
boards_dropdown.select_by_visible_text(TEST_BOARD)
5851

5952
assert boards_dropdown.first_selected_option.text == TEST_BOARD
6053

54+
def test_ports_dropdown(self):
55+
"""Ensures that the ports dropdown exists."""
56+
self.get_element(By.ID, "ports")
57+
58+
def test_run_with_no_port(self):
59+
"""Makes sure that there is an error when we attempt to run with no
60+
port selected."""
61+
flash_button = self.get_element(By.ID, "usbflash")
62+
flash_button.click()
63+
WebDriverWait(self.driver, FLASH_TIMEOUT).until(
64+
expected_condiditons.text_to_be_present_in_element(
65+
(By.ID, "operation_output"), "Please select a valid port or enable the plugin!!"))

0 commit comments

Comments
 (0)