Created
July 12, 2012 18:47
-
-
Save mjschranz/3100092 to your computer and use it in GitHub Desktop.
Export Button Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import time | |
from selenium import webdriver | |
from selenium.webdriver import ActionChains | |
from selenium.webdriver.common.keys import Keys | |
from selenium.common.exceptions import NoSuchElementException | |
class PM_HeaderTests(unittest.TestCase): | |
def setUp(self): | |
self.driver = webdriver.Firefox() | |
self.action = ActionChains( self.driver ) | |
def test_export_dialog(self): | |
driver = self.driver | |
action = self.action | |
templateTitle = "Basic template" | |
driver.get( "http://localhost:8888/templates/test.html" ) | |
driver.maximize_window() | |
self.assertEqual( templateTitle, driver.title ) | |
# Ensure the button is present on the page, then click it | |
sourceButton = driver.find_element_by_id( "butter-header-source" ) | |
self.assertTrue( sourceButton ) | |
sourceButton.click() | |
# Ensure an element with the class_name is present | |
# Only ever have this class on the page at one time | |
sourceDialog = driver.find_element_by_class_name( "butter-dialog" ) | |
self.assertTrue( sourceDialog ) | |
# Get JSON, HTML button in export dialog and their text areas | |
jsonButton = driver.find_element_by_class_name( "json-button" ) | |
htmlButton = driver.find_element_by_class_name( "html-button" ) | |
jsonTextArea = driver.find_element_by_class_name( "json-export" ) | |
htmlTextArea = driver.find_element_by_class_name( "html-export" ) | |
# Ensure the elements were on the page and retrieved | |
self.assertTrue( jsonButton ) | |
self.assertTrue( htmlButton ) | |
self.assertTrue( jsonTextArea ) | |
self.assertTrue( htmlTextArea ) | |
# Check that the appropriate display properties were set when switching to the JSON | |
jsonButton.click() | |
self.assertEqual( jsonTextArea.value_of_css_property( "display" ), "block" ) | |
self.assertEqual( htmlTextArea.value_of_css_property( "display" ), "none" ) | |
# Check that the appropriate display properties were set when switching to the HTML | |
htmlButton.click() | |
self.assertEqual( jsonTextArea.value_of_css_property( "display" ), "none" ) | |
self.assertEqual( htmlTextArea.value_of_css_property( "display" ), "block" ) | |
# Check pressing the ESCAPE key closes the dialog | |
try: | |
sourceDialog.send_keys( Keys.ESCAPE ) | |
sourceDialog = driver.find_element_by_class_name( "butter-dialog" ) | |
except NoSuchElementException as e: | |
self.assertTrue( "Dialog not found, as expected" ) | |
sourceButton.click() | |
dialogCloseButton = driver.find_element_by_class_name( "close-button" ) | |
# Check pressing the close button closes the dialog | |
try: | |
dialogCloseButton.click() | |
sourceDialog = driver.find_element_by_class_name( "butter-dialog" ) | |
except NoSuchElementException as e: | |
self.assertTrue( "Dialog not found, as expected" ) | |
time.sleep( 2 ) | |
def tearDown(self): | |
self.driver.quit() | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment