def test_activity_list_palette(self): with self.run_view("activitieslist"): root = uitree.get_root() for name in ["Make favorite", "Erase", "Start new"]: node = root.find_child(name=name, role_name="label") self.assertIsNotNone(node)
def test_add_button(self): with self.run_activity(): root = uitree.get_root() activity = root.find_child(name="HelloWorld Activity", role_name="frame") label = activity.find_child(name="Hello World!", role_name="label") self.assertEqual(label.text, "Hello World!")
def test_speak(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass all_push_buttons = activity.find_children(role_name="push button") uitree.drag(0.05*self.screen_width, 0.08*self.screen_height, 0.1*self.screen_width, 0.1*self.screen_height) speak_button = all_push_buttons[5] speak_button.click() time.sleep(1) all_toolbar = activity.find_children(role_name="tool bar") speak_toolbar = all_toolbar[1] play_button = speak_toolbar.find_child(role_name="toggle button") stop_button = speak_toolbar.find_child(role_name="push button") play_button.click() time.sleep(3) self.assertIsNotNone(play_button) self.assertIsNotNone(stop_button)
def launch_and_stop_activity(activity_name): logging.info("Launching %s" % activity_name) root = uitree.get_root() shell = root.find_child(name="main.py", role_name="application") table = shell.find_child(role_name="table") cells = table.find_children(role_name="table cell") for row in [cells[i:i + 5] for i in range(0, len(cells), 5)]: name = row[2].name icon = row[1] if name == activity_name: icon.do_action("activate") logging.info("Stopping %s" % activity_name) activity = root.find_child(name="sugar-activity", role_name="application") stop_buttons = activity.find_children(name="Stop", role_name="push button") stop_buttons[-1].do_action("click") activity = root.find_child(name="sugar-activity", role_name="application", expect_none=True) if activity is not None: raise RuntimeError
def test_orignal_size(self): uri = os.getcwd() + '/tests/integration/test.png' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Image Viewer Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass zoom_out_button = activity.find_child(name="Zoom out", role_name="push button") orignal_size = activity.find_child(name="Original size", role_name="push button") count = 5 while count: zoom_out_button.click() time.sleep(0.25) count -= 1 orignal_size.click() time.sleep(0.5) self.assertIsNotNone(zoom_out_button) self.assertIsNotNone(orignal_size) time.sleep(1.5)
def test_webaccount(self): with self.run_view("webaccount"): root = uitree.get_root() for name in [ACCOUNT_NAME]: node = root.find_child(name=name, role_name='label') self.assertIsNotNone(node)
def test_detail_toolbox(self): with self.run_view("journal_detailstoolbox"): root = uitree.get_root() for name in ['Clipboard', ACCOUNT_NAME]: node = root.find_child(name=name, role_name='menu item') self.assertIsNotNone(node)
def test_speak(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass all_push_buttons = activity.find_children(role_name="push button") uitree.drag(0.05 * self.screen_width, 0.08 * self.screen_height, 0.1 * self.screen_width, 0.1 * self.screen_height) speak_button = all_push_buttons[5] speak_button.click() time.sleep(1) all_toolbar = activity.find_children(role_name="tool bar") speak_toolbar = all_toolbar[1] play_button = speak_toolbar.find_child(role_name="toggle button") stop_button = speak_toolbar.find_child(role_name="push button") play_button.click() time.sleep(3) self.assertIsNotNone(play_button) self.assertIsNotNone(stop_button)
def test_webaccount(self): with self.run_view("webaccount"): root = uitree.get_root() for name in [ACCOUNT_NAME]: node = root.find_child(name=name, role_name="label") self.assertIsNotNone(node)
def _check_activities_palette(self): from sugar3.test import uitree root = uitree.get_root() for name in ["Make favorite", "Erase", "Start new"]: node = root.find_child(name=name, role_name="label") self.assertIsNotNone(node)
def run_view(self, name): view_path = os.path.join("views", "%s.py" % name) process = subprocess.Popen(["python", view_path]) try: yield except: logging.debug(uitree.get_root().dump()) raise finally: process.terminate()
def run_view(self, name): view_path = os.path.join("views", "%s.py" % name) process = subprocess.Popen(["python3", view_path]) try: yield except BaseException: logging.debug(uitree.get_root().dump()) raise finally: process.terminate()
def test_tree(self): process = subprocess.Popen(["python", __file__, "show_window1"]) try: root = uitree.get_root() window = root.find_child(name="window1", role_name="frame") button = window.find_child(name="button1", role_name="push button") finally: process.terminate() self.assertIsNotNone(button)
def test_tree(self): process = subprocess.Popen(["python3", __file__, "show_window1"]) try: root = uitree.get_root() window = root.find_child(name="window1", role_name="frame") button = window.find_child(name="button1", role_name="push button") finally: process.terminate() self.assertIsNotNone(button)
def get_activity(self): root = uitree.get_root() #activity = root.find_child(name="Calculate Activity", # role_name="frame") activity = root.find_child(name="Calculate Activity", role_name="frame") '''sec = [] for i in activity: sec.append(i.role_name) return sec''' return activity '''a = root.find_children()
def run_activity(self): if self.bundle_id is not None: process = subprocess.Popen(["sugar-launch", self.bundle_id]) else: print "No bundle_id specified." return try: yield except: logging.debug(uitree.get_root().dump()) raise finally: process.terminate()
def test_zoom(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass time.sleep(2) all_push_buttons = activity.find_children(role_name="push button") zoom_buttons = all_push_buttons[2] zoom_buttons.click() zoom_in = activity.find_child(name="Zoom in", role_name="push button") zoom_out = activity.find_child(name="Zoom out", role_name="push button") zoom_width = activity.find_child(name="Zoom to width", role_name="push button") zoom_fit = activity.find_child(name="Zoom to fit", role_name="push button") actual_size = activity.find_child(name="Actual size", role_name="push button") fullscreen = activity.find_child(name="Fullscreen", role_name="push button") rotate_left = activity.find_child(name="Rotate left", role_name="push button") rotate_right = activity.find_child(name="Rotate right", role_name="push button") count = 10 while count: zoom_in.click() time.sleep(0.25) count -= 1 count = 5 while count: zoom_out.click() time.sleep(0.25) count -= 1 self.assertIsNotNone(zoom_in) self.assertIsNotNone(zoom_out) self.assertIsNotNone(zoom_width) self.assertIsNotNone(zoom_fit) self.assertIsNotNone(actual_size) self.assertIsNotNone(fullscreen) self.assertIsNotNone(rotate_left) self.assertIsNotNone(rotate_right)
def test_open_file(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass stop_button = activity.find_child(name="Stop", role_name="push button") stop_button.click() self.assertIsNotNone(stop_button)
def _run_activity(self, options=None): if self.bundle_id is not None: cmd = ["sugar-launch", self.bundle_id] if options is not None: cmd += options process = subprocess.Popen(cmd) else: print("No bundle_id specified.") return try: yield except BaseException: logging.debug(uitree.get_root().dump()) raise finally: process.terminate()
def test_bookmarks(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass print activity.dump() toggle_buttons = activity.find_children(role_name="toggle button") bookmark_button = toggle_buttons[0] bookmark_button.click() time.sleep(1) self.assertIsNotNone(bookmark_button)
def test_search(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass all_push_buttons = activity.find_children(role_name="push button") edit_buttons = all_push_buttons[1] edit_buttons.click() time.sleep(0.25) all_panels = activity.find_children(role_name="panel") search_panel = all_panels[20] search_box = search_panel.find_child(role_name="text") search_box.click(1, 0.04*self.screen_width, 0.02*self.screen_height) time.sleep(0.5) uitree.type_text('t') time.sleep(1) backward_panel = all_panels[21] forward_panel = all_panels[22] hlight_panel = all_panels[24] forward_button = forward_panel.find_child(role_name="push button") back_button = backward_panel.find_child(role_name="push button") hlight_button = hlight_panel.find_child(role_name="toggle button") count = 2 while count: forward_button.click() time.sleep(1) count -= 1 hlight_button.click() count = 2 while count: back_button.click() time.sleep(1) count -= 1 self.assertIsNotNone(forward_button) self.assertIsNotNone(back_button) self.assertIsNotNone(hlight_button) self.assertIsNotNone(search_box)
def test_check_file(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass all_push_buttons = activity.find_children(role_name="push button") activity_buttons = all_push_buttons[0] activity_buttons.click() time.sleep(1) all_content = activity.find_children(role_name="text") activity_name = all_content[1].text.strip() self.assertEqual(activity_name, "Read Activity")
def test_search(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass all_push_buttons = activity.find_children(role_name="push button") edit_buttons = all_push_buttons[1] edit_buttons.click() time.sleep(0.25) all_panels = activity.find_children(role_name="panel") search_panel = all_panels[20] search_box = search_panel.find_child(role_name="text") search_box.click(1, 0.04 * self.screen_width, 0.02 * self.screen_height) time.sleep(0.5) uitree.type_text('t') time.sleep(1) backward_panel = all_panels[21] forward_panel = all_panels[22] hlight_panel = all_panels[24] forward_button = forward_panel.find_child(role_name="push button") back_button = backward_panel.find_child(role_name="push button") hlight_button = hlight_panel.find_child(role_name="toggle button") count = 2 while count: forward_button.click() time.sleep(1) count -= 1 hlight_button.click() count = 2 while count: back_button.click() time.sleep(1) count -= 1 self.assertIsNotNone(forward_button) self.assertIsNotNone(back_button) self.assertIsNotNone(hlight_button) self.assertIsNotNone(search_box)
def test_check_activity(self): uri = os.getcwd() + '/tests/integration/test.png' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Image Viewer Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass all_buttons = activity.find_children(role_name="push button") activity_button = all_buttons[0] activity_button.click() time.sleep(0.25) activity_name = activity.find_child(role_name="text") self.assertEqual(activity_name.text, "Image Viewer Activity") time.sleep(1.5)
def test_open_file(self): uri = os.getcwd() + '/tests/integration/test.png' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Image Viewer Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass stop_button = activity.find_child(name="Stop", role_name="push button") full_screen = activity.find_child(name="Fullscreen", role_name="push button") stop_button.click() self.assertIsNotNone(stop_button) self.assertIsNotNone(full_screen) time.sleep(1.5)
def test_rotate_aclockwise(self): uri = os.getcwd() + '/tests/integration/test.png' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Image Viewer Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass rotate_aclock = activity.find_child(name="Rotate anticlockwise", role_name="push button") count = 4 while count: rotate_aclock.click() time.sleep(0.25) count -= 1 self.assertIsNotNone(rotate_aclock) time.sleep(1.5)
def test_change_pages(self): uri = 'file://' + os.getcwd() + '/tests/integration/t2.txt' logging.error('OPEN WITH URI %s', uri) with self.run_activity_with_uri(uri): root = uitree.get_root() activity = root.find_child(name="Read Activity", role_name="frame") try: logging.error(activity.dump()) except: logging.error("Error") pass forward_button = activity.find_child(name="Forward", role_name="push button") backward_button = activity.find_child(name="Back", role_name="push button") forward_button.click() time.sleep(1) backward_button.click() time.sleep(1) self.assertIsNotNone(forward_button) self.assertIsNotNone(backward_button)
raise RuntimeError def go_to_list_view(): root = uitree.get_root() shell = root.find_child(name="main.py", role_name="application") radio_button = shell.find_child(name="List view", role_name="radio button") radio_button.do_action("click") def main(): format = "%(created)f %(message)s" logging.basicConfig(format=format) logging.root.setLevel(logging.DEBUG) logging.info("Start test") go_to_list_view() for activity in _activities_list: launch_and_stop_activity(activity) try: main() except: logging.error(traceback.format_exc()) logging.error("\n%s" % uitree.get_root().dump()) raise
def go_to_list_view(): root = uitree.get_root() shell = root.find_child(name="main.py", role_name="application") radio_button = shell.find_child(name="List view", role_name="radio button") radio_button.do_action("click")
def handle_dump_ui_tree(self, event_time): print uitree.get_root().dump()
def get_activity(self): root = uitree.get_root() activity = root.find_child(name="Log Activity", role_name="frame") return activity
if activity is not None: raise RuntimeError def go_to_list_view(): root = uitree.get_root() shell = root.find_child(name="main.py", role_name="application") radio_button = shell.find_child(name="List view", role_name="radio button") radio_button.do_action("click") def main(): format = "%(created)f %(message)s" logging.basicConfig(format=format) logging.root.setLevel(logging.DEBUG) logging.info("Start test") go_to_list_view() for activity in _activities_list: launch_and_stop_activity(activity) try: main() except: logging.error(traceback.format_exc()) logging.error("\n%s" % uitree.get_root().dump()) raise
def get_activity(): root = uitree.get_root() activity = root.find_child(name="Terminal Activity", role_name="frame") return activity
def handle_dump_ui_tree(self, event_time): print(uitree.get_root().dump())
def get_activity(self): root = uitree.get_root() activity = root.find_child(name="Pippy Activity", role_name="frame") return activity