class GtkSpinButton(AutopilotGtkEmulatorBase): """ Emulator class for a GtSpinButton instance""" def __init__(self, *args): super(GtkSpinButton, self).__init__(*args) self.pointing_device = Pointer(Mouse.create()) self.kbd = Keyboard.create() def enter_value(self, value): self._select_entry() self.kbd.type(value) expectThat(self.text).equals( value, msg="Expected spinbutton value '{0}' to equal {1}" .format(self.text, value)) def _select_entry(self, ): self.pointing_device.move_to_object(self) pos = self.pointing_device.position() x = pos[0] y = pos[1] x -= 15 # px self.pointing_device.move(x, y) self.pointing_device.click() self.kbd.press_and_release('Ctrl+a') self.kbd.press_and_release('Delete')
class GtkSpinButton(AutopilotGtkEmulatorBase): """ Emulator class for a GtSpinButton instance""" def __init__(self, *args): super(GtkSpinButton, self).__init__(*args) self.pointing_device = Pointer(Mouse.create()) self.kbd = Keyboard.create() def enter_value(self, value): self._select_entry() self.kbd.type(value) expectThat(self.text).equals( value, msg="Expected spinbutton value '{0}' to equal {1}".format( self.text, value)) def _select_entry(self, ): self.pointing_device.move_to_object(self) pos = self.pointing_device.position() x = pos[0] y = pos[1] x -= 15 # px self.pointing_device.move(x, y) self.pointing_device.click() self.kbd.press_and_release('Ctrl+a') self.kbd.press_and_release('Delete')
class UbuntuHTML5TestCaseBase(AutopilotTestCase): BROWSER_CONTAINER_PATH = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../tools/qml/webview.qml') INSTALLED_BROWSER_CONTAINER_PATH = '/usr/share/ubuntu-html5-theme/autopilot-tests/qml/webview.qml' arch = subprocess.check_output( ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip() BROWSER_QML_APP_LAUNCHER = "/usr/lib/" + arch + "/qt5/bin/qmlscene" # TODO: fix version LOCAL_HTML_EXAMPLES_PATH = os.path.abspath("%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../../../0.1/examples/')) INSTALLED_HTML_EXAMPLES_PATH = '/usr/share/ubuntu-html5-theme/0.1/examples' APPS_SUBFOLDER_NAME = 'apps' BASE_PATH = '' def get_browser_container_path(self): if os.path.exists(self.BROWSER_CONTAINER_PATH): return self.BROWSER_CONTAINER_PATH return self.INSTALLED_BROWSER_CONTAINER_PATH def create_file_url_from(self, filepath): return 'file://' + filepath def setup_base_path(self): if os.path.exists(self.LOCAL_HTML_EXAMPLES_PATH): self.BASE_PATH = self.LOCAL_HTML_EXAMPLES_PATH else: self.BASE_PATH = self.INSTALLED_HTML_EXAMPLES_PATH def setUp(self): self.setup_base_path() self.pointer = Pointer(Mouse.create()) self.app = self.launch_test_application(self.BROWSER_QML_APP_LAUNCHER, self.get_browser_container_path()) self.webviewContainer = self.get_webviewContainer() self.watcher = self.webviewContainer.watch_signal('resultUpdated(QString)') super(UbuntuHTML5TestCaseBase, self).setUp() def tearDown(self): super(UbuntuHTML5TestCaseBase, self).tearDown() def pick_app_launcher(self, app_path): # force Qt app introspection: from autopilot.introspection.qt import QtApplicationLauncher return QtApplicationLauncher() def get_webviewContainer(self): return self.app.select_single(objectName="webviewContainer") def get_webview(self): return self.app.select_single(objectName="webview") def get_addressbar(self): return self.app.select_single(objectName="addressbar") def get_button(self): return self.app.select_single(objectName="browseButton") def get_title(self): return self.get_webview().title def assert_url_eventually_loaded(self, url): webview = self.get_webview() self.assertThat(webview.loadProgress, Eventually(Equals(100))) self.assertThat(webview.loading, Eventually(Equals(False))) self.assertThat(webview.url, Eventually(Equals(url))) def click_dom_node_with_id(self, id): webview = self.get_webviewContainer() webview.slots.clickElementById(id) self.assertThat(lambda: self.watcher.num_emissions, Eventually(Equals(1))) def click_any_dom_node_by_selector(self, selector): webview = self.get_webviewContainer() webview.slots.clickAnyElementBySelector(selector) self.assertThat(lambda: self.watcher.num_emissions, Eventually(Equals(1))) def is_dom_node_visible(self, id): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.isNodeWithIdVisible(id) self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads(webview.get_signal_emissions('resultUpdated(QString)')[-1][0])['result'] def eval_expression_in_page_unsafe(self, expr): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.evalInPageUnsafe(expr) self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads(webview.get_signal_emissions('resultUpdated(QString)')[-1][0])['result'] def get_dom_node_id_attribute(self, id, attribute): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.getAttributeForElementWithId(id, attribute) self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads(webview.get_signal_emissions('resultUpdated(QString)')[-1][0])['result'] def browse_to_url(self, url): addressbar = self.get_addressbar() self.pointer.move_to_object(addressbar) self.pointer.click() self.keyboard.type(url, 0.001) button = self.get_button() self.pointer.move_to_object(button) self.pointer.click() self.assert_url_eventually_loaded(url); def browse_to_app(self, appname): APP_HTML_PATH = self.create_file_url_from(os.path.abspath(self.BASE_PATH + '/../../tests/data/html/' + self.APPS_SUBFOLDER_NAME + '/' + appname + '/index.html')) self.browse_to_url(APP_HTML_PATH) def browse_to_test_html(self, html_filename): self.browse_to_url(self.create_file_url_from(os.path.abspath(self.BASE_PATH + '/../../tests/data/html/' + html_filename)))
class DefaultInstallTests(AutopilotTestCase): def setUp(self): super(DefaultInstallTests, self).setUp() self.app = self.launch_application() #properties = self.app.get_properties() #print(properties) self.pointing_device = Pointer(Mouse.create()) def launch_application(self): ''' Hmm... launch ubiquity :returns: The application proxy object. ''' my_process = int(os.environ['UBIQUITY_PID']) my_dbus = str(os.environ['DBUS_SESSION_BUS_ADDRESS']) return get_proxy_object_for_existing_process( pid=my_process, dbus_bus=my_dbus) def test_default_install(self): ''' Test install using all default values ''' #Ubuntu: Lets get the focus back to ubiquity window #Comment out this line if running test on xubuntu/lubuntu and make sure terminal # is not on top of ubiquity when starting the test. #FIXME: Need setup and teardown to be implemented so we can lose this all together self.keyboard.press_and_release('Super+1') main_window = self.app.select_single( 'GtkWindow', name='live_installer') self.assertThat(main_window.title, Equals("Install")) # This method runs the ubiquity_ methods to navigate # testing through the install pages self.run_default_install_test() #Then finally here check that the complete dialog appears self.ubiquity_did_install_complete() def run_default_install_test(self): ''' this can be easily used when debugging. If the test exits on a particular page, you can comment out the pages prior to the exit point and reset current page to its default state, then run test again. The test will start from the page it exited on. This can save alot of hassle having to setup the whole test again, just to fix a small error. ''' #Page 1 self.ubiquity_welcome_page_test() #Page 2 self.ubiquity_preparing_page_test() ##Page 3 self.ubiquity_install_type_page_test() #Page 4 self.ubiquity_where_are_you_page_test() #Page 5 self.ubiquity_keyboard_page_test() #Page 6 self.ubiquity_who_are_you_page_test() #page 7 self.ubiquity_progress_bar_test() def ubiquity_welcome_page_test(self): ''' Tests that all needed objects on the Welcome page are accessible And can also be navigated to. Once confirmed continue with install accepting all defaults ''' self.get_ubiquity_objects() self.assertThat(self.headerlabel.label, Eventually(Contains('Welcome'))) #Can we navigate to the quit button? This fails the test if object # has no position attribs self.pointing_device.move_to_object(self.quit_button) self.assertThat(self.continue_button.label, Equals('Continue')) #Can we navigate to the continue button? self.pointing_device.move_to_object(self.continue_button) #Finally lets move on to the next page self.pointing_device.click() def ubiquity_preparing_page_test(self): self.wait_for_button_state_changed() #Check the next page title self.assertThat(self.headerlabel.label, Eventually(Contains('Preparing to install'))) #lets get all the page objects self.get_ubiquity_objects() ''' Lets test we can go back to the welcome page and come back here ''' #Click back self.pointing_device.move_to_object(self.back_button) self.pointing_device.click() self.wait_for_button_state_changed() #check we went back self.assertThat(self.headerlabel.label, Eventually(Contains('Welcome'))) #go back to the page we were on self.get_ubiquity_objects() self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() self.wait_for_button_state_changed() self.assertThat(self.headerlabel.label, Eventually(Contains('Preparing to install'))) ''' Lets navigate round all objects ''' # first need to get all objects again self.get_ubiquity_objects() #navigate to each one self.pointing_device.move_to_object(self.install_updates) self.pointing_device.move_to_object(self.third_party) self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.quit_button) self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) #Lets move on to next page now self.pointing_device.click() def ubiquity_install_type_page_test(self): """ Check next page value """ self.assertThat(self.headerlabel.label, Eventually(Contains('Installation type'))) #get all page objects self.get_ubiquity_objects() ''' Test we can go back to previous page and come back here ''' #Go back self.pointing_device.move_to_object(self.back_button) self.pointing_device.click() self.wait_for_button_state_changed() self.assertThat(self.headerlabel.label, Eventually(Contains('Preparing to install'))) #To Come back again we need to get the objects of the preparing page self.get_ubiquity_objects() self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() #check we came back ok self.assertThat(self.headerlabel.label, Eventually(Contains('Installation type'))) ''' Lets check we can get and navigate to all the objects If we wanted to change the install type we can just add required clicks here for different installation types ''' #Get all the page objects again self.get_ubiquity_objects() self.assertThat(self.erase_disk.label, Contains('Erase disk and install')) self.pointing_device.move_to_object(self.erase_disk) self.pointing_device.move_to_object(self.lvm_install) self.pointing_device.move_to_object(self.something_else_install) self.pointing_device.move_to_object(self.encrypt_install) self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.quit_button) self.pointing_device.move_to_object(self.continue_button) #and now continue self.assertThat(self.continue_button.label, Equals('_Install Now')) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def ubiquity_where_are_you_page_test(self): """ From this point on the installation has started If you need to re-run the test from here then the HDD partitions need to be wiped and ./run_ubiquity run again """ #check button activated self.wait_for_button_state_changed() self.get_ubiquity_objects() #check we are on the correct page. self.assertThat(self.headerlabel.label, Eventually(Contains('Where are you?'))) #Not much to test on this page lets move on self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def ubiquity_keyboard_page_test(self): #Check we are on the right page self.assertThat(self.headerlabel.label, Eventually(Contains('Keyboard layout'))) #get all the page objects self.get_ubiquity_objects() ''' Test we can go back ''' self.pointing_device.move_to_object(self.back_button) self.pointing_device.click() self.wait_for_button_state_changed() #check we went back ok self.assertThat(self.headerlabel.label, Eventually(Contains('Where are you?'))) #now lets go back self.continue_button = self.app.select_single('GtkButton', name='next') self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() #wait for button to become active again self.wait_for_button_state_changed() #check we came back ok self.assertThat(self.headerlabel.label, Eventually(Contains('Keyboard layout'))) #We need to get the page objects again as the id's have changed self.get_ubiquity_objects() ''' Test we can test keyboard ''' self.pointing_device.move_to_object(self.keyboard_entry) self.pointing_device.click() self.keyboard.type('This is testing that we can enter text in this GtkEntry') ''' Test we can navigate round the objects ''' self.pointing_device.move_to_object(self.keyboard_layout) self.pointing_device.move_to_object(self.keyboard_entry) self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.continue_button) #Lets move on to next page self.pointing_device.click() def ubiquity_who_are_you_page_test(self): """ This method enters the new users details on the 'Who are you?' page """ #assert page title self.assertThat(self.headerlabel.label, Eventually(Contains('Who are you'))) self.get_ubiquity_objects() ''' Test we can create a user ''' self.keyboard.type('autopilot rocks') # Lets lose these tabs self.pointing_device.move_to_object(self.password_entry) self.pointing_device.click() #Intentionally cause passwords to mis-match self.keyboard.type('password') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.conf_pwd_entry) self.pointing_device.click() self.keyboard.type('will_not_match') #check that passwords match, and if not redo them self.check_passwords_match() self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def check_passwords_match(self): while True: self.continue_button = self.app.select_single('GtkButton', name='next') button_sensitive = self.continue_button.sensitive if button_sensitive == 1: self.assertThat(self.continue_button.sensitive, Equals(1)) break #If passwords didn't match (which they didn't ;-) ) then retype them self.pointing_device.move_to_object(self.password_entry) self.pointing_device.click() self.keyboard.press_and_release('Ctrl+a') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.password_entry) self.keyboard.type('password') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.conf_pwd_entry) self.pointing_device.click() self.keyboard.press_and_release('Ctrl+a') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.password_entry) self.keyboard.type('password') def ubiquity_progress_bar_test(self): ''' This method tracks the current progress of the install by using the fraction property of the progress bar to assertain the percentage complete. ''' #We cant assert page title here as its an external html page #Maybe try assert WebKitWebView is visible self.webkitwindow = self.app.select_single('GtkScrolledWindow', name='webkit_scrolled_window') self.assertThat(self.webkitwindow.visible, Eventually(Equals(1))) #Can we track the progress percentage? self.install_progress = self.app.select_single('GtkProgressBar', name='install_progress') #Copying files progress bar self.track_install_progress_bar() self.assertThat(self.install_progress.fraction, Eventually(Equals(0.0))) #And now the install progress bar self.track_install_progress_bar() def track_install_progress_bar(self): ''' Gets the value of the fraction property of the progress bar so we can see when the progress bar is complete ''' progress = 0.0 complete = 1.0 while progress < complete: #Lets check there have been no install errors while in this loop self.check_for_install_errors() #keep updating fraction value progress = self.install_progress.fraction # Use for debugging. Shows current 'fraction' value print(progress) def ubiquity_did_install_complete(self): self.complete_dialog = self.app.select_single('GtkDialog', name='finished_dialog') self.assertThat(self.complete_dialog.title, Eventually(Contains('Installation Complete'))) self.con_testing_button = self.complete_dialog.select_single('GtkButton', name='quit_button') self.restart_button = self.complete_dialog.select_single('GtkButton', name='reboot_button') self.assertThat(self.complete_dialog.visible, Eventually(Equals(1))) def wait_for_button_state_changed(self): ''' This waits on the continuebutton becoming active again ''' self.continue_button = self.app.select_single('GtkButton', name='next') #check button disabled self.assertThat(self.continue_button.sensitive, Eventually(Equals(0))) obj_prop = self.continue_button.sensitive #lets wait for button to enable again while obj_prop != 1: #keep grabbing the button to refresh it's state self.continue_button = self.app.select_single('GtkButton', name='next') obj_prop = self.continue_button.sensitive #Check there are no errors while in this loop self.check_for_install_errors() #lets check it is enabled before returning self.assertThat(self.continue_button.sensitive, Eventually(Equals(1))) def check_for_install_errors(self): ''' This checks that no error/unwanted dialogs appear simply asserting that their visible properties = 0 If they are not visible then there is no problems, UI wise that is! ;-) ''' # For each dialog lets, select each dialog and finally check its not visible crash_dialog = self.app.select_single('GtkDialog', name='crash_dialog') self.assertThat(crash_dialog.visible, Equals(0)) warning_dialog = self.app.select_single('GtkDialog', name='warning_dialog') self.assertThat(warning_dialog.visible, Equals(0)) def get_ubiquity_objects(self): """ Selects all the objects needed for usage in the test """ #-----------------------------------------------------------------------# # OBJECTS THAT ARE ON EVERY PAGE # # # self.headerlabel = self.app.select_single('GtkLabel', name='page_title') self.quit_button = self.app.select_single('GtkButton', name='quit') self.assertThat(self.quit_button.label, Equals('_Quit')) # We cannot assert continue button label here as the label value changes self.continue_button = self.app.select_single('GtkButton', name='next') #-----------------------------------------------------------------------# #-----------------------------------------------------------------------# # OBJECTS THAT ARE ON MULTIPLE PAGES # # # self.back_button = self.app.select_single('GtkButton', name='back') self.assertThat(self.back_button.label, Equals('_Back')) #-----------------------------------------------------------------------# #-----------------------------------------------------------------------# # OBJECTS 'FROM PREPARING TO INSTALL' PAGE # # # self.install_updates = self.app.select_single('GtkCheckButton', name='prepare_download_updates') self.assertThat(self.install_updates.label, Equals('Download updates while installing')) self.third_party = self.app.select_single('GtkCheckButton', name='prepare_nonfree_software') self.assertThat(self.third_party.label, Equals('Install this third-party software')) #------------------------------------------------------------------------# #------------------------------------------------------------------------# # OBJECTS FROM THE 'INSTALLATION TYPE' PAGE # # # self.erase_disk = self.app.select_single('GtkRadioButton', name='use_device') self.encrypt_install = self.app.select_single('GtkCheckButton', name='use_crypto') self.assertThat(self.encrypt_install.label, Equals('Encrypt the new Ubuntu installation for security')) self.lvm_install = self.app.select_single('GtkCheckButton', name='use_lvm') self.assertThat(self.lvm_install.label, Equals('Use LVM with the new Ubuntu installation')) self.something_else_install = self.app.select_single('GtkRadioButton', name='custom_partitioning') self.assertThat(self.something_else_install.label, Equals('Something else')) #-------------------------------------------------------------------------# #-------------------------------------------------------------------------# # OBJECTS FROM THE KEYBOARD LAYOUT PAGE # # # self.keyboard_entry = self.app.select_single('GtkEntry', name='keyboard_test') self.keyboard_layout = self.app.select_single('GtkButton', name='deduce_layout') self.assertThat(self.keyboard_layout.label, Equals('Detect Keyboard Layout')) #-------------------------------------------------------------------------# #-------------------------------------------------------------------------# # OBJECTS FROM THE 'WHO ARE YOU' PAGE # # # self.user_gtkbox = self.app.select_single('GtkBox', name='stepUserInfo') self.user_gtkgrid = self.user_gtkbox.select_single('GtkGrid', name='userinfo_table') self.user_hbox1 = self.user_gtkgrid.select_single('GtkBox', name='hbox1') self.password_entry = self.user_hbox1.select_single('GtkEntry', name='password') self.user_hbox2 = self.user_gtkgrid.select_single('GtkBox', name='hbox2') self.conf_pwd_entry = self.user_hbox2.select_single('GtkEntry', name='verified_password')
class UbiquityAutopilotTestCase(UbiquityTestCase): def setUp(self): super(UbiquityAutopilotTestCase, self).setUp() self.app = self.launch_application() self.pointing_device = Pointer(Mouse.create()) self.kbd = Keyboard.create() self.current_page_title = '' self.previous_page_title = '' self.current_step = '' self.step_before = '' self.english_install = False english_label_conf.generate_config() self.english_config = configparser.ConfigParser() self.english_config.read('/tmp/english_config.ini') #delete config at end of test self.addCleanup(os.remove, '/tmp/english_config.ini') # always starts with 1 row ('/dev/sda') self.part_table_rows = 1 self.total_number_partitions = 0 def tearDown(self): self._check_no_visible_dialogs() super(UbiquityAutopilotTestCase, self).tearDown() unittest.TestCase.tearDown(self) def launch_application(self): ''' Hmm... launch ubiquity :returns: The application proxy object. ''' my_process = int(os.environ['UBIQUITY_PID']) my_dbus = str(os.environ['DBUS_SESSION_BUS_ADDRESS']) return get_proxy_object_for_existing_process( pid=my_process, dbus_bus=my_dbus, emulator_base=AutopilotGtkEmulatorBase) @property def main_window(self, ): return self.app.select_single('GtkWindow', name='live_installer') def go_to_next_page(self, wait=False): """ Goes to the next page of Ubiquity installer Will timeout after 2 mins waiting for next page to appear. Params: wait: If set to true will wait for the buttons sensitive property to be true. Will timeout after 20mins. NOTE: this should only be used when clicking 'Install Now' the default 2 mins is sufficient for every other page switch """ logger.debug('go_to_next_page(wait={0})'.format(wait)) nxt_button = self.main_window.select_single('GtkButton', name='next') nxt_button.click() if wait: # This sleep just bridges a weird error when the next button, # sometimes flickers its sensitive property back to 1 once clicked # and then goes back to 0 time.sleep(2) # now take back over from the sleep and wait for sensitive to # become 1 logger.debug("Waiting for 'next' Button to become sensitive " "again.....") self.assertThat(nxt_button.sensitive, Eventually(Equals(True), timeout=1200)) page_title = self.main_window.select_single( 'GtkLabel', name='page_title') self.assertThat(page_title.label, Eventually(NotEquals(self.current_page_title), timeout=120)) def go_to_progress_page(self, ): """ This simply clicks next and goes to the progress page NOTE: This shouldn't be used for any other page switches as it does no checks. """ nxt_button = self.main_window.select_single('GtkButton', name='next') nxt_button.click() def welcome_page_tests(self, lang=None): """ Runs the tests for the Welcome Page :param lang: The treeview label value (e.g 'English') of the required language. If None will pick a random language from the tree. ..NOTE: You should only specify a language if the test relies upon a specific language. It is better to write the tests to work for any language. """ self._update_current_step('stepLanguage') self._check_navigation_buttons() #first check pageTitle visible and correct if label given logger.debug("run_welcome_page_tests()") #selecting an install language logger.debug("Selecting stepLanguage page object") welcome_page = self.main_window.select_single( 'GtkBox', name='stepLanguage') treeview = welcome_page.select_single('GtkTreeView') #lets get all items treeview_items = treeview.get_all_items() #first lets check all the items are non-empty unicode strings logger.debug("Checking all tree items are valid unicode") for item in treeview_items: logger.debug("Check tree item with name '%s' is unicode" % item.accessible_name) self.expectIsInstance(item.accessible_name, str, "[Page:'stepLanguage'] Expected '%s' tree " "view item to be unicode but it wasn't" % item.accessible_name) self.expectThat(item.accessible_name, NotEquals(u''), "[Page:'stepLanguage'] Tree item found that " "doesn't contain any text") if lang: if lang == 'English': self.english_install = True item = treeview.select_item(lang) language = item else: language = welcome_page.get_random_language() if language == 'English': self.english_install = True welcome_page.select_language(language) self.assertThat(language.selected, Equals(True)) ##Test release notes label is visible logger.debug("Checking the release_notes_label") self.check_visible_object_with_label('release_notes_label') release_notes_label = welcome_page.select_single( BuilderName='release_notes_label') self.pointing_device.move_to_object(release_notes_label) self._update_page_titles() self._check_page_titles() self._check_navigation_buttons() def preparing_page_tests(self, updates=False, thirdParty=False, networkConnection=True, sufficientSpace=True, powerSource=False): """ Runs the tests for the 'Preparing to install' page :param updates: Boolean, if True selects install updates during install :param thirdParty: Boolean, if True selects install third-party software :param networkConnection: Boolean if True checks the network state box is visible and objects are correct, If false will still check the objects are correct but the state box is not visible :param sufficientSpace: Boolean if True checks the network state box is visible and objects are correct, If false will still check the objects are correct but the state box is not visible :param powerSource: Boolean if True checks the network state box is visible and objects are correct, If false will still check the objects are correct but the state box is not visible """ self._update_current_step('stepPrepare') self._check_navigation_buttons() self._update_page_titles() logger.debug("run_preparing_page_tests()") logger.debug("selecting stepPrepare page") preparing_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPrepare') objList = ['prepare_best_results', 'prepare_foss_disclaimer', 'prepare_download_updates', 'prepare_nonfree_software'] self.check_visible_object_with_label(objList) if updates: logger.debug("Selecting install updates") update_checkbutton = preparing_page.select_single( 'GtkCheckButton', BuilderName='prepare_download_updates') self.pointing_device.click_object(update_checkbutton) if thirdParty: logger.debug("Selecting install thirdparty software") thrdprty_checkbutton = preparing_page.select_single( 'GtkCheckButton', BuilderName='prepare_nonfree_software') self.pointing_device.click_object(thrdprty_checkbutton) self._check_preparing_statebox('prepare_network_connection', visible=networkConnection) #and sufficient space self._check_preparing_statebox('prepare_sufficient_space', visible=sufficientSpace) # and power source self._check_preparing_statebox('prepare_power_source', visible=powerSource) self._check_page_titles() self._check_navigation_buttons() def edubuntu_addon_window_tests(self, unity=False, gnome=False, ltsp=False): """Run Page tests for edubuntu addon page""" self._update_current_step('edubuntu-addon_window') self._check_navigation_buttons() self._update_page_titles() add_on_page = self.main_window.select_single( 'GtkVBox', BuilderName='edubuntu-addon_window') page_objects = ['fallback_install', 'description', 'fallback_title', 'fallback_description', 'ltsp_install', 'ltsp_title', 'ltsp_description', 'ltsp_interface_label'] self.check_visible_object_with_label(page_objects) env = None if unity: logger.debug('Using default Unity env...') pass elif gnome: logger.debug("Using gnome fallback env") env = 'fallback_install' elif ltsp: logger.debug('Using LTSP env') env = 'ltsp_install' else: items = [None, 'fallback_install', 'ltsp_install'] env = random.choice(items) if env: choice = add_on_page.select_single(BuilderName=env) self.pointing_device.click_object(choice) self._check_page_titles() self._check_navigation_buttons() def edubuntu_packages_window_tests(self, ): """Run Page tests for edubuntu packages page""" self._update_current_step('edubuntu-packages_window') self._check_navigation_buttons() self._update_page_titles() self.check_visible_object_with_label('description') self._check_page_titles() self._check_navigation_buttons() def installation_type_page_tests(self, default=False, lvm=False, lvmEncrypt=False, custom=False): """Runs the tests for the installation type page :param default: Boolean if True will use the default selected option for the installation :param lvm: Boolean if True will use the LVM option for the installation :param lvmEncrypt: Boolean if True will use the LVM with encryption option for the installation :param custom: Boolean if True will use the 'Something else' option for the installation """ self._update_current_step('stepPartAsk') self._check_navigation_buttons() self._update_page_titles() option_name = None if default: from ubiquity_autopilot_tests.configs import default_install config = default_install if lvm: from ubiquity_autopilot_tests.configs import lvm_install config = lvm_install option_name = 'use_lvm' if lvmEncrypt: from ubiquity_autopilot_tests.configs import encrypt_lvm_install config = encrypt_lvm_install option_name = 'use_crypto' if custom: from ubiquity_autopilot_tests.configs import custom_install config = custom_install option_name = 'custom_partitioning' self.check_visible_object_with_label(config.visible_options) self.check_hidden_object_with_label(config.hidden_options) install_type_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPartAsk') if option_name: obj = install_type_page.select_single(BuilderName=option_name) self.pointing_device.click_object(obj) self._check_page_titles() self._check_navigation_buttons() def lvm_crypto_page_tests(self, crypto_password): """ Runs the tests for the LVM encryption password page :param crypto_password: *String*, password to be used for the encryption """ self._update_current_step('stepPartCrypto') self._check_navigation_buttons() self._update_page_titles() logger.debug("run_step_part_crypto_page_tests({0})" .format(crypto_password)) logger.debug('Selecting stepPartCrypto page object') crypto_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPartCrypto') items = ['verified_crypto_label', 'crypto_label', 'crypto_description', 'crypto_warning', 'crypto_extra_label', 'crypto_extra_time', 'crypto_description_2', 'crypto_overwrite_space'] self.check_visible_object_with_label(items) crypto_page.enter_crypto_phrase(crypto_password) self._check_page_titles() self._check_navigation_buttons() def custom_partition_page_tests(self, part_config=None): """ Runs the tests for the custom partition page The custom partition configurations are in partconfig.py. This function selects a random Config for each test run from partconfig.py. When adding a new config, import it and add it to the custom_configs list :param part_config: """ part_config = Config1 self._update_current_step('stepPartAdvanced') self._check_navigation_buttons() self._update_page_titles() logger.debug("run_custom_partition_page_tests()") logger.debug("Selecting the stepPartAdvanced page object") custom_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPartAdvanced') treeview = custom_page.select_single('GtkTreeView') self.expectThat(treeview.visible, Equals(True), "[Page:'{0}'] Partition tree view was not visible") obj_list = ['partition_button_new', 'partition_button_delete', 'partition_button_edit', 'partition_button_edit', 'partition_button_new_label'] for name in obj_list: obj = custom_page.select_single(BuilderName=name) self.expectThat(obj.visible, Equals(True), "[Page:'{0}'] {1} object was not visible" .format(self.current_step, obj.name)) logger.debug("Sleeping while we wait for all UI elements to fully " "load") time.sleep(5) # need to give time for all UI elements to load custom_page.create_new_partition_table() #update number of table rows self.part_table_rows = treeview.get_number_of_rows() logger.debug("TOTAL NUMBER OF ROWS: {0}".format(self.part_table_rows)) #lets create the partitions from here if part_config: logger.debug("Setting the given partition config") config = part_config else: logger.debug("Selecting a random partition config") config = random.choice(custom_configs) logger.debug("LENGTH OF CONFIG IS: {0}".format(len(config))) logger.debug( "TOTAL NUMBER OF PARTITIONS IN CONFIG: {0}".format(len(config)) ) self.total_number_partitions = len(config) logger.debug( "TOTAL NUMBER OF PARTITIONS TO BE IN TABLE: {0}".format( self.total_number_partitions) ) for elem in config: self._add_new_partition() partition_dialog = self.main_window.get_dialog( 'GtkDialog', BuilderName='partition_dialog') self.assertThat(partition_dialog.visible, Eventually(Equals(True)), "Partition dialog not visible") partition_dialog.set_partition_size(elem['PartitionSize']) partition_dialog.set_partition_location(elem['Position']) partition_dialog.set_partition_type(elem['PartitionType']) partition_dialog.set_file_system_type(elem['FileSystemType']) partition_dialog.set_mount_point(elem['MountPoint']) ok_button = partition_dialog.select_single( 'GtkButton', BuilderName='partition_dialog_okbutton') self.pointing_device.click_object(ok_button) self.assertThat(partition_dialog.visible, Eventually(Equals(False)), "Partition dialog did not close") self._check_partition_created(elem) # TODO: Uncomment once bug 1066152 is fixed #self._check_page_titles() self._check_navigation_buttons() def location_page_tests(self, ): """ Runs the test for the Location page Due to not being able to introspect the timezone map we only have a choice of 4 locations which get selected at random. """ logger.debug('run_location_page_tests()') self._update_current_step('stepLocation') self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=False, skip_button=False) self._update_page_titles() logger.debug("Selecting stepLocation page object") location_page = self.main_window.select_single( 'GtkBox', BuilderName='stepLocation') location_map = location_page.select_single('CcTimezoneMap') self.assertThat(location_map.visible, Equals(True), "Expected location map to be visible but it wasn't") location_entry = location_page.select_single( BuilderName='timezone_city_entry') self.assertThat(location_entry.visible, Equals(True), "Expected location entry to be visible but it wasn't") location = ['London', 'Paris', 'Madrid', 'Algiers'] if self.english_install: location_page.select_location('London') else: location_page.select_location(random.choice(location)) self._check_page_titles() self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=False, skip_button=False) def keyboard_layout_page_tests(self, ): self._update_current_step('stepKeyboardConf') self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=False, skip_button=False) self._update_page_titles() logger.debug("run_keyboard_layout_page_tests()") logger.debug("Selecting the stepKeyboardCOnf page object") keyboard_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepKeyboardConf') treeviews = keyboard_page.select_many('GtkTreeView') # lets check all the keyboard tree items for the selected language # TODO: we should probably test at some point try changing the keyboard # layout to a different language/locale/layout and see if # ubiquity breaks for treeview in treeviews: items = treeview.get_all_items() for item in items: self.expectIsInstance(item.accessible_name, str, "[Page:'%r'] Expected %r item to be " "unicode but it wasn't" % ( self.current_step, item.accessible_name)) self.expectThat(item.accessible_name, NotEquals(u''), "[Page:'{0}'] Tree view item found which " "didn't contain text, but it should!!") # now lets test typing with the keyboard layout entry = keyboard_page.select_single('GtkEntry') while True: text = u'Testing keyboard layout' with self.keyboard.focused_type(entry) as kb: kb.type(text) #check entry value is same length as text if len(entry.text) == len(text): # only test the entry value if we are using english install if self.english_install: self.expectThat(entry.text, Equals(text)) self.expectThat( entry.text, NotEquals(u''), "[Page:'{0}'] Expected Entry to contain text " "after typing but it didn't" .format(self.current_step)) self.expectIsInstance( entry.text, str, "[Page:'{0}'] Expected Entry text to be " "unicode but it wasnt" .format(self.current_step)) break #delete the entered text before trying again kb.press_and_release('Ctrl+a') kb.press_and_release('Delete') # TODO: Test detecting keyboard layout self._check_page_titles() self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=False, skip_button=False) def user_info_page_tests(self, username, pwd, encrypted=False, autologin=False): """ Runs tests for the User Info Page :param username:*String*, name of user :param pwd: *String*, password for user :param encrypted: *Bool* if true encypts the home directory :param autologin: *Bool* if true sets the user account to login automagically """ self._update_current_step('stepUserInfo') self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=False, skip_button=False) self._update_page_titles() logger.debug("Selecting stepUserInfo page") user_info_page = self.main_window.select_single( 'GtkBox', BuilderName='stepUserInfo') objects = ['hostname_label', 'username_label', 'password_label', 'verified_password_label', 'hostname_extra_label' ] logger.debug("checking user info page objects ......") self.check_visible_object_with_label(objects) user_info_page.create_user(username, pwd) #TODO: get these working if encrypted: user_info_page.encrypt_home_dir(encrypt=True) if autologin: user_info_page.set_auto_login() self._check_page_titles() self._check_navigation_buttons(continue_button=True, back_button=True, quit_button=False, skip_button=False) def progress_page_tests(self, ): ''' Runs the test for the installation progress page This method tracks the current progress of the install by using the fraction property of the progress bar to assertain the percentage complete. ''' #TODO: Remove all these prints once dbus bug is fixed logger.debug("run_install_progress_page_tests()") print("run_install_progress_page_tests()") #We cant assert page title here as its an external html page #Maybe try assert WebKitWebView is visible # # NOTE: disable test to check if webkit view is visible. autopilot # randomly crashes with LP#1284671 and very often in the QA Lab #print("Selecting WebKit") #webkitwindow = self.main_window.select_single( # 'GtkScrolledWindow', name='webkit_scrolled_window' #) #print("Test webkitwindow visible") #self.expectThat(webkitwindow.visible, Equals(True)) #print("Webkit window found and is visible") print("Selecting Progress bar") progress_bar = self.main_window.select_single('GtkProgressBar', name='install_progress') #Copying files progress bar print("Entering first tracking loop all that will be called " "from here is GtkWindow name = liveinstaller and the " "progressbar") self._track_install_progress() print("First loop complete waiting for pbar to go back to 0") self.assertThat(progress_bar.fraction, Eventually( Equals(0.0), timeout=180)) print("Now entering the second loop...........") #And now the install progress bar self._track_install_progress() def check_visible_object_with_label(self, visible_obj): """Check an visible objects label and visible properties, :param visible_obj: Accepts either a objects name property or a list of names ..note:: If english installation this function will also test the english label value which is retrieved from the generated english_config.ini file """ if isinstance(visible_obj, list): for item in visible_obj: self._check_object(item) return if isinstance(visible_obj, str): self._check_object(visible_obj) return raise ValueError( "Object name must either be a string or list of strings") def check_hidden_object_with_label(self, hidden_obj): """Check an hidden objects label and visible properties, :param hidden_obj: Accepts either a objects name property or a list of names """ if isinstance(hidden_obj, list): for item in hidden_obj: self._check_object(item, False) return if isinstance(hidden_obj, str): self._check_object(hidden_obj, False) return raise ValueError( "Object name must either be a string or list of strings") def _check_object(self, obj_name, obj_visible=True): logger.debug("Checking {0} object.......".format(obj_name)) #select current page object page = self.main_window.select_single(BuilderName=self.current_step) #select object page_object = page.select_single(BuilderName=obj_name) if obj_visible: visible_message = "[Page:'{0}'] Expected {1} object to be " \ "visible but it wasn't".format(self.current_step, page_object.name) else: visible_message = "[Page:'{0}'] Expected {1} object to not be " \ "visible but it was!".format(self.current_step, page_object.name) self.expectThat(page_object.visible, Equals(obj_visible), visible_message) self.expectThat(page_object.label, NotEquals(u''), "[Page:'{0}'] Expected {1} objects label value to " "contain text but it didn't" .format(self.current_step, page_object.name)) self.expectIsInstance(page_object.label, str, "[Page:'{0}'] Expected {1} objects label " "value to be unicode but it wasn't" .format(self.current_step, page_object.name)) #we only want to test visible english values, hidden ones don't matter if (self.current_step in self.english_config) and obj_visible: if self.english_install and ( obj_name in self.english_config[self.current_step]): logger.debug( "Checking {0} object's english label value....".format( obj_name)) #if english install check english values self.expectThat(page_object.label, Equals( self.english_config[self.current_step][obj_name])) def _track_install_progress(self, ): '''Gets the value of the fraction property of the progress bar so we can see when the progress bar is complete ''' logger.debug("_track_install_progress_bar()") print("_track_install_progress()") print("selecting progress bar") progress_bar = self.main_window.select_single('GtkProgressBar', name='install_progress') progress = 0.0 while progress < 1.0: #print("Progressbar = %d" % progress) #keep updating fraction value #print("Getting an updated pbar.fraction") progress = progress_bar.fraction #print("Got an updated pbar fraction") # lets sleep for longer at early stages then # reduce nearer to complete if progress < 0.5: time.sleep(5) elif progress < 0.7: time.sleep(3) elif progress < 0.85: time.sleep(1) else: pass #logger.debug('Percentage complete "{0:.0f}%"' # .format(progress * 100)) def _check_no_visible_dialogs(self, arg=None): # lets try grab some dialogs we know of dialogs = ['warning_dialog', 'crash_dialog', 'bootloader_fail_dialog', 'ubi_question_dialog'] safe_dialogs = ['finished_dialog', 'partition_dialog'] for dialog_name in dialogs: dialog = self.app.select_single(BuilderName=dialog_name) if dialog.visible: msg = self._get_dialog_message(dialog) # each dialog will display a label explaining the error self.expectNotVisible(dialog.visible, "{0} was found to be visible. " "With error message: \n" "{1}" .format(dialog.name, msg)) # Try grab dialogs created at runtime unknown_dialogs = self.app.select_many('GtkDialog') for dlg in unknown_dialogs: if dlg.name in dialogs or safe_dialogs: pass else: if dlg.visible: msg = self._get_dialog_message(dlg) # each dialog will display a label explaining the error self.expectNotVisible(dlg.visible, "Error dialog found to be visible " "With error message: \n" "{0}" .format(msg)) # Lets try and grab any spawned GtkMessageDialogs try: unknown_msg_dialogs = self.app.select_many('GtkMessageDialog') for dlg in unknown_msg_dialogs: msg = self._get_dialog_message(dlg) # each dialog will display a label explaining the error self.expectNotVisible(dlg.visible, "A GtkMessageDialog was found to be " "visible. With error message: \n" "{0}" .format(msg)) except StateNotFoundError: # catch statenotfound so we can continue pass def _get_dialog_message(self, dlg_object): dialog_labels = dlg_object.select_many('GtkLabel') message = '' for gtklabel in dialog_labels: #only add labels longer than 'Continue' so we avoid button labels if len(gtklabel.label) > 8: message += (gtklabel.label + '. ') return message def _add_new_partition(self, ): """ adds a new partition """ logger.debug("_add_new_partition()") custom_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPartAdvanced') tree_view = custom_page.select_single('GtkTreeView') item = tree_view.select_item(u' free space') self.pointing_device.click_object(item) self.assertThat(item.selected, Equals(True), "[Page:'{0}'] Free Space tree item not selected" .format(self.current_step)) add_button = custom_page.select_single( 'GtkToolButton', BuilderName='partition_button_new') self.pointing_device.click_object(add_button) time.sleep(2) logger.debug('_add_new_partition complete') def _check_partition_created(self, config): """ Checks that the partition was created properly """ logger.debug("Checking partition was created.....") custom_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPartAdvanced') tree_view = custom_page.select_single('GtkTreeView') #assert a new row has been added to the partition table total_rows = self._update_table_row_count(config) logger.debug("TOTAL NUMBER OF ROWS: {0}".format(self.part_table_rows)) self.assertThat(total_rows, Equals(self.part_table_rows)) items = tree_view.get_all_items() fsFormat = config['FileSystemType'] mount_point = config['MountPoint'] size_obj = config['PartitionSize'] if mount_point: index = next((index for index, value in enumerate(items) if mount_point == value.accessible_name), None) self.assertIsNotNone(index, "Could not get index for '{0}' tree item" .format(mount_point)) logger.debug("Found index for {0} tree item".format(mount_point)) fs_item = tree_view.select_item_by_index(index - 1) mount_item = tree_view.select_item_by_index(index) size_item = tree_view.select_item_by_index(index + 1) else: index = next((index for index, value in enumerate(items) if fsFormat.lower() == value.accessible_name), None) self.assertIsNotNone(index, "Could not get index for {0} FS tree item" .format(fsFormat)) logger.debug("Found index for {0} tree item".format(fsFormat)) fs_item = tree_view.select_item_by_index(index) mount_item = tree_view.select_item_by_index(index + 1) size_item = tree_view.select_item_by_index(index + 2) self.expectThat(fsFormat.lower(), Equals(fs_item.accessible_name)) self.expectThat(fs_item.visible, Equals(True), "[Page: '{0}'] Expected {0} to be visible but " "it wasn't".format(fs_item.accessible_name)) if mount_point: # Fail the test if we don't have correct mount point self.assertThat(mount_point, Equals(mount_item.accessible_name)) self.expectThat(mount_item.visible, Equals(True), "[Page: '{0}'] Expected {0} to be visible but " "it wasn't".format(mount_item.accessible_name)) if size_obj: self.expectThat( int(size_item.accessible_name.strip(' MB')), InRange((size_obj - 3), (size_obj + 3)), "[Page:'{0}'] Expected partition size to be " "somwhere in the range of {1}-{2}MB but instead was {3}. " "This means the created partition was significantly " "different in size to the requested amount of {4}MB" .format(self.current_step, str(size_obj - 3), str(size_obj + 3), size_item.accessible_name, str(size_obj))) self.expectThat(size_item.visible, Equals(True), "[Page: '{0}'] Expected {0} to be visible but " " it wasn't".format(size_item.accessible_name)) logger.debug("Partition created") def _check_navigation_buttons(self, continue_button=True, back_button=True, quit_button=True, skip_button=False): """ Function that checks the navigation buttons through out the install :param continue_button: Boolean value of buttons expected visibility :param back_button: Boolean value of buttons expected visibility :param quit_button: Boolean value of buttons expected visibility :param skip_button: Boolean value of buttons expected visibility """ logger.debug("check_window_constants({0}, {1}, {2}, {3})".format( continue_button, back_button, quit_button, skip_button)) con_button = self.main_window.select_single('GtkButton', name='next') self.assertThat(con_button.visible, Equals(continue_button)) bk_button = self.main_window.select_single('GtkButton', name='back') self.assertThat(bk_button.visible, Equals(back_button)) qt_button = self.main_window.select_single('GtkButton', name='quit') self.assertThat(qt_button.visible, Equals(quit_button)) skp_button = self.main_window.select_single('GtkButton', name='skip') self.assertThat(skp_button.visible, Equals(skip_button)) def _update_current_step(self, name): logger.debug("Updating current step to %s" % name) self.step_before = self.current_step self.current_step = name # Lets print current step print("Current step = {0}".format(self.current_step)) def _update_table_row_count(self, config): " Returns number of rows in table" custom_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPartAdvanced') tree_view = custom_page.select_single('GtkTreeView') num = tree_view.get_number_of_rows() if num == self.total_number_partitions: #TODO: assert 'free space' changes to a partition # this will take some further work. time.sleep(15) return num if num == self.part_table_rows: timeout = 30 while True: if num is not self.part_table_rows + 1: time.sleep(1) num = tree_view.get_number_of_rows() if num is self.part_table_rows + 1: break elif not timeout: raise ValueError("No new rows in partition table") else: timeout -= 1 self.assertThat(num, Equals(self.part_table_rows + 1)) self.part_table_rows = num return num def _update_page_titles(self, ): self.previous_page_title = self.current_page_title self.current_page_title = self.main_window.select_single( 'GtkLabel', BuilderName='page_title').label def _check_page_titles(self, ): current_page_title = self.main_window.select_single( 'GtkLabel', BuilderName='page_title') if self.current_step in self.english_config: if self.english_install and ( 'page_title' in self.english_config[self.current_step]): #if english install check english values self.expectThat(current_page_title.label, Equals( self.english_config[self.current_step]['page_title'])) #also lets check it changed from the previous page message_one = "Expected %s page title '%s' to not equal the "\ "previous %s page title '%s' but it does" % ( self.current_step, self.current_page_title, self.step_before, self.previous_page_title) self.expectThat(self.previous_page_title, NotEquals(self.current_page_title), message=message_one) ## XXX Re-enable to catch bugs where page title changes after a page ## has loaded # ## This second one catches the known bug for the stepPartAdvanced page ## title switching back to the prev page title #message_two = "Expected %s page title '%s' to not equal the "\ # "previous %s page title '%s' but it does" % ( # self.current_step, current_page_title.label, # self.step_before, self.previous_page_title) ## This only runs if the current page title changes from its initial ## value when page loaded #if current_page_title.label != self.current_page_title: # self.expectThat(self.previous_page_title, # NotEquals(current_page_title.label), # message=message_two) # self.expectThat(current_page_title.visible, Equals(True), # "[Page:'{0}'] Expect page title to be visible " # "but it wasn't".format(self.current_step)) def _check_preparing_statebox(self, stateboxName, visible=True, imagestock='gtk-yes'): """ Checks the preparing page statebox's """ logger.debug("Running checks on {0} StateBox".format(stateboxName)) preparing_page = self.main_window.select_single( 'GtkAlignment', BuilderName='stepPrepare') state_box = preparing_page.select_single( 'StateBox', BuilderName=stateboxName) logger.debug('check({0}, {1})'.format(visible, imagestock)) logger.debug("Running checks.......") if visible: self.expectThat(state_box.visible, Equals(visible), "StateBox.check(): Expected {0} statebox to be " "visible but it wasn't" .format(state_box.name)) label = state_box.select_single('GtkLabel') self.expectThat(label.label, NotEquals(u''), "[Page:'{0}'] Expected {1} Statebox's label to " "contain text but it didn't" .format(self.current_step, stateboxName)) self.expectThat(label.visible, Equals(visible), "[Page:'{0}'] Expected {1} Statebox label's " "visible property to be {2} " .format(self.current_step, stateboxName, str(visible))) self.expectIsInstance(label.label, str, "[Page:'{0}'] Expected {1} Statebox's label " "to be unicode but it wasn't" .format(self.current_step, stateboxName)) image = state_box.select_single('GtkImage') self.expectThat(image.stock, Equals(imagestock)) self.expectThat(image.visible, Equals(visible)) else: self.expectThat(state_box.visible, Equals(False), "[Page:'{0}'] Expected {1} statebox to not be " "visible but it was" .format(self.current_step, stateboxName)) def get_distribution(self, ): """Returns the name of the running distribution.""" logger.debug("Detecting flavor") with open('/cdrom/.disk/info') as f: for line in f: distro = line[:max(line.find(' '), 0) or None] if distro: logger.debug("{0} flavor detected".format(distro)) return str(distro) raise SystemError("Could not get distro name")
class GtkBox(GtkContainers): """ Emulator class for a GtkBox instance """ def __init__(self, *args): super(GtkBox, self).__init__(*args) self.pointing_device = Pointer(Mouse.create()) self.kbd = Keyboard.create() def get_random_language(self, ): """ gets a random language from the 'stepLanguage' page :returns: A random TreeView item from the language treeview :raises: EmulatorException if function is not called from the step language page object You can now use select_language_item """ logger.debug("get_random_language()") if self.name == 'stepLanguage': language_item = self._get_install_language() if language_item is None: raise ValueError("Language could not be selected") return language_item raise RuntimeError("Function can only be used from a stepLanguage " "page object. Use .select_single('GtkBox, " "name='stepLanguage')") def select_language(self, item): """ Selects a language for the install You can either use get_random_language or if you want to set the install language instead of randomly selecting an item. Then select from the treeview using GtkTreeView.select_item and pass the returned item to select_language :param item: A treeview item object :raises: exception if function not called from stepLanguage page object """ if self.name == 'stepLanguage': logger.debug("select_language()") treeview = self.select_single('GtkTreeView') treeview.click() #for sanity lets ensure we always start at the top of the list logger.debug("Selecting top item of treeview list") self.kbd.press_and_release('Home') tree_items = treeview.get_all_items() top_item = tree_items[0] #If we are at the top if top_item.selected: logger.debug("top item {0} selected" .format(top_item.accessible_name)) #Now select required Language self.kbd.type(item.accessible_name[0:2]) item.click() #check selected if item.selected: logger.debug("Install language successfully selected! :-)") return raise ValueError("Could not select Item") raise ValueError("Top item not selected") raise ValueError("Function can only be used from a stepLanguage page " "object. Use .select_single('GtkBox, " "name='stepLanguage')") def _get_install_language(self, ): """ Gets a random language for the install :returns: an object of a TreeView item for the chosen language """ logger.debug("_get_install_language()") treeview = self.select_single('GtkTreeView') #lets get all items treeview_items = treeview.get_all_items() #get a language which the first two chars can be ascii decoded test_language = self._get_decode_ascii_item(treeview_items) return test_language def _get_decode_ascii_item(self, items): """ decodes a list of unicode items """ logger.debug("_get_decode_ascii_item()") # at the moment we can't select all locales as this would be a pain # to figure out all encodings for keyboard input lang_item = None l_ascii = None while True: lang_item = random.choice(items) l_unicode = lang_item.accessible_name logger.debug("Attempting to decode %s" % l_unicode) lan = l_unicode[0:2] try: l_ascii = lan.encode('ascii') except UnicodeEncodeError: logger.debug("%s could not be decoded" % l_unicode) pass if l_ascii: logger.debug("%s decoded successfully" % l_unicode) break logger.debug("Returning selected language: %s" % l_unicode) return lang_item def select_location(self, location): """ Selects a location on the timezone map """ if self.name == 'stepLocation': logger.debug("select_location({0})".format(location)) location_map = self.select_single('CcTimezoneMap') self.pointing_device.move_to_object(location_map) x1, y1, x2, y2 = location_map.globalRect #hmmmm this is tricky! and really hacky pos = self.pointing_device.position() x = pos[0] y = pos[1] x -= 25 # px self.pointing_device.move(x, y) while True: entry = self.select_single('GtkEntry') if entry.text != location: pos = self.pointing_device.position() x = pos[0] y = pos[1] y -= 10 # px self.pointing_device.move(x, y) self.pointing_device.click() if y < y1: logger.warning("We missed the location on the map and " "ended up outside the globalRect. Now " "using the default selected location " "instead") break else: expectThat(entry.text).equals(location) logger.debug("Location; '{0}' selected".format(location)) break else: raise ValueError("Function can only be called from a " "stepLocation page object") def create_user(self, name, password): """ Creates a user account with password :param name: Username :param password: user password """ logger.debug("create_user({0}, {1})".format(name, password)) if self.name == 'stepUserInfo': self._enter_username(name) self._enter_password(password) else: raise ValueError("Function can only be called froma stepUserInfo" "page object") def _enter_username(self, name): """ Enters the username :param name: username for user account """ logger.debug("_enter_username({0})".format(name)) entry = self.select_single('GtkEntry', name='fullname') with self.kbd.focused_type(entry) as kb: kb.press_and_release('Ctrl+a') kb.press_and_release('Delete') kb.type(name) #lets get the fullname from the entry # as we don't know the kb layout till runtime fullname = entry.text logger.debug("Checking that name, username and hostname all contain " "'{0}'".format(name)) #now check computer name contains username hostname_entry = self.select_single('GtkEntry', name='hostname') expectThat(hostname_entry.text).contains( fullname.lower(), msg="GtkBox._enter_username(): Expected the hostname entry: " "'{0}', to contain '{1}'" .format(hostname_entry.text, fullname.lower())) #check username contains name username_entry = self.select_single('GtkEntry', name='username') expectThat(username_entry.text).contains( fullname.lower(), msg="GtkBox._enter_username(): Expected the username entry: " "'{0}', to contain '{1}'" .format(username_entry.text, fullname.lower())) #check the GtkYes images are now visible logger.debug("Checking the stock 'gtk-yes' images are visible") images = ['fullname_ok', 'hostname_ok', 'username_ok'] for image in images: img = self.select_single('GtkImage', name=image) expectThat(img.visible).equals( True, msg="Expected {0} image to be visible but it wasn't" .format(img.name)) expectThat(img.stock).equals( 'gtk-yes', msg="Expected {0} image to have a 'gtk-yes' stock image and " "not {1}".format(img.name, img.stock)) def _enter_password(self, password): if self.name == 'stepUserInfo': while True: self._enter_pass_phrase(password) match = self._check_phrase_match() if match: break else: raise ValueError("enter_crypto_phrase() can only be called from " "stepPartCrypto page object") def _enter_pass_phrase(self, phrase): pwd_entries = ['password', 'verified_password'] for i in pwd_entries: entry = self.select_single(BuilderName=i) with self.kbd.focused_type(entry) as kb: kb.press_and_release('Ctrl+a') kb.press_and_release('Delete') expectThat(entry.text).equals( u'', msg='{0} entry text was not cleared properly' .format(entry.name)) kb.type(phrase) def _check_phrase_match(self, ): pwd1 = self.select_single(BuilderName='password').text pwd2 = self.select_single(BuilderName='verified_password').text if pwd1 == pwd2: return True else: return False def encrypt_home_dir(self, encrypt=None): """ Check the login_encrypt box """ chk_encrypt = self.select_single(BuilderName='login_encrypt') active = chk_encrypt.active if encrypt is None: # Switch checkbox and ensure it switched self.pointing_device.click_object(chk_encrypt) expectThat(chk_encrypt.active).equals( not active, msg='encrypt home checkbox state did not change. Current ' 'state: {0}'.format(chk_encrypt.active)) elif encrypt and not active: self.pointing_device.click_object(chk_encrypt) expectThat(chk_encrypt.active).equals( True, msg='encrypt home checkbox not active and should be.') elif not encrypt and active: self.pointing_device.click_object(chk_encrypt) expectThat(chk_encrypt.active).equals( False, msg='encrypt home checkbox active and should not be.') else: raise ValueError("Invalid value for 'encrypt' parameter: {}" .format(encrypt))
class UbuntuTouchAppTestCase(AutopilotTestCase): """A common test case class that provides several useful methods for the tests.""" if model() == 'Desktop': scenarios = [ ('with mouse', dict(input_device_class=Mouse)) ] else: scenarios = [ ('with touch', dict(input_device_class=Touch)) ] @property def main_window(self): return MainWindow(self.app) def setUp(self): self.pointing_device = Pointer(self.input_device_class.create()) super(UbuntuTouchAppTestCase, self).setUp() self.launch_test_qml() def launch_test_qml(self): # If the test class has defined a 'test_qml' class attribute then we # write it to disk and launch it inside the QML Scene. If not, then we # silently do nothing (presumably the test has something else planned). arch = subprocess.check_output(["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip() if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring): qml_path = mktemp(suffix='.qml') open(qml_path, 'w').write(self.test_qml) self.addCleanup(remove, qml_path) self.app = self.launch_test_application( "/usr/lib/" + arch + "/qt5/bin/qmlscene", "-I", get_module_include_path(), qml_path, app_type='qt') if hasattr(self, 'test_qml_file') and isinstance(self.test_qml_file, basestring): qml_path = self.test_qml_file self.app = self.launch_test_application( "/usr/lib/" + arch + "/qt5/bin/qmlscene", "-I", get_module_include_path(), qml_path, app_type='qt') self.assertThat(self.get_qml_view().visible, Eventually(Equals(True))) def get_qml_view(self): """Get the main QML view""" return self.app.select_single("QQuickView") def get_mainview(self): """Get the QML MainView""" mainView = self.app.select_single("MainView") self.assertThat(mainView, Not(Is(None))) return mainView def get_object(self,objectName): """Get a object based on the objectName""" obj = self.app.select_single(objectName=objectName) self.assertThat(obj, Not(Is(None))) return obj def mouse_click(self,objectName): """Move mouse on top of the object and click on it""" obj = self.get_object(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.click() def mouse_press(self,objectName): """Move mouse on top of the object and press mouse button (without releasing it)""" obj = self.get_object(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.press() def mouse_release(self): """Release mouse button""" self.pointing_device.release() def type_string(self, string): """Type a string with keyboard""" self.keyboard.type(string) def type_key(self, key): """Type a single key with keyboard""" self.keyboard.key(key)
class UbuntuTouchAppTestCase(AutopilotTestCase): """A common test case class that provides several useful methods for the tests.""" if model() == 'Desktop': scenarios = [('with mouse', dict(input_device_class=Mouse))] else: scenarios = [('with touch', dict(input_device_class=Touch))] @property def main_window(self): return MainWindow(self.app) def setUp(self): self.pointing_device = Pointer(self.input_device_class.create()) super(UbuntuTouchAppTestCase, self).setUp() self.launch_test_qml() def launch_test_qml(self): # If the test class has defined a 'test_qml' class attribute then we # write it to disk and launch it inside the QML Scene. If not, then we # silently do nothing (presumably the test has something else planned). arch = subprocess.check_output( ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip() if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring): qml_path = mktemp(suffix='.qml') open(qml_path, 'w').write(self.test_qml) self.addCleanup(remove, qml_path) self.app = self.launch_test_application("/usr/lib/" + arch + "/qt5/bin/qmlscene", "-I", get_module_include_path(), qml_path, app_type='qt') if hasattr(self, 'test_qml_file') and isinstance( self.test_qml_file, basestring): qml_path = self.test_qml_file self.app = self.launch_test_application("/usr/lib/" + arch + "/qt5/bin/qmlscene", "-I", get_module_include_path(), qml_path, app_type='qt') self.assertThat(self.get_qml_view().visible, Eventually(Equals(True))) def get_qml_view(self): """Get the main QML view""" return self.app.select_single("QQuickView") def get_mainview(self): """Get the QML MainView""" mainView = self.app.select_single("MainView") self.assertThat(mainView, Not(Is(None))) return mainView def get_object(self, objectName): """Get a object based on the objectName""" obj = self.app.select_single(objectName=objectName) self.assertThat(obj, Not(Is(None))) return obj def mouse_click(self, objectName): """Move mouse on top of the object and click on it""" obj = self.get_object(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.click() def mouse_press(self, objectName): """Move mouse on top of the object and press mouse button (without releasing it)""" obj = self.get_object(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.press() def mouse_release(self): """Release mouse button""" self.pointing_device.release() def type_string(self, string): """Type a string with keyboard""" self.keyboard.type(string) def type_key(self, key): """Type a single key with keyboard""" self.keyboard.key(key)
class GtkBox(GtkContainers): """ Emulator class for a GtkBox instance """ def __init__(self, *args): super(GtkBox, self).__init__(*args) self.pointing_device = Pointer(Mouse.create()) self.kbd = Keyboard.create() def get_random_language(self, ): """ gets a random language from the 'stepLanguage' page :returns: A random TreeView item from the language treeview :raises: EmulatorException if function is not called from the step language page object You can now use select_language_item """ logger.debug("get_random_language()") if self.name == 'stepLanguage': language_item = self._get_install_language() if language_item is None: raise ValueError("Language could not be selected") return language_item raise RuntimeError("Function can only be used from a stepLanguage " "page object. Use .select_single('GtkBox, " "name='stepLanguage')") def select_language(self, item): """ Selects a language for the install You can either use get_random_language or if you want to set the install language instead of randomly selecting an item. Then select from the treeview using GtkTreeView.select_item and pass the returned item to select_language :param item: A treeview item object :raises: exception if function not called from stepLanguage page object """ if self.name == 'stepLanguage': logger.debug("select_language()") treeview = self.select_single('GtkTreeView') treeview.click() # for sanity lets ensure we always start at the top of the list logger.debug("Selecting top item of treeview list") self.kbd.press_and_release('Home') tree_items = treeview.get_all_items() top_item = tree_items[0] # If we are at the top if top_item.selected: logger.debug("top item {0} selected".format( top_item.accessible_name)) # Now select required Language self.kbd.type(item.accessible_name[0:2]) item.click() # check selected if item.selected: logger.debug("Install language successfully selected! :-)") return raise ValueError("Could not select Item") raise ValueError("Top item not selected") raise ValueError("Function can only be used from a stepLanguage page " "object. Use .select_single('GtkBox, " "name='stepLanguage')") def _get_install_language(self, ): """ Gets a random language for the install :returns: an object of a TreeView item for the chosen language """ logger.debug("_get_install_language()") treeview = self.select_single('GtkTreeView') # lets get all items treeview_items = treeview.get_all_items() # get a language which the first two chars can be ascii decoded test_language = self._get_decode_ascii_item(treeview_items) return test_language def _get_decode_ascii_item(self, items): """ decodes a list of unicode items """ logger.debug("_get_decode_ascii_item()") # at the moment we can't select all locales as this would be a pain # to figure out all encodings for keyboard input lang_item = None l_ascii = None while True: lang_item = random.choice(items) l_unicode = lang_item.accessible_name logger.debug("Attempting to decode %s" % l_unicode) lan = l_unicode[0:2] try: l_ascii = lan.encode('ascii') except UnicodeEncodeError: logger.debug("%s could not be decoded" % l_unicode) pass if l_ascii: logger.debug("%s decoded successfully" % l_unicode) break logger.debug("Returning selected language: %s" % l_unicode) return lang_item def select_location(self, location): """ Selects a location on the timezone map """ if self.name == 'stepLocation': logger.debug("select_location({0})".format(location)) location_map = self.select_single('CcTimezoneMap') self.pointing_device.move_to_object(location_map) x1, y1, x2, y2 = location_map.globalRect # hmmmm this is tricky! and really hacky pos = self.pointing_device.position() x = pos[0] y = pos[1] x -= 25 # px self.pointing_device.move(x, y) while True: entry = self.select_single('GtkEntry') if entry.text != location: pos = self.pointing_device.position() x = pos[0] y = pos[1] y -= 10 # px self.pointing_device.move(x, y) self.pointing_device.click() if y < y1: logger.warning("We missed the location on the map and " "ended up outside the globalRect. Now " "using the default selected location " "instead") break else: expectThat(entry.text).equals(location) logger.debug("Location; '{0}' selected".format(location)) break else: raise ValueError("Function can only be called from a " "stepLocation page object") def create_user(self, name, password): """ Creates a user account with password :param name: Username :param password: user password """ logger.debug("create_user({0}, {1})".format(name, password)) if self.name == 'stepUserInfo': self._enter_username(name) self._enter_password(password) else: raise ValueError("Function can only be called froma stepUserInfo" "page object") def _enter_username(self, name): """ Enters the username :param name: username for user account """ logger.debug("_enter_username({0})".format(name)) entry = self.select_single('GtkEntry', name='fullname') with self.kbd.focused_type(entry) as kb: kb.press_and_release('Ctrl+a') kb.press_and_release('Delete') kb.type(name) # lets get the fullname from the entry # as we don't know the kb layout till runtime fullname = entry.text logger.debug("Checking that name, username and hostname all contain " "'{0}'".format(name)) # now check computer name contains username hostname_entry = self.select_single('GtkEntry', name='hostname') expectThat(hostname_entry.text).contains( fullname.lower(), msg="GtkBox._enter_username(): Expected the hostname entry: " "'{0}', to contain '{1}'".format(hostname_entry.text, fullname.lower())) # check username contains name username_entry = self.select_single('GtkEntry', name='username') expectThat(username_entry.text).contains( fullname.lower(), msg="GtkBox._enter_username(): Expected the username entry: " "'{0}', to contain '{1}'".format(username_entry.text, fullname.lower())) # check the GtkYes images are now visible logger.debug("Checking the stock 'gtk-yes' images are visible") images = ['fullname_ok', 'hostname_ok', 'username_ok'] for image in images: img = self.select_single('GtkImage', name=image) expectThat(img.visible).equals( True, msg="Expected {0} image to be visible but it wasn't".format( img.name)) expectThat(img.stock).equals( 'gtk-yes', msg="Expected {0} image to have a 'gtk-yes' stock image and " "not {1}".format(img.name, img.stock)) def _enter_password(self, password): if self.name == 'stepUserInfo': while True: self._enter_pass_phrase(password) match = self._check_phrase_match() if match: break else: raise ValueError("enter_crypto_phrase() can only be called from " "stepPartCrypto page object") def _enter_pass_phrase(self, phrase): pwd_entries = ['password', 'verified_password'] for i in pwd_entries: entry = self.select_single(BuilderName=i) with self.kbd.focused_type(entry) as kb: kb.press_and_release('Ctrl+a') kb.press_and_release('Delete') expectThat(entry.text).equals( u'', msg='{0} entry text was not cleared properly'.format( entry.name)) kb.type(phrase) def _check_phrase_match(self, ): pwd1 = self.select_single(BuilderName='password').text pwd2 = self.select_single(BuilderName='verified_password').text if pwd1 == pwd2: return True else: return False def encrypt_home_dir(self, encrypt=None): """ Check the login_encrypt box """ chk_encrypt = self.select_single(BuilderName='login_encrypt') active = chk_encrypt.active if encrypt is None: # Switch checkbox and ensure it switched self.pointing_device.click_object(chk_encrypt) expectThat(chk_encrypt.active).equals( not active, msg='encrypt home checkbox state did not change. Current ' 'state: {0}'.format(chk_encrypt.active)) elif encrypt and not active: self.pointing_device.click_object(chk_encrypt) expectThat(chk_encrypt.active).equals( True, msg='encrypt home checkbox not active and should be.') elif not encrypt and active: self.pointing_device.click_object(chk_encrypt) expectThat(chk_encrypt.active).equals( False, msg='encrypt home checkbox active and should not be.') else: raise ValueError( "Invalid value for 'encrypt' parameter: {}".format(encrypt))
class UbuntuHTML5TestCaseBase(AutopilotTestCase): BROWSER_CONTAINER_PATH = "%s/%s" % (os.path.dirname( os.path.realpath(__file__)), '../../tools/qml/webview.qml') INSTALLED_BROWSER_CONTAINER_PATH = '/usr/share/ubuntu-html5-theme/autopilot-tests/qml/webview.qml' arch = subprocess.check_output( ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip() BROWSER_QML_APP_LAUNCHER = "/usr/lib/" + arch + "/qt5/bin/qmlscene" # TODO: fix version LOCAL_HTML_EXAMPLES_PATH = os.path.abspath("%s/%s" % (os.path.dirname( os.path.realpath(__file__)), '../../../../0.1/examples/')) INSTALLED_HTML_EXAMPLES_PATH = '/usr/share/ubuntu-html5-theme/0.1/examples' APPS_SUBFOLDER_NAME = 'apps' BASE_PATH = '' def get_browser_container_path(self): if os.path.exists(self.BROWSER_CONTAINER_PATH): return self.BROWSER_CONTAINER_PATH return self.INSTALLED_BROWSER_CONTAINER_PATH def create_file_url_from(self, filepath): return 'file://' + filepath def setup_base_path(self): if os.path.exists(self.LOCAL_HTML_EXAMPLES_PATH): self.BASE_PATH = self.LOCAL_HTML_EXAMPLES_PATH else: self.BASE_PATH = self.INSTALLED_HTML_EXAMPLES_PATH def setUp(self): self.setup_base_path() self.pointer = Pointer(Mouse.create()) self.app = self.launch_test_application( self.BROWSER_QML_APP_LAUNCHER, self.get_browser_container_path()) self.webviewContainer = self.get_webviewContainer() self.watcher = self.webviewContainer.watch_signal( 'resultUpdated(QString)') super(UbuntuHTML5TestCaseBase, self).setUp() def tearDown(self): super(UbuntuHTML5TestCaseBase, self).tearDown() def pick_app_launcher(self, app_path): # force Qt app introspection: from autopilot.introspection.qt import QtApplicationLauncher return QtApplicationLauncher() def get_webviewContainer(self): return self.app.select_single(objectName="webviewContainer") def get_webview(self): return self.app.select_single(objectName="webview") def get_addressbar(self): return self.app.select_single(objectName="addressbar") def get_button(self): return self.app.select_single(objectName="browseButton") def get_title(self): return self.get_webview().title def assert_url_eventually_loaded(self, url): webview = self.get_webview() self.assertThat(webview.loadProgress, Eventually(Equals(100))) self.assertThat(webview.loading, Eventually(Equals(False))) self.assertThat(webview.url, Eventually(Equals(url))) def click_dom_node_with_id(self, id): webview = self.get_webviewContainer() webview.slots.clickElementById(id) self.assertThat(lambda: self.watcher.num_emissions, Eventually(Equals(1))) def click_any_dom_node_by_selector(self, selector): webview = self.get_webviewContainer() webview.slots.clickAnyElementBySelector(selector) self.assertThat(lambda: self.watcher.num_emissions, Eventually(Equals(1))) def is_dom_node_visible(self, id): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.isNodeWithIdVisible(id) self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads( webview.get_signal_emissions('resultUpdated(QString)')[-1] [0])['result'] def eval_expression_in_page_unsafe(self, expr): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.evalInPageUnsafe(expr) self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads( webview.get_signal_emissions('resultUpdated(QString)')[-1] [0])['result'] def get_dom_node_id_attribute(self, id, attribute): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.getAttributeForElementWithId(id, attribute) self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads( webview.get_signal_emissions('resultUpdated(QString)')[-1] [0])['result'] def browse_to_url(self, url): addressbar = self.get_addressbar() self.pointer.move_to_object(addressbar) self.pointer.click() self.keyboard.type(url, 0.001) button = self.get_button() self.pointer.move_to_object(button) self.pointer.click() self.assert_url_eventually_loaded(url) def browse_to_app(self, appname): APP_HTML_PATH = self.create_file_url_from( os.path.abspath(self.BASE_PATH + '/../../tests/data/html/' + self.APPS_SUBFOLDER_NAME + '/' + appname + '/index.html')) self.browse_to_url(APP_HTML_PATH) def browse_to_test_html(self, html_filename): self.browse_to_url( self.create_file_url_from( os.path.abspath(self.BASE_PATH + '/../../tests/data/html/' + html_filename)))
class QMLFileAppTestCase(base.UbuntuUIToolkitAppTestCase): """Base test case for self tests that launch a QML file.""" test_qml_file_path = '/path/to/file.qml' desktop_file_path = None def setUp(self): super().setUp() self.pointing_device = Pointer(self.input_device_class.create()) self.launch_application() def get_command_line(self, command_line): return command_line def launch_application(self): desktop_file_path = self._get_desktop_file_path() command_line = [ base.get_toolkit_launcher_command(), "-I", _get_module_include_path(), self.test_qml_file_path, '--desktop_file_hint={0}'.format(desktop_file_path) ] self.app = self.launch_test_application( *self.get_command_line(command_line), emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase, app_type='qt') self.assertThat(self.main_view.visible, Eventually(Equals(True))) def _get_desktop_file_path(self): if self.desktop_file_path is None: desktop_file_path = _write_test_desktop_file() self.addCleanup(os.remove, desktop_file_path) return desktop_file_path else: self.desktop_file_path @property def main_view(self): """ Return the MainView of the app, selected by objectName. QML code used for testing must define the objectName of the MainView to be 'mainView'. """ return self.app.select_single(objectName='mainView') def getOrientationHelper(self): orientationHelper = self.main_view.select_many("OrientationHelper")[0] self.assertThat(orientationHelper, Not(Is(None))) return orientationHelper def checkPageHeader(self, pageTitle): header_label = self.main_view.wait_select_single( objectName="header_title_label", text=pageTitle, visible=True) self.assertThat(header_label, Not(Is(None))) self.assertThat(header_label.visible, Eventually(Equals(True))) def getObject(self, objectName): obj = self.app.select_single(objectName=objectName) self.assertThat(obj, Not(Is(None))) return obj def tap(self, objectName): obj = self.getObject(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.click()
class UbuntuHTML5TestCaseBase(AutopilotTestCase): BROWSER_CONTAINER_PATH = "{}/{}".format( os.path.dirname(os.path.realpath(__file__)), '../../tools/qml/webview.qml') INSTALLED_BROWSER_CONTAINER_PATH = \ '/usr/share/ubuntu-html5-ui-toolkit/tests/tools/qml/webview.qml' BROWSER_QML_APP_LAUNCHER = "/usr/lib/{}/qt5/bin/qmlscene".format( subprocess.check_output( ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip().decode('utf-8')) # TODO: fix version LOCAL_HTML_EXAMPLES_PATH = os.path.abspath( "{}/{}".format( os.path.dirname(os.path.realpath(__file__)), '../../../../tests')) INSTALLED_HTML_EXAMPLES_PATH = \ '/usr/share/ubuntu-html5-ui-toolkit/tests/' APPS_SUBFOLDER_NAME = 'apps' BASE_PATH = '' def get_browser_container_path(self): if os.path.exists(self.BROWSER_CONTAINER_PATH): return self.BROWSER_CONTAINER_PATH return self.INSTALLED_BROWSER_CONTAINER_PATH def create_file_url_from(self, filepath): return 'file://' + filepath def setup_base_path(self): if os.path.exists(self.LOCAL_HTML_EXAMPLES_PATH): self.BASE_PATH = self.LOCAL_HTML_EXAMPLES_PATH else: self.BASE_PATH = self.INSTALLED_HTML_EXAMPLES_PATH def setUp(self): self.setup_base_path() if platform.model() == "Desktop": self.pointer = Pointer(Mouse.create()) else: self.pointer = Pointer(Touch.create()) params = [self.BROWSER_QML_APP_LAUNCHER, self.get_browser_container_path()] if (platform.model() != 'Desktop'): params.append( '--desktop_file_hint=/usr/share/" \ + "applications/unitywebappsqmllauncher.desktop') self.app = self.launch_test_application( *params, app_type='qt') self.webviewContainer = self.get_webviewContainer() self.watcher = self.webviewContainer.watch_signal( 'resultUpdated(QString)') super(UbuntuHTML5TestCaseBase, self).setUp() def tearDown(self): super(UbuntuHTML5TestCaseBase, self).tearDown() def pick_app_launcher(self, app_path): # force Qt app introspection: from autopilot.introspection.qt import QtApplicationLauncher return QtApplicationLauncher() def get_webviewContainer(self): return self.app.select_single(objectName="webviewContainer") def get_webview(self): return self.app.select_single(objectName="webview") def get_addressbar(self): return self.app.select_single(objectName="addressbar") def get_button(self): return self.app.select_single(objectName="browseButton") def get_title(self): return self.get_webview().title def assert_url_eventually_loaded(self, url): webview = self.get_webview() self.assertThat( webview.loadProgress, Eventually(Equals(100))) self.assertThat( webview.loading, Eventually(Equals(False))) self.assertThat( webview.url, Eventually(Equals(url))) def click_dom_node_with_id(self, id): webview = self.get_webviewContainer() webview.slots.clickElementById(id) self.assertThat( lambda: self.watcher.num_emissions, Eventually(Equals(1))) def click_any_dom_node_by_selector(self, selector): webview = self.get_webviewContainer() webview.slots.clickAnyElementBySelector(selector) self.assertThat( lambda: self.watcher.num_emissions, Eventually(Equals(1))) def is_dom_node_visible(self, id): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.isNodeWithIdVisible(id) self.assertThat( lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads( webview.get_signal_emissions( 'resultUpdated(QString)')[-1][0])['result'] def eval_expression_in_page_unsafe(self, expr): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.evalInPageUnsafe(expr) self.assertThat( lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return webview.get_signal_emissions('resultUpdated(QString)')[-1][0] def get_dom_node_id_attribute(self, id, attribute): webview = self.get_webviewContainer() prev_emissions = self.watcher.num_emissions webview.slots.getAttributeForElementWithId(id, attribute) self.assertThat( lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) return json.loads( webview.get_signal_emissions( 'resultUpdated(QString)')[-1][0])['result'] def get_address_bar_action_button(self): addressbar = self.get_addressbar() return addressbar.select_single(objectName="browseButton") def browse_to_url(self, url): import time addressbar = self.get_addressbar() self.assertThat( addressbar.activeFocus, Eventually(Equals(True))) self.keyboard.type(url, 0.001) self.pointer.click_object(self.get_webview()) # XXX: very bad, but wont fix time.sleep(1) button = self.get_address_bar_action_button() self.pointer.move_to_object(button) self.pointer.press() # XXX: very bad, but wont fix time.sleep(1) self.pointer.release() self.assert_url_eventually_loaded(url) def browse_to_app(self, appname): appfilepath = os.path.abspath( self.BASE_PATH + '/data/html/' + self.APPS_SUBFOLDER_NAME + '/' + appname + '/index.html') APP_HTML_PATH = self.create_file_url_from(appfilepath) self.browse_to_url(APP_HTML_PATH) def browse_to_test_html(self, html_filename): self.browse_to_url( self.create_file_url_from( os.path.abspath( '{}/data/html/{}'.format( self.BASE_PATH, html_filename))))
class SaucyBaconTestCase(AutopilotTestCase): """A common test case class that provides several useful methods for the tests.""" if model() == 'Desktop': scenarios = [ ('with mouse', dict(input_device_class=Mouse)) ] else: scenarios = [ ('with touch', dict(input_device_class=Touch)) ] local_location = get_qml_location() + "/saucybacon.qml" @property def main_window(self): return MainWindow(self.app) def setUp(self): self.pointing_device = Pointer(self.input_device_class.create()) super(SaucyBaconTestCase, self).setUp() print self.local_location print get_module_include_path() if os.path.exists(self.local_location): self.launch_test_local() elif os.path.exists('/usr/share/saucybacon/app/saucybacon.qml'): self.launch_test_installed() else: self.launch_test_click() def launch_test_local(self): self.app = self.launch_test_application( "qmlscene", self.local_location, "-I", get_module_include_path(), app_type='qt', emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) def launch_test_installed(self): self.app = self.launch_test_application( "qmlscene", "/usr/share/postino/postino.qml", "--desktop_file_hint=/usr/share/applications/saucybacon.desktop", app_type='qt', emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) def launch_test_click(self): self.app = self.launch_click_package( 'com.ubuntu.developers.gcollura.saucybacon', emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) def get_qml_view(self): """Get the main QML view""" return self.app.select_single("QQuickView") def get_mainview(self): """Get the QML MainView""" mainView = self.app.select_single("MainView") self.assertThat(mainView, Not(Is(None))) return mainView def get_object(self,objectName): """Get a object based on the objectName""" obj = self.app.select_single(objectName=objectName) self.assertThat(obj, Not(Is(None))) return obj def mouse_click(self,objectName): """Move mouse on top of the object and click on it""" obj = self.get_object(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.click() def mouse_press(self,objectName): """Move mouse on top of the object and press mouse button (without releasing it)""" obj = self.get_object(objectName) self.pointing_device.move_to_object(obj) self.pointing_device.press() def mouse_release(self): """Release mouse button""" self.pointing_device.release() def type_string(self, string): """Type a string with keyboard""" self.keyboard.type(string) def type_key(self, key): """Type a single key with keyboard""" self.keyboard.key(key) @property def main_view(self): return self.app.select_single(emulators.MainView)
class CustomInstallTests(AutopilotTestCase): def setUp(self): super(CustomInstallTests, self).setUp() self.app = self.launch_application() self.pointing_device = Pointer(Mouse.create()) def launch_application(self): my_process = int(os.environ['UBIQUITY_PID']) my_dbus = str(os.environ['DBUS_SESSION_BUS_ADDRESS']) return get_proxy_object_for_existing_process( pid=my_process, dbus_bus=my_dbus) def test_custom_install(self): ''' Test install using Custom partition configuration ''' self.keyboard.press_and_release('Super+1') main_window = self.app.select_single( 'GtkWindow', name='live_installer') self.assertThat(main_window.title, Equals("Install")) # This method runs the ubiquity_ methods to navigate # testing through the install pages self.run_custom_install_test() #Then finally here check that the complete dialog appears self.ubiquity_did_install_complete() def run_custom_install_test(self): ''' this can be easily used when debugging. If the test exits on a particular page, you can comment out the pages prior to the exit point and reset current page to its default state, then run test again. The test will start from the page it exited on. This can save alot of hassle having to setup the whole test again, just to fix a small error. ''' #Page 1 self.ubiquity_welcome_page_test() #Page 2 self.ubiquity_preparing_page_test() ##Page 3 self.ubiquity_install_type_page_test() ##Page 3 extended self.ubiquity_advanced_partition_page() #Page 4 self.ubiquity_where_are_you_page_test() #Page 5 self.ubiquity_keyboard_page_test() #Page 6 self.ubiquity_who_are_you_page_test() #page 7 self.ubiquity_progress_bar_test() def ubiquity_welcome_page_test(self): ''' Tests that all needed objects on the Welcome page are accessible And can also be navigated to. Once confirmed continue with install accepting all defaults ''' self.get_ubiquity_objects() self.assertThat(self.headerlabel.label, Eventually(Contains('Welcome'))) #Can we navigate to the quit button? This fails the test if object # has no position attribs self.pointing_device.move_to_object(self.quit_button) self.assertThat(self.continue_button.label, Equals('Continue')) #Can we navigate to the continue button? self.pointing_device.move_to_object(self.continue_button) #Finally lets move on to the next page self.pointing_device.click() def ubiquity_preparing_page_test(self): self.wait_for_button_state_changed() #Check the next page title self.assertThat(self.headerlabel.label, Eventually(Contains('Preparing to install'))) #lets get all the page objects self.get_ubiquity_objects() ''' Lets test we can go back to the welcome page and come back here ''' #Click back self.pointing_device.move_to_object(self.back_button) self.pointing_device.click() self.wait_for_button_state_changed() #check we went back self.assertThat(self.headerlabel.label, Eventually(Contains('Welcome'))) #go back to the page we were on self.get_ubiquity_objects() self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() self.wait_for_button_state_changed() self.assertThat(self.headerlabel.label, Eventually(Contains('Preparing to install'))) ''' Lets navigate round all objects ''' # first need to get all objects again self.get_ubiquity_objects() #navigate to each one self.pointing_device.move_to_object(self.install_updates) self.pointing_device.move_to_object(self.third_party) self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.quit_button) self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) #Lets move on to next page now self.pointing_device.click() def ubiquity_install_type_page_test(self): """ Check next page value """ self.assertThat(self.headerlabel.label, Eventually(Contains('Installation type'))) #get all page objects self.get_ubiquity_objects() ''' Test we can go back to previous page and come back here ''' #Go back self.pointing_device.move_to_object(self.back_button) self.pointing_device.click() self.wait_for_button_state_changed() self.assertThat(self.headerlabel.label, Eventually(Contains('Preparing to install'))) #To Come back again we need to get the objects of the preparing page self.get_ubiquity_objects() self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() #check we came back ok self.assertThat(self.headerlabel.label, Eventually(Contains('Installation type'))) ''' Lets check we can get and navigate to all the objects If we wanted to change the install type we can just add required clicks here for different installation types ''' #Get all the page objects again self.get_ubiquity_objects() self.assertThat(self.erase_disk.label, Contains('Erase disk and install')) self.pointing_device.move_to_object(self.erase_disk) self.pointing_device.move_to_object(self.lvm_install) self.pointing_device.move_to_object(self.something_else_install) self.pointing_device.move_to_object(self.encrypt_install) self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.quit_button) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.move_to_object(self.something_else_install) self.pointing_device.click() #and now continue self.assertThat(self.continue_button.label, Equals('Continue')) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def ubiquity_advanced_partition_page(self): self.get_ubiquity_objects() self.wait_for_button_state_changed() self.assertThat(self.headerlabel.label, Eventually(Contains('Installation type'))) self.assertThat(self.adv_page_object.visible, Eventually(Equals(1))) #Create a new partition table self.pointing_device.move_to_object(self.adv_new_part_button) self.pointing_device.click() #COnfirm new table self.assertThat(self.adv_confirm_dialog.visible, Eventually(Equals(1))) self.keyboard.press_and_release('Right') self.keyboard.press_and_release('Enter') #check dialog closed self.assertThat(self.adv_confirm_dialog.visible, Eventually(Equals(0))) self.pointing_device.move_to_object(self.adv_undo_button) self.pointing_device.move_to_object(self.continue_button) self.pointing_device.move_to_object(self.adv_new_part_button) self.pointing_device.move_to_object(self.adv_scrolledwindow) self.pointing_device.click() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') self.assertThat(self.partition_dialog.visible, Eventually(Equals(1))) #Create swap partition self.partition_dialog_create_partition('swap', '1000', 'end', 'primary') self.assertThat(self.partition_dialog.visible, Eventually(Equals(0))) self.wait_for_button_state_changed() self.keyboard.press_and_release('Down') self.keyboard.press_and_release('Enter') #create root partition self.partition_dialog_create_partition('/', '', 'beginning', 'primary') self.assertThat(self.partition_dialog.visible, Eventually(Equals(0))) self.wait_for_button_state_changed() self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def partition_dialog_create_partition(self, mount, size, partition_place, partition_type): ''' Create required partition Params ::mount = a string val of the required mount point for example * 'swap' * '/' * '/home' * '/boot' ::size = string val of partition size required in MB AN empty string '' takes all the available space ::partition_place = a string val of position of partition * 'beginning' * 'end' ::partition_type = string val of the type of partition * 'logical' or * 'primary' Currently it uses the default partition format ext4 ''' #get the objects just to ensure id's have not changed self.get_ubiquity_objects() self.assertThat(self.partition_dialog.visible, Eventually(Equals(1))) self.assertThat(self.partition_dialog.title, Eventually(Contains('Create partition'))) if mount == 'swap' : self.select_spin_button() self.keyboard.type(size) if partition_place == 'beginning': self.pointing_device.move_to_object(self.place_begin_radio_button) elif partition_place == 'end' : self.pointing_device.move_to_object(self.place_end_radio_button) else: #if it matches neither lets place it at end by default as its a swap self.pointing_device.move_to_object(self.place_end_radio_button) self.pointing_device.click() if partition_type == 'primary' : self.pointing_device.move_to_object(self.primary_radio_button) elif partition_type == 'logical' : self.pointing_device.move_to_object(self.logical_radio_button) else: self.pointing_device.move_to_object(self.primary_radio_button) self.pointing_device.click() self.pointing_device.move_to_object(self.partition_use_combo) self.pointing_device.click() self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Up') self.keyboard.press_and_release('Enter') else: # input partition size if it is not '' if size is not '' : self.select_spin_button() self.keyboard.type(size) if partition_place == 'beginning': self.pointing_device.move_to_object(self.place_begin_radio_button) elif partition_place == 'end' : self.pointing_device.move_to_object(self.place_end_radio_button) else: #if it matches neither lets place it at beginning by default self.pointing_device.move_to_object(self.place_end_radio_button) self.pointing_device.click() if partition_type == 'primary' : self.pointing_device.move_to_object(self.primary_radio_button) elif partition_type == 'logical' : self.pointing_device.move_to_object(self.logical_radio_button) else: self.pointing_device.move_to_object(self.primary_radio_button) self.pointing_device.click() self.pointing_device.move_to_object(self.mount_gtkentry) self.pointing_device.click() self.keyboard.type(mount) self.pointing_device.move_to_object(self.ok_button) self.pointing_device.click() def select_spin_button(self): self.pointing_device.move_to_object(self.size_spinbutton) pos = self.pointing_device.position() x = pos[0] y = pos[1] x = x - 8 #px self.pointing_device.move(x, y) self.pointing_device.click() self.keyboard.press_and_release('Ctrl+a') def ubiquity_where_are_you_page_test(self): """ From this point on the installation has started If you need to re-run the test from here then the HDD partitions need to be wiped and ./run_ubiquity run again """ #check button activated self.wait_for_button_state_changed() self.get_ubiquity_objects() #check we are on the correct page. self.assertThat(self.headerlabel.label, Eventually(Contains('Where are you?'))) #Not much to test on this page lets move on self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def ubiquity_keyboard_page_test(self): #Check we are on the right page self.assertThat(self.headerlabel.label, Eventually(Contains('Keyboard layout'))) #get all the page objects self.get_ubiquity_objects() ''' Test we can go back ''' self.pointing_device.move_to_object(self.back_button) self.pointing_device.click() self.wait_for_button_state_changed() #check we went back ok self.assertThat(self.headerlabel.label, Eventually(Contains('Where are you?'))) #now lets go back self.continue_button = self.app.select_single('GtkButton', name='next') self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() #wait for button to become active again self.wait_for_button_state_changed() #check we came back ok self.assertThat(self.headerlabel.label, Eventually(Contains('Keyboard layout'))) #We need to get the page objects again as the id's have changed self.get_ubiquity_objects() ''' Test we can test keyboard ''' self.pointing_device.move_to_object(self.keyboard_entry) self.pointing_device.click() self.keyboard.type('This is testing that we can enter text in this GtkEntry') ''' Test we can navigate round the objects ''' self.pointing_device.move_to_object(self.keyboard_layout) self.pointing_device.move_to_object(self.keyboard_entry) self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.continue_button) #Lets move on to next page self.pointing_device.click() def ubiquity_who_are_you_page_test(self): """ This method enters the new users details on the 'Who are you?' page """ #assert page title self.assertThat(self.headerlabel.label, Eventually(Contains('Who are you'))) self.get_ubiquity_objects() ''' Test we can create a user ''' self.keyboard.type('autopilot rocks') # Lets lose these tabs self.pointing_device.move_to_object(self.password_entry) self.pointing_device.click() #Intentionally cause passwords to mis-match self.keyboard.type('password') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.conf_pwd_entry) self.pointing_device.click() self.keyboard.type('will_not_match') #check that passwords match, and if not redo them self.check_passwords_match() self.pointing_device.move_to_object(self.continue_button) self.pointing_device.click() def check_passwords_match(self): while True: self.continue_button = self.app.select_single('GtkButton', name='next') button_sensitive = self.continue_button.sensitive if button_sensitive == 1: self.assertThat(self.continue_button.sensitive, Equals(1)) break #If passwords didn't match (which they didn't ;-) ) then retype them self.pointing_device.move_to_object(self.password_entry) self.pointing_device.click() self.keyboard.press_and_release('Ctrl+a') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.password_entry) self.keyboard.type('password') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.conf_pwd_entry) self.pointing_device.click() self.keyboard.press_and_release('Ctrl+a') self.pointing_device.move_to_object(self.back_button) self.pointing_device.move_to_object(self.password_entry) self.keyboard.type('password') def ubiquity_progress_bar_test(self): ''' This method tracks the current progress of the install by using the fraction property of the progress bar to assertain the percentage complete. ''' #We cant assert page title here as its an external html page #Maybe try assert WebKitWebView is visible self.webkitwindow = self.app.select_single('GtkScrolledWindow', name='webkit_scrolled_window') self.assertThat(self.webkitwindow.visible, Eventually(Equals(1))) #Can we track the progress percentage? self.install_progress = self.app.select_single('GtkProgressBar', name='install_progress') #Copying files progress bar self.track_install_progress_bar() self.assertThat(self.install_progress.fraction, Eventually(Equals(0.0))) #And now the install progress bar self.track_install_progress_bar() def track_install_progress_bar(self): ''' Gets the value of the fraction property of the progress bar so we can see when the progress bar is complete ''' progress = 0.0 complete = 1.0 while progress < complete: #Lets check there have been no install errors while in this loop self.check_for_install_errors() #keep updating fraction value progress = self.install_progress.fraction # Use for debugging. Shows current 'fraction' value print(progress) def ubiquity_did_install_complete(self): self.complete_dialog = self.app.select_single('GtkDialog', name='finished_dialog') self.assertThat(self.complete_dialog.title, Eventually(Contains('Installation Complete'))) self.con_testing_button = self.complete_dialog.select_single('GtkButton', name='quit_button') self.restart_button = self.complete_dialog.select_single('GtkButton', name='reboot_button') self.assertThat(self.complete_dialog.visible, Eventually(Equals(1))) def wait_for_button_state_changed(self): ''' This waits on the continuebutton becoming active again ''' self.continue_button = self.app.select_single('GtkButton', name='next') #check button disabled self.assertThat(self.continue_button.sensitive, Eventually(Equals(0))) obj_prop = self.continue_button.sensitive #lets wait for button to enable again while obj_prop != 1: #keep grabbing the button to refresh it's state self.continue_button = self.app.select_single('GtkButton', name='next') obj_prop = self.continue_button.sensitive #Check there are no errors while in this loop self.check_for_install_errors() #lets check it is enabled before returning self.assertThat(self.continue_button.sensitive, Eventually(Equals(1))) def check_for_install_errors(self): ''' This checks that no error/unwanted dialogs appear simply asserting that their visible properties = 0 If they are not visible then there is no problems, UI wise that is! ;-) ''' # For each dialog lets, select each dialog and finally check its not visible crash_dialog = self.app.select_single('GtkDialog', name='crash_dialog') self.assertThat(crash_dialog.visible, Equals(0)) warning_dialog = self.app.select_single('GtkDialog', name='warning_dialog') self.assertThat(warning_dialog.visible, Equals(0)) def get_ubiquity_objects(self): """ Selects all the objects needed for usage in the test """ #-----------------------------------------------------------------------# # OBJECTS THAT ARE ON EVERY PAGE # # # self.headerlabel = self.app.select_single('GtkLabel', name='page_title') self.quit_button = self.app.select_single('GtkButton', name='quit') self.assertThat(self.quit_button.label, Equals('_Quit')) # We cannot assert continue button label here as the label value changes self.continue_button = self.app.select_single('GtkButton', name='next') #-----------------------------------------------------------------------# #-----------------------------------------------------------------------# # OBJECTS THAT ARE ON MULTIPLE PAGES # # # self.back_button = self.app.select_single('GtkButton', name='back') self.assertThat(self.back_button.label, Equals('_Back')) #-----------------------------------------------------------------------# #-----------------------------------------------------------------------# # OBJECTS 'FROM PREPARING TO INSTALL' PAGE # # # self.install_updates = self.app.select_single('GtkCheckButton', name='prepare_download_updates') self.assertThat(self.install_updates.label, Equals('Download updates while installing')) self.third_party = self.app.select_single('GtkCheckButton', name='prepare_nonfree_software') self.assertThat(self.third_party.label, Equals('Install this third-party software')) #------------------------------------------------------------------------# #------------------------------------------------------------------------# # OBJECTS FROM THE 'INSTALLATION TYPE' PAGE # # # self.erase_disk = self.app.select_single('GtkRadioButton', name='use_device') self.encrypt_install = self.app.select_single('GtkCheckButton', name='use_crypto') self.assertThat(self.encrypt_install.label, Equals('Encrypt the new Ubuntu installation for security')) self.lvm_install = self.app.select_single('GtkCheckButton', name='use_lvm') self.assertThat(self.lvm_install.label, Equals('Use LVM with the new Ubuntu installation')) self.something_else_install = self.app.select_single('GtkRadioButton', name='custom_partitioning') self.assertThat(self.something_else_install.label, Equals('Something else')) #-------------------------------------------------------------------------# #-------------------------------------------------------------------------# # OBJECTS FROM THE KEYBOARD LAYOUT PAGE # # # self.keyboard_entry = self.app.select_single('GtkEntry', name='keyboard_test') self.keyboard_layout = self.app.select_single('GtkButton', name='deduce_layout') self.assertThat(self.keyboard_layout.label, Equals('Detect Keyboard Layout')) #-------------------------------------------------------------------------# #-------------------------------------------------------------------------# # OBJECTS FROM THE 'WHO ARE YOU' PAGE # # # self.user_gtkbox = self.app.select_single('GtkBox', name='stepUserInfo') self.user_gtkgrid = self.user_gtkbox.select_single('GtkGrid', name='userinfo_table') self.user_hbox1 = self.user_gtkgrid.select_single('GtkBox', name='hbox1') self.password_entry = self.user_hbox1.select_single('GtkEntry', name='password') self.user_hbox2 = self.user_gtkgrid.select_single('GtkBox', name='hbox2') self.conf_pwd_entry = self.user_hbox2.select_single('GtkEntry', name='verified_password') #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# # OBJECTS FROM LVM ENCRYPTION PASSWORD PAGE # # # self.password_grid = self.app.select_single('GtkGrid', name='password_grid') self.encrypt_password = self.password_grid.select_single('GtkEntry', name='password') self.verify_encrypt_password = self.password_grid.select_single('GtkEntry', name='verified_password') #--------------------------------------------------------------------------# # OBJECTS FROM THE ADVANCED PARTITION PAGE # # # self.adv_page_object = self.app.select_single('GtkAlignment', name='stepPartAdvanced') self.adv_toolbar_grid = self.adv_page_object.select_single('GtkGrid', name='partition_list_buttonbox') self.adv_toolbar = self.adv_toolbar_grid.select_single('GtkToolbar', name='partition_toolbar') self.adv_new_button = self.adv_toolbar.select_single('GtkToolButton', name='partition_button_new') self.adv_del_button = self.adv_toolbar.select_single('GtkToolButton', name='partition_button_delete') self.adv_edit_button = self.adv_toolbar.select_single('GtkToolButton', name='partition_button_edit') self.adv_undo_button = self.adv_toolbar_grid.select_single('GtkButton', name='partition_button_undo') self.adv_new_part_button = self.adv_toolbar_grid.select_single('GtkButton', name='partition_button_new_label') self.adv_spinner = self.adv_toolbar_grid.select_single('GtkSpinner', name='part_advanced_recalculating_spinner') self.adv_scrolledwindow = self.adv_page_object.select_single('GtkScrolledWindow', name='scrolledwindow') # The Confirm Dialog when creating a new table self.adv_confirm_dialog = self.app.select_single('GtkDialog', name='ubi_question_dialog') self.adv_conf_button = self.adv_confirm_dialog.select_single('GtkButton', label='Continue') #Objects for the partition dialog self.partition_dialog = self.app.select_single('GtkDialog', name='partition_dialog') self.size_spinbutton = self.partition_dialog.select_single('GtkSpinButton', name='partition_size_spinbutton') self.logical_radio_button = self.partition_dialog.select_single('GtkRadioButton', name='partition_create_type_logical') self.primary_radio_button = self.partition_dialog.select_single('GtkRadioButton', name='partition_create_type_primary') self.place_end_radio_button = self.partition_dialog.select_single('GtkRadioButton', name='partition_create_place_end') self.place_begin_radio_button = self.partition_dialog.select_single('GtkRadioButton', name='partition_create_place_beginning') self.mount_combo_box = self.partition_dialog.select_single('GtkComboBox', name='partition_mount_combo') self.mount_gtkentry = self.mount_combo_box.select_single('GtkEntry', name='combobox-entry4') self.partition_use_combo = self.partition_dialog.select_single('GtkComboBox', name='partition_use_combo') self.partition_use_cellview = self.partition_use_combo.select_single('GtkCellView') self.ok_button = self.partition_dialog.select_single('GtkButton', name='partition_dialog_okbutton')