def create_a_bookmark(self, name=None, query=None, public=None, searchbox_query=None): """Bookmark a search on current entity page""" self.navigate_to_entity() prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element(common_locators[prefix + 'search'], timeout=self.button_timeout) if searchbox is None: raise UINoSuchElementError('Search box not found.') if searchbox_query is not None: searchbox.clear() searchbox.send_keys(u'{0}'.format(escape_search(searchbox_query))) self.click(common_locators['search_dropdown']) self.click(locators['bookmark.new']) self.wait_until_element(locators['bookmark.name']) if name is not None: self.assign_value(locators['bookmark.name'], name) if query is not None: self.assign_value(locators['bookmark.query'], query) if public is not None: self.assign_value(locators['bookmark.public'], public) self.click(locators['bookmark.create'])
def search_entity(self, element_name, element_locator, search_key=None, katello=None, button_timeout=15, result_timeout=15): """Uses the search box to locate an element from a list of elements.""" search_key = search_key or 'name' prefix = 'kt_' if katello else '' searchbox = self.wait_until_element( common_locators[prefix + 'search'], timeout=button_timeout) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None searchbox.clear() searchbox.send_keys(u'{0} = {1}'.format( search_key, escape_search(element_name))) self.click(search_button_locator) element = self.wait_until_element( (element_locator[0], element_locator[1] % element_name), timeout=result_timeout, ) return element
def search(self, element, _raw_query=None): """Uses the search box to locate an element from a list of elements. :param element: either element name or a tuple, containing element name as a first element and all the rest variables required for element locator. :param _raw_query: (optional) custom search query. Can be used to find entity by some of its fields (e.g. 'hostgroup = foo' for entity named 'bar') or to combine complex queries (e.g. 'name = foo and os = bar'). Note that this will ignore entity's default ``search_key``. """ element_name = element[0] if isinstance(element, tuple) else element # Navigate to the page self.logger.debug(u'Searching for: %s', element_name) self.navigate_to_entity() # Provide search criterions or use default ones search_key = self.search_key or 'name' element_locator = self._search_locator() # Determine search box and search button locators depending on the type # of entity prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element(common_locators[prefix + 'search'], timeout=self.button_timeout) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if self.is_katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None # Pass the data into search field and push the search button if # applicable searchbox.clear() searchbox.send_keys( _raw_query or u'{0} = {1}'.format(search_key, escape_search(element_name))) # ensure mouse points at search button and no tooltips are covering it # before clicking self.perform_action_chain_move(search_button_locator) self.click(search_button_locator) # Make sure that found element is returned no matter it described by # its own locator or common one (locator can transform depending on # element name length) for _ in range(self.result_timeout): for strategy, value in (element_locator, common_locators['select_filtered_entity']): result = self.find_element((strategy, value % element)) if result is not None: return result time.sleep(1) return None
def search(self, element): """Uses the search box to locate an element from a list of elements. :param element: either element name or a tuple, containing element name as a first element and all the rest variables required for element locator. """ element_name = element[0] if isinstance(element, tuple) else element # Navigate to the page self.logger.debug(u'Searching for: %s', element_name) self.navigate_to_entity() # Provide search criterions or use default ones search_key = self.search_key or 'name' element_locator = self._search_locator() # Determine search box and search button locators depending on the type # of entity prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element( common_locators[prefix + 'search'], timeout=self.button_timeout ) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if self.is_katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None # Pass the data into search field and push the search button if # applicable searchbox.clear() searchbox.send_keys(u'{0} = {1}'.format( search_key, escape_search(element_name))) # ensure mouse points at search button and no tooltips are covering it # before clicking self.perform_action_chain_move(search_button_locator) self.click(search_button_locator) # Make sure that found element is returned no matter it described by # its own locator or common one (locator can transform depending on # element name length) for _ in range(self.result_timeout): for strategy, value in ( element_locator, common_locators['select_filtered_entity'] ): result = self.find_element((strategy, value % element)) if result is not None: return result time.sleep(1) return None
def search(self, element_name): """Searches existing Subscription from UI""" strategy, value = locators['subs.subscription_search'] searchbox = self.wait_until_element(common_locators['kt_search']) if searchbox: searchbox.clear() searchbox.send_keys(escape_search(element_name)) self.click(common_locators['kt_search_button']) return self.wait_until_element((strategy, value))
def search(self, name, search_key=None): """Perform search on Dashboard page""" self.navigate_to_entity() if search_key is None: search_string = name else: search_string = u'{0} = {1}'.format( search_key, escape_search(name)) self.assign_value(common_locators['search'], search_string) self.click(common_locators['search_button']) return self.get_total_hosts_count()
def search(self, element_name): """Uses the search box to locate an element from a list of elements""" element = None strategy, value = locators['contentviews.key_name'] searchbox = self.wait_until_element(common_locators['kt_search']) if searchbox: searchbox.clear() searchbox.send_keys(escape_search(element_name)) self.click(common_locators['kt_search_button']) element = self.wait_until_element((strategy, value % element_name)) return element
def search(self, name, search_key=None): """Perform search on Dashboard page""" self.navigate_to_entity() if search_key is None: search_string = name else: search_string = u'{0} = {1}'.format(search_key, escape_search(name)) self.assign_value(common_locators['search'], search_string) self.click(common_locators['search_button']) return self.get_total_hosts_count()
def search_key(self, element_name): """Uses the search box to locate an element from a list of elements.""" element = None searchbox = self.wait_until_element(common_locators['kt_search']) if searchbox: searchbox.clear() searchbox.send_keys(escape_search(element_name)) self.wait_for_ajax() self.click(common_locators['kt_search_button']) strategy, value = locators['ak.ak_name'] element = self.wait_until_element((strategy, value % element_name)) return element
def search(self, element_name): """Uses the search box to locate an element from a list of elements.""" Navigator(self.browser).go_to_gpg_keys() element = None strategy, value = locators["gpgkey.key_name"] searchbox = self.wait_until_element(common_locators["kt_search"]) if searchbox: searchbox.clear() searchbox.send_keys(escape_search(element_name)) self.wait_for_ajax() self.click(common_locators["kt_search_button"]) element = self.wait_until_element((strategy, value % element_name)) return element
def search(self, element_name): """Uses the search box to locate an element from a list of elements.""" # Navigate to the page self.navigate_to_entity() # Provide search criterions or use default ones search_key = self.search_key or 'name' element_locator = self._search_locator() # Determine search box and search button locators depending on the type # of entity prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element( common_locators[prefix + 'search'], timeout=self.button_timeout ) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if self.is_katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None # Pass the data into search field and push the search button if # applicable searchbox.clear() searchbox.send_keys(u'{0} = {1}'.format( search_key, escape_search(element_name))) self.click(search_button_locator) strategy, value = element_locator # If foreman entity and it's length more than 32 chars, and not in # exceptions list use the common locator. if ( not self.is_katello and len(element_name) > 32 and type(self).__name__ not in SEARCH_EXCEPTIONS_LIST): strategy, value = common_locators['select_filtered_entity'] # Return found element element = self.wait_until_element( (strategy, value % element_name), timeout=self.result_timeout, ) return element
def search(self, element_name): """Uses the search box to locate an element from a list of elements.""" # Navigate to the page self.navigate_to_entity() # Provide search criterions or use default ones search_key = self.search_key or 'name' element_locator = self._search_locator() # Determine search box and search button locators depending on the type # of entity prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element( common_locators[prefix + 'search'], timeout=self.button_timeout ) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if self.is_katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None # Pass the data into search field and push the search button if # applicable searchbox.clear() searchbox.send_keys(u'{0} = {1}'.format( search_key, escape_search(element_name))) self.click(search_button_locator) # Make sure that found element is returned no matter it described by # its own locator or common one (locator can transform depending on # element name length) strategy, value = element_locator strategy2, value2 = common_locators['select_filtered_entity'] for _ in range(self.result_timeout): element = self.find_element((strategy, value % element_name)) if element is not None: return element element2 = self.find_element((strategy2, value2 % element_name)) if element2 is not None: return element2 time.sleep(1) return None
def search(self, element_name): """Uses the search box to locate an element from a list of elements.""" # Navigate to the page self.navigate_to_entity() # Provide search criterions or use default ones search_key = self.search_key or 'name' element_locator = self._search_locator() # Determine search box and search button locators depending on the type # of entity prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element(common_locators[prefix + 'search'], timeout=self.button_timeout) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if self.is_katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None # Pass the data into search field and push the search button if # applicable searchbox.clear() searchbox.send_keys(u'{0} = {1}'.format(search_key, escape_search(element_name))) self.click(search_button_locator) # Make sure that found element is returned no matter it described by # its own locator or common one (locator can transform depending on # element name length) strategy, value = element_locator strategy2, value2 = common_locators['select_filtered_entity'] for _ in range(self.result_timeout): element = self.find_element((strategy, value % element_name)) if element is not None: return element element2 = self.find_element((strategy2, value2 % element_name)) if element2 is not None: return element2 time.sleep(1) return None
def search_key_subscriptions(self, ak_name, subscription_name): """Fetch associated subscriptions from selected activation key""" activation_key = self.search_key(ak_name) if activation_key is None: raise UINoSuchElementError( u'Could not find activation key {0}'.format(ak_name)) activation_key.click() self.wait_for_ajax() if self.wait_until_element(tab_locators['ak.subscriptions']) is None: raise UINoSuchElementError('Could not find Subscriptions tab') self.click(tab_locators['ak.subscriptions']) searchbox = self.wait_until_element( locators['ak.subscriptions.search']) if searchbox is None: raise UINoSuchElementError( 'Could not find Subscriptions search box') searchbox.clear() searchbox.send_keys(escape_search(subscription_name)) self.click(locators['ak.subscriptions.search_button']) strategy, value = locators['ak.get_subscription_name'] element = self.wait_until_element( (strategy, value % subscription_name)) return element
def create_a_bookmark(self, name=None, query=None, public=None, searchbox_query=None): """Bookmark a search on current entity page""" self.navigate_to_entity() prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element( common_locators[prefix + 'search'], timeout=self.button_timeout ) if searchbox is None: raise UINoSuchElementError('Search box not found.') if searchbox_query is not None: searchbox.clear() searchbox.send_keys(u'{0}'.format(escape_search(searchbox_query))) self.click(common_locators['search_dropdown']) self.click(locators['bookmark.new']) self.wait_until_element(locators['bookmark.name']) if name is not None: self.assign_value(locators['bookmark.name'], name) if query is not None: self.assign_value(locators['bookmark.query'], query) if public is not None: self.assign_value(locators['bookmark.public'], public) self.click(locators['bookmark.create'])
def test_escapes_backslash(self): """Tests if escape search escapes backslashes""" self.assertEqual(escape_search('termwith\\')[1:-1], 'termwith\\\\')
def test_escapes_double_quotes(self): """Tests if escape search escapes double quotes""" self.assertEqual(escape_search('termwith"')[1:-1], 'termwith\\"')
def test_return_type(self): """Tests if escape search returns a unicode string""" self.assertIsInstance(escape_search('search term'), six.text_type)
def test_wraps_in_double_quotes(self): """Tests if escape search wraps the term in double quotes""" term = escape_search('term') self.assertEqual(term[0], '"') self.assertEqual(term[-1], '"')
def test_return_type(self): """Tests if escape search returns a unicode string""" assert isinstance(escape_search('search term'), str)
def test_escapes_backslash(self): """Tests if escape search escapes backslashes""" assert escape_search('termwith\\')[1:-1] == 'termwith\\\\'
def test_escapes_double_quotes_and_backslash(self): """Tests if escape search escapes backslashes""" self.assertEqual( escape_search('termwith"and\\')[1:-1], 'termwith\\"and\\\\')
def test_escapes_double_quotes(self): """Tests if escape search escapes double quotes""" assert escape_search('termwith"')[1:-1] == 'termwith\\"'
def test_escapes_double_quotes_and_backslash(self): """Tests if escape search escapes backslashes""" self.assertEqual(escape_search('termwith"and\\')[1:-1], 'termwith\\"and\\\\')
def search(self, element, _raw_query=None, expecting_results=True): """Uses the search box to locate an element from a list of elements. :param element: either element name or a tuple, containing element name as a first element and all the rest variables required for element locator. :param _raw_query: (optional) custom search query. Can be used to find entity by some of its fields (e.g. 'hostgroup = foo' for entity named 'bar') or to combine complex queries (e.g. 'name = foo and os = bar'). Note that this will ignore entity's default ``search_key``. :param expecting_results: Specify whether we expect to find any entity or not """ element_name = element[0] if isinstance(element, tuple) else element # Navigate to the page self.logger.debug(u'Searching for: %s', element_name) self.navigate_to_entity() # Provide search criterions or use default ones search_key = self.search_key or 'name' element_locator = self._search_locator() # Determine search box and search button locators depending on the type # of entity prefix = 'kt_' if self.is_katello else '' searchbox = self.wait_until_element( common_locators[prefix + 'search'], timeout=self.button_timeout ) search_button_locator = common_locators[prefix + 'search_button'] # Do not proceed if searchbox is not found if searchbox is None: # For katello, search box should be always present on the page # no matter we have entity on the page or not... if self.is_katello: raise UINoSuchElementError('Search box not found.') # ...but not for foreman return None # Pass the data into search field and push the search button if # applicable searchbox.clear() searchbox.send_keys(_raw_query or u'{0} = {1}'.format( search_key, escape_search(element_name))) # ensure mouse points at search button and no tooltips are covering it # before clicking self.perform_action_chain_move(search_button_locator) self.click(search_button_locator) # In case we expecting that search should not find any entity if expecting_results is False: return self.wait_until_element( common_locators[prefix + 'search_no_results']) # Make sure that found element is returned no matter it described by # its own locator or common one (locator can transform depending on # element name length) for _ in range(self.result_timeout): for strategy, value in ( element_locator, common_locators['select_filtered_entity'] ): result = self.find_element((strategy, value % element)) if result is not None: return result time.sleep(1) return None
def test_wraps_in_double_quotes(self): """Tests if escape search wraps the term in double quotes""" term = escape_search('term') assert term[0] == '"' assert term[-1] == '"'