~rpadovani/ubuntu-calculator-app/1365564

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_calculator_app/__init__.py

  • Committer: Riccardo Padovani
  • Date: 2014-10-20 15:51:35 UTC
  • mfrom: (319.1.18 ubuntu-calculator-app)
  • Revision ID: riccardo@rpadovani.com-20141020155135-xfe5cd6kffz5qoar
MergedĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import logging
20
20
 
21
21
import autopilot.logging
22
 
from autopilot.introspection import dbus
23
22
 
24
23
import ubuntuuitoolkit
25
24
 
95
94
 
96
95
    def get_current_screen(self):
97
96
        """Return the screen for the current calculation."""
98
 
        count = self.get_number_of_screens()
99
 
        return self.select_many(Screen)[count - 1]
 
97
        return self.get_screen_by_index(0)
100
98
 
101
99
    def get_operand_by_index(self, index):
102
100
        """Return an operand of a calculation entered."""
117
115
 
118
116
    def get_screen_by_index(self, index):
119
117
        """Return a screen."""
120
 
        return self._get_screens()[index]
 
118
        return self.wait_select_single(Screen,
 
119
                                       objectName="screen" + str(index))
121
120
 
122
121
    def _get_screens(self):
123
122
        return self.select_many(Screen)
131
130
        _, prev_screen_y, _, prev_screen_h = previous_screen.globalRect
132
131
        x, y, w, h = self.globalRect
133
132
        start_x = stop_x = x + w / 2
134
 
        start_y = y + h / 2
135
 
        stop_y = start_y + y - prev_screen_y
 
133
        stop_y = y + h / 2
 
134
        start_y = stop_y + y - prev_screen_y
136
135
        self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
137
136
        self._wait_for_screen_to_finish_animation()
138
137
 
253
252
        try:
254
253
            return self.select_single(
255
254
                'CalcLabel', objectName='result', isLast=True)
256
 
        except dbus.StateNotFoundError:
257
 
            results = self.select_many('CalcLabel', objectName='result')
258
 
            count = len(results)
259
 
            if count > 0:
260
 
                return results[count - 1]
261
 
            else:
262
 
                return None
 
255
        except:
 
256
            try:
 
257
                return self.select_many('CalcLabel', objectName='result')[0]
 
258
            except:
 
259
                try:
 
260
                    return self.select_single(
 
261
                        'CalcLabel', objectName='result')
 
262
                except:
 
263
                    return None
263
264
 
264
265
    @autopilot.logging.log_action(logger.info)
265
266
    def click_result_label(self):
310
311
                self.get_operand_by_index(0) == "")
311
312
 
312
313
    def _get_number_of_labels(self):
313
 
        return len(self.select_many('CalcLabel'))
 
314
        try:
 
315
            labels = self.select_many('CalcLabel')
 
316
        except:
 
317
            try:
 
318
                labels = self.select_single('CalcLabel')
 
319
            except:
 
320
                raise CalculatorException("No calculations found")
 
321
 
 
322
        return len(labels)
314
323
 
315
324
    @autopilot.logging.log_action(logger.info)
316
325
    def swipe_to_delete(self):