Merge lp:~elopio/ubuntu-ui-toolkit/fix_tab_switch into lp:ubuntu-ui-toolkit

Proposed by Leo Arias
Status: Rejected
Rejected by: Zsombor Egri
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/fix_tab_switch
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~zsombi/ubuntu-ui-toolkit/tab-index
Diff against target: 116 lines (+36/-4)
1 file modified
tests/autopilot/ubuntuuitoolkit/emulators.py (+36/-4)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/fix_tab_switch
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Zsombor Egri Approve
Review via email: mp+188774@code.launchpad.net

This proposal supersedes a proposal from 2013-09-30.

Commit message

Fixed the tab switch on autopilot emulators that used to rely on the order of the tree.

Description of the change

There where two places where the autopilot emulators relied on the order of the tree. Now, instead of that, they rely on the index property of the elements.
For this, I had to merge zsombi's branch that added the index property to the Tabs.
Here I'm also adding debug information to the log while switching tabs, hoping that it will help to diagnose other failures that happen sometimes on Jenkins. This logs are temporary. Once we can update to autopilot 1.4 we will have a much more elegant way to log all the user actions simulated by autopilot.

To post a comment you must log in.
Revision history for this message
I Ahmad (iahmad) wrote : Posted in a previous version of this proposal

This line import pdb; pdb.set_trace() below will stop the execution if this is picked up by ci. Any reason you are leaving this in your merge proposal?

Revision history for this message
Leo Arias (elopio) wrote : Posted in a previous version of this proposal

> This line import pdb; pdb.set_trace() below will stop the execution if this
> is picked up by ci. Any reason you are leaving this in your merge proposal?

No, thanks for catching it.

Revision history for this message
Zsombor Egri (zsombi) wrote :

Looks good to me. Thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

