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
1=== modified file 'tests/autopilot/ubuntuuitoolkit/emulators.py'
2--- tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-21 19:08:50 +0000
3+++ tests/autopilot/ubuntuuitoolkit/emulators.py 2013-10-02 07:16:16 +0000
4@@ -14,11 +14,15 @@
5 # You should have received a copy of the GNU Lesser General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8+import logging
9+
10 from autopilot import input, platform
11 from autopilot.introspection import dbus
12
13 _NO_TABS_ERROR = 'The MainView has no Tabs.'
14
15+logger = logging.getLogger(__name__)
16+
17
18 class ToolkitEmulatorException(Exception):
19 """Exception raised when there is an error with the emulator."""
20@@ -111,6 +115,7 @@
21 :return: The newly opened tab.
22
23 """
24+ logger.debug('Switch to next tab.')
25 self.get_header().switch_to_next_tab()
26 current_tab = self.get_tabs().get_current_tab()
27 current_tab.visible.wait_for(True)
28@@ -123,6 +128,7 @@
29 :return: The newly opened tab.
30
31 """
32+ logger.debug('Switch to tab with index {0}.'.format(index))
33 tabs = self.get_tabs()
34 number_of_tabs = tabs.get_number_of_tabs()
35 if index >= number_of_tabs:
36@@ -130,6 +136,8 @@
37 current_tab = tabs.get_current_tab()
38 number_of_switches = 0
39 while not tabs.selectedTabIndex == index:
40+ logger.debug(
41+ 'Current tab index: {0}.'.format(tabs.selectedTabIndex))
42 if number_of_switches >= number_of_tabs - 1:
43 # This prevents a loop. But if this error is ever raised, it's
44 # likely there's a bug on the emulator or on the QML Tab.
45@@ -162,7 +170,7 @@
46 tabs = self.get_tabs()
47 for index, tab in enumerate(tabs.select_many('Tab')):
48 if tab.objectName == object_name:
49- return self.switch_to_tab_by_index(index)
50+ return self.switch_to_tab_by_index(tab.index)
51 raise ValueError(
52 'Tab with objectName "{0}" not found.'.format(object_name))
53
54@@ -221,11 +229,23 @@
55
56 def get_current_tab(self):
57 """Return the currently selected tab."""
58- return self.select_many('Tab')[self.selectedTabIndex]
59+ return self._get_tab(self.selectedTabIndex)
60+
61+ def _get_tab(self, index):
62+ tabs = self._get_tabs()
63+ for tab in tabs:
64+ if tab.index == index:
65+ return tab
66+ else:
67+ raise ToolkitEmulatorException(
68+ 'There is no tab with index {0}.'.format(index))
69+
70+ def _get_tabs(self):
71+ return self.select_many('Tab')
72
73 def get_number_of_tabs(self):
74 """Return the number of tabs."""
75- return len(self.select_many('Tab'))
76+ return len(self._get_tabs())
77
78
79 class TabBar(UbuntuUIToolkitEmulatorBase):
80@@ -234,16 +254,19 @@
81 def switch_to_next_tab(self):
82 """Open the next tab."""
83 # Click the tab bar to switch to selection mode.
84+ logger.debug('Click the tab bar to enable selection mode.')
85 self.pointing_device.click_object(self)
86 if not self.selectionMode:
87+ logger.debug('Selection mode not enabled, try again.')
88 # in case someone stole the click, like the open toolbar
89 self.pointing_device.click_object(self)
90+ logger.debug('Click the next tab bar button.')
91 self.pointing_device.click_object(self._get_next_tab_button())
92
93 def _get_next_tab_button(self):
94 current_index = self._get_selected_button_index()
95 next_index = (current_index + 1) % self._get_number_of_tab_buttons()
96- return self._get_tab_buttons()[next_index]
97+ return self._get_tab_button(next_index)
98
99 def _get_selected_button_index(self):
100 return self.select_single('QQuickPathView').selectedButtonIndex
101@@ -254,6 +277,15 @@
102 def _get_tab_buttons(self):
103 return self.select_many('AbstractButton')
104
105+ def _get_tab_button(self, index):
106+ buttons = self._get_tab_buttons()
107+ for button in buttons:
108+ if button.buttonIndex == index:
109+ return button
110+ else:
111+ raise ToolkitEmulatorException(
112+ 'There is no tab button with index {0}.'.format(index))
113+
114
115 class ActionSelectionPopover(UbuntuUIToolkitEmulatorBase):
116 """ActionSelectionPopover Autopilot emulator."""

Subscribers

People subscribed via source and target branches

to status/vote changes: