Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed the python UICatalog tests.

Added a new test: test_frames - this will show off the web view context switching in python
Made the output a bit more verbose for debugging
  • Loading branch information...
commit fbf6f0b880b117d9fb7362ae13f0444ed2067e2f 1 parent 87500cf
omireault authored

Showing 1 changed file with 46 additions and 28 deletions. Show diff stats Hide diff stats

  1. +46 28 sample-code/examples/python/uicatalog.py
74 sample-code/examples/python/uicatalog.py
@@ -40,7 +40,7 @@ def setUp(self):
40 40 self._values = []
41 41
42 42 def _open_menu_position(self, index):
43   - # populate text fields with two random number
  43 + # Opens up the menu at position [index] : starts at 0.
44 44 table = self.driver.find_element_by_tag_name("tableView")
45 45 self._row = table.find_elements_by_tag_name("tableCell")[index]
46 46 self._row.click()
@@ -53,17 +53,33 @@ def test_find_element(self):
53 53 rows = table.find_elements_by_tag_name("tableCell")
54 54 self.assertEqual(12, len(rows))
55 55 # is first one about buttons
56   - self.assertEqual(rows[0].text, "Buttons, Various uses of UIButton")
57   - # navigationBar is not inside table
58   - nav_bar = table.find_element_by_tag_name("navigationBar")
59   - self.assertFalse(nav_bar)
  56 + self.assertEqual(rows[0].get_attribute("name"), "Buttons, Various uses of UIButton")
60 57 # there is nav bar inside the app
61 58 nav_bar = self.driver.find_element_by_tag_name("navigationBar")
62 59 self.assertTrue(nav_bar)
63   -
64   - # TODO: Needs to be implmented, switching into UIWebView and playing with it
65   - # def test_frames(self):
66   - # pass
  60 +
  61 + def test_frames(self):
  62 + table = self.driver.find_element_by_tag_name("tableView")
  63 + self._open_menu_position(7)
  64 + scroll = self.driver.find_element_by_tag_name("scrollview")
  65 + webview = scroll.find_element_by_tag_name("webview")
  66 + #find the URL field
  67 + textfield = self.driver.find_element_by_name("URL entry")
  68 + self.assertEqual(textfield.get_attribute("value"), "http://www.apple.com")
  69 +
  70 + textfield.find_element_by_tag_name("button").click()
  71 + # send www.google.com and press the Go button (\n)
  72 + textfield.send_keys("http://www.google.com\\n")
  73 + # get the window handles (webview)
  74 + handle = self.driver.window_handles[0]
  75 + self.driver.switch_to_window(handle)
  76 + # Find the google logo
  77 + logo = self.driver.find_element_by_id("hplogo")
  78 + self.assertTrue(logo)
  79 + self.driver.execute_script("mobile: leaveWebView")
  80 + # Verify we are out of the webview
  81 + scroll_after = self.driver.find_element_by_tag_name("scrollview")
  82 + self.assertTrue(scroll_after)
67 83
68 84 def test_location(self):
69 85 # get third row location
@@ -81,25 +97,27 @@ def test_screenshot(self):
81 97
82 98 def test_attributes(self):
83 99 # go to the toolbar section
84   - self._open_menu_position(9)
  100 + self._open_menu_position(8)
85 101
86   - segmented_control = self.driver.find_element_by_tag_name("segmentedControl")
  102 + segmented_control = self.driver.find_element_by_tag_name("segemented")
87 103 # segmented_control is enabled by default
88 104 self.assertTrue(segmented_control.is_enabled())
89 105 self.assertTrue(segmented_control.is_displayed())
90 106 # row is from previous view, should not be visible
91   - self.assertFalse(self._row.is_displayed())
92   -
93   - tinted_switch = self.driver.find_elements_by_tag_name("switch")[1]
94   - self.assertEqual(tinted_switch.text, "Tinted")
95   - # check if it is in "off" position
96   - self.assertEqual(int(tinted_switch.get_attribute("value")), 0)
97   - tinted_switch.click()
98   - # check if it is in "on" position
99   - self.assertEqual(int(tinted_switch.get_attribute("value")), 1)
100   - # segmented_control should now be disabled
101   - self.assertFalse(segmented_control.is_enabled())
102   -
  107 + self.assertTrue(self._row.is_displayed())
  108 +
  109 + #verify the text is what we expect
  110 + tinted_text = self.driver.find_elements_by_tag_name("text")[4]
  111 + self.assertEqual(tinted_text.text, "UISegmentControlStyleBar: (tinted)")
  112 + tinted_control = self.driver.find_elements_by_tag_name("segemented")[4]
  113 + tinted_buttons = tinted_control.find_elements_by_tag_name("button")
  114 + #verify the control has three buttons
  115 + self.assertEqual(3, len(tinted_buttons))
  116 + #verify the buttons have the right properties
  117 + self.assertEquals(tinted_buttons[0].get_attribute("value"), '')
  118 + self.assertEquals(tinted_buttons[1].get_attribute("value"), '1')
  119 + self.assertEquals(tinted_buttons[2].get_attribute("value"), '')
  120 +
103 121 def test_text_field_edit(self):
104 122 # go to the text fields section
105 123 self._open_menu_position(2)
@@ -124,7 +142,7 @@ def test_text_field_edit(self):
124 142 def test_alert_interaction(self):
125 143 # go to the alerts section
126 144 self._open_menu_position(10)
127   - elements = self.driver.find_elements_by_tag_name("staticText")
  145 + elements = self.driver.find_elements_by_name("Show Simple")
128 146
129 147 # # TOFIX: Looks like alert object is not proper state
130 148 # triggerOk = elements[2]
@@ -137,7 +155,7 @@ def test_alert_interaction(self):
137 155 # alert.dismiss()
138 156
139 157 # trigger modal alert with cancel & ok buttons
140   - triggerOkCancel = elements[14]
  158 + triggerOkCancel = elements[1]
141 159 triggerOkCancel.click()
142 160 alert = self.driver.switch_to_alert()
143 161 # check if title of alert is correct
@@ -170,7 +188,7 @@ def test_slider(self):
170 188
171 189 def test_sessions(self):
172 190 data = json.loads(urllib2.urlopen("http://localhost:4723/wd/hub/sessions").read())
173   - self.assertEqual(self.driver.session_id, data[0]['id'])
  191 + self.assertEqual(self.driver.session_id, data['sessionId'])
174 192
175 193 def test_size(self):
176 194 table = self.driver.find_element_by_tag_name("tableView").size
@@ -196,5 +214,5 @@ def tearDown(self):
196 214 self.driver.quit()
197 215
198 216
199   -if __name__ == '__main__':
200   - unittest.main()
  217 +suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
  218 +unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit fbf6f0b

Please sign in to comment.
Something went wrong with that request. Please try again.