Brendan McCollam avatar Brendan McCollam committed 1554909

Adding tests; fixing some failures

Comments (0)

Files changed (2)

punky/browster.py

         if (el.tagName() == 'TEXTAREA' or
            (el.tagName() == 'INPUT' and
             str(el.attribute('type')) in SUPPORTED_STRING_INPUT_TYPES)):
-            v = self._first(selector).evaluateJavaScript('this.value')
+            v = el.evaluateJavaScript('this.value')
             return unicode(v.toString())
         else:
             raise PunkyError('value() expected input[type=text] or textarea')
         if el.tagName() == 'INPUT':
             input_type = str(el.attribute('type'))
             if input_type in ('radio', 'checkbox'):
-                v = self._first(selector).evaluateJavaScript('this.checked')
+                v = el.evaluateJavaScript('this.checked')
                 return v.toBool()
 
         raise PunkyError('checked() expected input[type=radio] or input[type=checkbox]')
         """
         el = self._get_element(selector_or_element)
         if el.tagName() == 'OPTION':
-            v = self._first(selector).evaluateJavaScript('this.selected')
+            v = el.evaluateJavaScript('this.selected')
             return v.toBool()
 
         raise PunkyError('selected() expected option')

tests/test_interaction.py

     eq_(values, ['rgb(255, 192, 203)', '3px dashed purple', '10px', '60px 10px', '1.5em'])
 
 
-def test_fill():
-    """Does calling fill() on an input element cause that element to receive a new value?
+def test_fill_by_selector():
+    """Does calling fill() with a CSS selector cause the element specified
+    to receive a new value?
     """
     browser.load('tests/pages/test_interaction.html')
 
     eq_(value, "vuvuzelas ruined the world cup")
 
 
+def test_fill_by_element():
+    """Does calling fill() on an input element directly cause
+    that element to receive a new value?
+    """
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('#text_input')
+    browser.fill(elem, 'vuvuzelas ruined the world cup')
+
+    # Let us grab the value of that element using raw JavaScript
+    qvariant = browser.runjs("document.getElementById('text_input').value")
+    value = unicode(qvariant.toString())
+    eq_(value, "vuvuzelas ruined the world cup")
+
+
 def test_fill_unicode():
     """Does passing a unicode string to fill() still work?
     """
     assert 'tests/pages/test_interaction_2.html?text_input=foobar&checked_checkbox=on&select=77&mood=livid' in browser.url
 
 
-def test_check():
+def test_check_selector():
     browser.load('tests/pages/test_interaction.html')
 
     browser.check('#unchecked_checkbox')
     eq_(qvariant.toBool(), True)
 
 
-def test_uncheck():
+def test_check_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('#unchecked_checkbox')
+    browser.check(elem)
+
+    qvariant = browser.first('#unchecked_checkbox').evaluateJavaScript('this.checked')
+    eq_(qvariant.toBool(), True)
+
+
+def test_uncheck_selector():
     browser.load('tests/pages/test_interaction.html')
 
     browser.uncheck('#checked_checkbox')
     eq_(qvariant.toBool(), False)
 
 
-def test_select():
+def test_uncheck_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('#checked_checkbox')
+    browser.uncheck(elem)
+
+    qvariant = browser.first('#checked_checkbox').evaluateJavaScript('this.checked')
+    eq_(qvariant.toBool(), False)
+
+
+def test_select_selector():
     browser.load('tests/pages/test_interaction.html')
 
     browser.select('#select option[value="88"]')
     eq_(str(xml), 'Something was selected.')
 
 
-def test_choose():
+def test_select_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('#select option[value="88"]')
+    browser.select(elem)
+
+    qvariant = browser.first('#select').evaluateJavaScript('this.value')
+    eq_(str(qvariant.toString()), '88')
+
+    # Was the 'change' event fired? If the event was fired, then the
+    # #select_message element should contain some text.
+    xml = browser.first('#select_message').toInnerXml()
+    eq_(str(xml), 'Something was selected.')
+
+
+def test_choose_selector():
     browser.load('tests/pages/test_interaction.html')
 
     browser.choose('input[name=mood][value=hulk]')
                     for radio in browser.all('input[type=radio]')]
 
     eq_(radio_values, [False, False, True])
+
+
+def test_choose_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('input[name=mood][value=hulk]')
+    browser.choose(elem)
+
+    radio_values = [radio.evaluateJavaScript('this.checked').toBool()
+                    for radio in browser.all('input[type=radio]')]
+
+    eq_(radio_values, [False, False, True])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.