Commits

Brendan McCollam  committed 4bac2e4

Adding tests for unselect and unchecking radio buttons

  • Participants
  • Parent commits 4138ad3

Comments (0)

Files changed (3)

File punky/browster.py

                 })(this.parentNode);
             """)
         else:
-            raise PunkyFormControlMismatch("Cannot 'select()' {0} element {1}".format(
+            raise PunkyFormControlMismatch("Cannot 'unselect()' {0} element {1}".format(
                     el.tagName(),
                     dict((str(i), str(el.attribute(i)))
                         for i in el.attributeNames())

File tests/pages/test_interaction.html

 
 <head>
     <title>test_interaction</title>
-    
+
     <script>
     var makeNewDiv = function(cls, text) {
         var div = document.createElement('div');
-        
+
         div.setAttribute('class', cls);
         div.innerHTML = text;
-        
+
         document.body.appendChild(div);
     };
-    
+
     var setSelectMessage = function() {
         var span = document.getElementById('select_message');
-        span.innerHTML = 'Something was selected.'        
+        span.innerHTML = 'Something was selected.'
     };
     </script>
 
 
 <form action="test_interaction_2.html">
     <input name="text_input" id="text_input" type="text" value="foobar" />
-    
+
     <br />
-    
+
     <input name="unchecked_checkbox" id="unchecked_checkbox" type="checkbox" />Unchecked checkbox
-    
+
     <br />
-    
+
     <input name="checked_checkbox" id="checked_checkbox"  type="checkbox" checked="checked" />Checked checkbox
-    
+
     <br />
-    
-    <select name="select" id="select" onchange="setSelectMessage();">
+
+    <select name="select1" id="select1" onchange="setSelectMessage();">
         <option value="77">Salsa</option>
         <option value="88">Rumba</option>
         <option value="99">Tango</option>
     </select>
     <span id="select_message"></span>
-    
+
     <br />
 
     <input name="mood" type="radio" value="angry" />Angry
     <input name="mood" type="radio" value="livid" checked="checked" />Livid
     <input name="mood" type="radio" value="hulk" />Hulk Smash!
-    
+
     <br />
-    
+
+    <select multiple="multiple" id="select2" name="select2">
+        <option value="apple">Apple</option>
+        <option value="orange" selected="selected">Orange</option>
+        <option value="pear">Pear</option>
+        <option value="banana">Banana</option>
+    </select>
+
+    <br/>
+
     <input type="submit" value="Submit" />
 </form>
 
 </body>
-</html>
+</html>

File tests/test_interaction.py

 
     browser.submit('form', wait_load=True)
 
-    assert 'tests/pages/test_interaction_2.html?text_input=foobar&checked_checkbox=on&select=77&mood=livid' in browser.url
+    assert '/test_interaction_2.html?text_input=foobar&checked_checkbox=on&select1=77&mood=livid&select2=orange' in browser.url
 
 
 def test_check_selector():
     eq_(qvariant.toBool(), False)
 
 
+def test_uncheck_radio_button_with_selector():
+    browser.load('tests/pages/test_interaction.html')
+
+    css_selector = 'input[type="radio"][name="mood"][value="livid"]'
+    browser.uncheck(css_selector)
+
+    qvariant = browser.first(css_selector).evaluateJavaScript('this.checked')
+    eq_(qvariant.toBool(), False)
+
+
+def test_uncheck_radio_button_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    css_selector = 'input[type="radio"][name="mood"][value="livid"]'
+    elem = browser.first(css_selector)
+    browser.uncheck(elem)
+
+    qvariant = browser.first(css_selector).evaluateJavaScript('this.checked')
+    eq_(qvariant.toBool(), False)
+
+
 def test_select_selector():
     browser.load('tests/pages/test_interaction.html')
 
-    browser.select('#select option[value="88"]')
+    browser.select('#select1 option[value="88"]')
 
-    qvariant = browser.first('#select').evaluateJavaScript('this.value')
+    qvariant = browser.first('#select1').evaluateJavaScript('this.value')
+    eq_(str(qvariant.toString()), '88')
+
+    # Was the 'change' event fired? If the event was fired, then the
+    # #select1_message element should contain some text.
+    xml = browser.first('#select_message').toInnerXml()
+    eq_(str(xml), 'Something was selected.')
+
+
+def test_select_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('#select1 option[value="88"]')
+    browser.select(elem)
+
+    qvariant = browser.first('#select1').evaluateJavaScript('this.value')
     eq_(str(qvariant.toString()), '88')
 
     # Was the 'change' event fired? If the event was fired, then the
     eq_(str(xml), 'Something was selected.')
 
 
-def test_select_element():
+def test_unselect_selector():
     browser.load('tests/pages/test_interaction.html')
 
-    elem = browser.first('#select option[value="88"]')
-    browser.select(elem)
+    browser.unselect('#select2 option[value="orange"]')
 
-    qvariant = browser.first('#select').evaluateJavaScript('this.value')
-    eq_(str(qvariant.toString()), '88')
+    qvariant = browser.first('#select2').evaluateJavaScript('this.value')
+    eq_(str(qvariant.toString()), '')
 
-    # 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_unselect_element():
+    browser.load('tests/pages/test_interaction.html')
+
+    elem = browser.first('#select2 option[value="orange"]')
+    browser.unselect(elem)
+
+    qvariant = browser.first('#select2').evaluateJavaScript('this.value')
+    eq_(str(qvariant.toString()), '')
 
 
 def test_choose_selector():