Had to reject as prerequisite wasn't landing. Merged into prerequisite MR so we can proceed with the release.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/autopilot/ubuntuuitoolkit/emulators.py'
--- tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-21 19:08:50 +0000
+++ tests/autopilot/ubuntuuitoolkit/emulators.py 2013-10-02 07:16:16 +0000
@@ -14,11 +14,15 @@
14# You should have received a copy of the GNU Lesser General Public License14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17import logging
18
17from autopilot import input, platform19from autopilot import input, platform
18from autopilot.introspection import dbus20from autopilot.introspection import dbus
1921
20_NO_TABS_ERROR = 'The MainView has no Tabs.'22_NO_TABS_ERROR = 'The MainView has no Tabs.'
2123
24logger = logging.getLogger(__name__)
25
2226
23class ToolkitEmulatorException(Exception):27class ToolkitEmulatorException(Exception):
24 """Exception raised when there is an error with the emulator."""28 """Exception raised when there is an error with the emulator."""
@@ -111,6 +115,7 @@
111 :return: The newly opened tab.115 :return: The newly opened tab.
112116
113 """117 """
118 logger.debug('Switch to next tab.')
114 self.get_header().switch_to_next_tab()119 self.get_header().switch_to_next_tab()
115 current_tab = self.get_tabs().get_current_tab()120 current_tab = self.get_tabs().get_current_tab()
116 current_tab.visible.wait_for(True)121 current_tab.visible.wait_for(True)
@@ -123,6 +128,7 @@
123 :return: The newly opened tab.128 :return: The newly opened tab.
124129
125 """130 """
131 logger.debug('Switch to tab with index {0}.'.format(index))
126 tabs = self.get_tabs()132 tabs = self.get_tabs()
127 number_of_tabs = tabs.get_number_of_tabs()133 number_of_tabs = tabs.get_number_of_tabs()
128 if index >= number_of_tabs:134 if index >= number_of_tabs:
@@ -130,6 +136,8 @@
130 current_tab = tabs.get_current_tab()136 current_tab = tabs.get_current_tab()
131 number_of_switches = 0137 number_of_switches = 0
132 while not tabs.selectedTabIndex == index:138 while not tabs.selectedTabIndex == index:
139 logger.debug(
140 'Current tab index: {0}.'.format(tabs.selectedTabIndex))
133 if number_of_switches >= number_of_tabs - 1:141 if number_of_switches >= number_of_tabs - 1:
134 # This prevents a loop. But if this error is ever raised, it's142 # This prevents a loop. But if this error is ever raised, it's
135 # likely there's a bug on the emulator or on the QML Tab.143 # likely there's a bug on the emulator or on the QML Tab.
@@ -162,7 +170,7 @@
162 tabs = self.get_tabs()170 tabs = self.get_tabs()
163 for index, tab in enumerate(tabs.select_many('Tab')):171 for index, tab in enumerate(tabs.select_many('Tab')):
164 if tab.objectName == object_name:172 if tab.objectName == object_name:
165 return self.switch_to_tab_by_index(index)173 return self.switch_to_tab_by_index(tab.index)
166 raise ValueError(174 raise ValueError(
167 'Tab with objectName "{0}" not found.'.format(object_name))175 'Tab with objectName "{0}" not found.'.format(object_name))
168176
@@ -221,11 +229,23 @@
221229
222 def get_current_tab(self):230 def get_current_tab(self):
223 """Return the currently selected tab."""231 """Return the currently selected tab."""
224 return self.select_many('Tab')[self.selectedTabIndex]232 return self._get_tab(self.selectedTabIndex)
233
234 def _get_tab(self, index):
235 tabs = self._get_tabs()
236 for tab in tabs:
237 if tab.index == index:
238 return tab
239 else:
240 raise ToolkitEmulatorException(
241 'There is no tab with index {0}.'.format(index))
242
243 def _get_tabs(self):
244 return self.select_many('Tab')
225245
226 def get_number_of_tabs(self):246 def get_number_of_tabs(self):
227 """Return the number of tabs."""247 """Return the number of tabs."""
228 return len(self.select_many('Tab'))248 return len(self._get_tabs())
229249
230250
231class TabBar(UbuntuUIToolkitEmulatorBase):251class TabBar(UbuntuUIToolkitEmulatorBase):
@@ -234,16 +254,19 @@
234 def switch_to_next_tab(self):254 def switch_to_next_tab(self):
235 """Open the next tab."""255 """Open the next tab."""
236 # Click the tab bar to switch to selection mode.256 # Click the tab bar to switch to selection mode.
257 logger.debug('Click the tab bar to enable selection mode.')
237 self.pointing_device.click_object(self)258 self.pointing_device.click_object(self)
238 if not self.selectionMode:259 if not self.selectionMode:
260 logger.debug('Selection mode not enabled, try again.')
239 # in case someone stole the click, like the open toolbar261 # in case someone stole the click, like the open toolbar
240 self.pointing_device.click_object(self)262 self.pointing_device.click_object(self)
263 logger.debug('Click the next tab bar button.')
241 self.pointing_device.click_object(self._get_next_tab_button())264 self.pointing_device.click_object(self._get_next_tab_button())
242265
243 def _get_next_tab_button(self):266 def _get_next_tab_button(self):
244 current_index = self._get_selected_button_index()267 current_index = self._get_selected_button_index()
245 next_index = (current_index + 1) % self._get_number_of_tab_buttons()268 next_index = (current_index + 1) % self._get_number_of_tab_buttons()
246 return self._get_tab_buttons()[next_index]269 return self._get_tab_button(next_index)
247270
248 def _get_selected_button_index(self):271 def _get_selected_button_index(self):
249 return self.select_single('QQuickPathView').selectedButtonIndex272 return self.select_single('QQuickPathView').selectedButtonIndex
@@ -254,6 +277,15 @@
254 def _get_tab_buttons(self):277 def _get_tab_buttons(self):
255 return self.select_many('AbstractButton')278 return self.select_many('AbstractButton')
256279
280 def _get_tab_button(self, index):
281 buttons = self._get_tab_buttons()
282 for button in buttons:
283 if button.buttonIndex == index:
284 return button
285 else:
286 raise ToolkitEmulatorException(
287 'There is no tab button with index {0}.'.format(index))
288
257289
258class ActionSelectionPopover(UbuntuUIToolkitEmulatorBase):290class ActionSelectionPopover(UbuntuUIToolkitEmulatorBase):
259 """ActionSelectionPopover Autopilot emulator."""291 """ActionSelectionPopover Autopilot emulator."""

Subscribers

People subscribed via source and target branches

to status/vote changes: