def set_implicit_wait(self, system_name, timeout, browser_name="all", element_config_file=None, element_tag=None): """ This keyword would permanently set the implicit wait time for given browser instance(s) :Datafile Usage: Tags or attributes to be used in input datafile for the system or subsystem. If both tag and attribute is provided the attribute will be used. 1. system_name = This attribute can be specified in the datafile as a <system> tag directly under the <credentials> tag. An attribute "name" has to be added to this tag and the value of that attribute would be taken in as value to this keyword attribute. <system name="name_of_thy_system"/> 2. browser_name = This <browser_name> tag is a child of the <browser> tag in the data file. Each browser instance should have a unique name. This name can be added here Eg: <browser_name>Unique_name_1</browser_name> 3. timeout = This contains the information of how much time the browser needs to wait for any action to be performed on it Eg: <timeout>15</timeout> 4. element_config_file = This <element_config_file> tag is a child of the <browser> tag in the data file. This stores the location of the element configuration file that contains all element locators. Eg: <element_config_file> ../Config_files/selenium_config.json </element_config_file> 5. element_tag = This element_tag refers to a particular element in the json fie which contains relevant information to that element. If you want to use this one element through out the testcase for a particular browser, you can include it in the data file. If this not the case, then you should create an argument tag in the relevant testcase step and add the value directly in the testcase step. FOR DATA FILE Eg: <element_tag>json_name_1</element_tag> FOR TEST CASE Eg: <argument name="element_tag" value="json_name_1"> :Arguments: 1. system_name(str) = the system name. 2. browser_name(str) = Unique name for this particular browser 3. timeout(str) = amount of time the browser should wait 4. element_config_file (str) = location of the element configuration file that contains all element locators 5. element_tag (str) = particular element in the json fie which contains relevant information to that element :Returns: 1. status(bool)= True / False. """ arguments = locals() arguments.pop('self') status = True wdesc = "This would permanently set the implicit wait time for " \ "given browser instance(s)" pNote("KEYWORD: set_implicit_wait | Description: {0}".format(wdesc)) pSubStep(wdesc) browser_details = {} system = xml_Utils.getElementWithTagAttribValueMatch(self.datafile, "system", "name", system_name) browser_list = system.findall("browser") try: browser_list.extend(system.find("browsers").findall("browser")) except AttributeError: pass if not browser_list: browser_list.append(1) browser_details = arguments for browser in browser_list: arguments = Utils.data_Utils.get_default_ecf_and_et(arguments, self.datafile, browser) if browser_details == {}: browser_details = selenium_Utils. \ get_browser_details(browser, datafile=self.datafile, **arguments) if browser_details is not None: current_browser = Utils.data_Utils.get_object_from_datarepository(system_name + "_" + browser_details["browser_name"]) if not current_browser: pNote("Browser of system {0} and name {1} not found in the " "datarepository" .format(system_name, browser_details["browser_name"]), "Exception") status = False else: self.wait_oper_object.\ implicit_wait(current_browser, browser_details["timeout"]) browser_details = {} Utils.testcase_Utils.report_substep_status(status) if current_browser: selenium_Utils.save_screenshot_onerror(status, current_browser) return status
def wait_until_visibility_of_element_located(self, system_name, timeout="5", locator=None, locator_type=None, browser_name="all", element_tag=None, element_config_file=None): """ This keyword would check whether an element is present on the DOM of a page and visible. :Datafile Usage: Tags or attributes to be used in input datafile for the system or subsystem. If both tag and attribute is provided the attribute will be used. 1. system_name = This attribute can be specified in the datafile as a <system> tag directly under the <credentials> tag. An attribute "name" has to be added to this tag and the value of that attribute would be taken in as value to this keyword attribute. <system name="name_of_thy_system"/> 2. browser_name = This <browser_name> tag is a child of the <browser> tag in the data file. Each browser instance should have a unique name. This name can be added here Eg: <browser_name>Unique_name_1</browser_name> 3. timeout = This contains the information of how much time the browser needs to wait for an element whose existence in the DOM is unknown to become visible Eg: <timeout>15</timeout> 4. locator_type = This contains information about the type of locator that you want to use. Can be 'xpath', 'id', 'css', 'link', 'tag','class', 'name' 5. locator = This contains the value of the locator. Something like "form", "nav-tags", "//[dh./dhh[yby]" 6. element_config_file = This contains the location of the json file that contains information about all the elements that you require for the testcase execution 7. element_tag = This contains the name of the element in that element_config_file which you want to use USING LOCATOR_TYPE, LOCATOR, ELEMENT_CONFIG_FILE, AND ELEMENT_TAG ================================================================= None of these arguments are mandatory BUT to search an element, you need to provide Warrior with some way to do it. a. You can either directly give values for the locator_type and locator. So if locator_type = name and locator = navigation-bar, then Warrior can search for an element with name "navigation-bar" b. You can give location of the element_config_file and a tag inside it so that Warrior can search for that tag and get the required information from there. - Now, if the locator type is given, Warrior will search for that locator_type in the children of that element in the element_config_file - You can also set defaults in the element_config_file, and now, even if the locator_type is not given, Warrior will know which element to find. If locator_type is given, the default will be overridden - If locator_type is not f=given, and the defaults are not specified, then the first element in the child list of the element tag would be picked. NOTES: For these four arguments to be given correctly, ONE of the following conditions must be satisfied. 1. locator_type and locator must be given 2. locator_type, element_config_file, and element_tag must be given 3. element_config_file, and element_tag must be given The datafile has the first priority, then the json file, and then finally the testcase. If all arguments are passed from the same place, then, if locator and locator_type are given, then they would have priority. Otherwise, the element_config_file would be searched The locator_type locator, element_tag can be given the datafile as children of the <browser> tag, but these values would remain constant for that browser. It is recommended that these values be passed from the testcase step. The element_config_file typically would not change from step to step, so it can be passed from the data file :Arguments: 1. system_name(str) = the system name. 2. browser_name(str) = Unique name for this particular browser 3. timeout(str) = amount of time the browser should wait 4. locator_type(str) = type of the locator - xpath, id, etc. 5. locator(str) = locator by which the element should be located. 6. element_config_file(str) = location of the element config file 7. element_tag(str) = json id of the locator that you want to use from the element config file :Returns: 1. status(bool)= True / False. """ arguments = locals() arguments.pop('self') status = True wdesc = "Browser would wait until visibility of an element known to " \ "be is determined" pNote("KEYWORD: wait_until_visibility_of_element_located | Description: {0}".format(wdesc)) pSubStep(wdesc) browser_details = {} system = xml_Utils.getElementWithTagAttribValueMatch(self.datafile, "system", "name", system_name) browser_list = system.findall("browser") try: browser_list.extend(system.find("browsers").findall("browser")) except AttributeError: pass if not browser_list: browser_list.append(1) browser_details = arguments for browser in browser_list: arguments = Utils.data_Utils.get_default_ecf_and_et(arguments, self.datafile, browser) if browser_details == {}: browser_details = selenium_Utils. \ get_browser_details(browser, datafile=self.datafile, **arguments) if browser_details is not None: current_browser = Utils.data_Utils.get_object_from_datarepository(system_name + "_" + browser_details["browser_name"]) if not current_browser: pNote("Browser of system {0} and name {1} not found in the " "datarepository" .format(system_name, browser_details["browser_name"]), "Exception") status = False else: status = self.wait_oper_object.\ wait_until_visibility_of_element_located(current_browser, browser_details["locator_type"], browser_details["locator"], browser_details["timeout"]) browser_details = {} Utils.testcase_Utils.report_substep_status(status) if current_browser: selenium_Utils.save_screenshot_onerror(status, current_browser) return status
def verify_page_by_property(self, system_name, expected_value, value_type, browser_name="all", element_config_file=None, element_tag=None): """ This keyword will verify page by property. :Datafile Usage: Tags or attributes to be used in input datafile for the system or subsystem. If both tag and attribute is provided the attribute will be used. 1. system_name = This attribute can be specified in the datafile as a <system> tag directly under the <credentials> tag. An attribute "name" has to be added to this tag and the value of that attribute would be taken in as value to this keyword attribute. <system name="name_of_thy_system"/> 2. browser_name = This <browser_name> tag is a child og the <browser> tag in the data file. Each browser instance should have a unique name. This name can be added here Eg: <browser_name>Unique_name_1</browser_name> 3. url = The URL that you want to open your browser to can be added in the <url> tag under the <browser> tag. Eg: <url>https://www.google.com</url> 4. expected_value = This <expected_value> tag is a child og the <browser> tag in the data file. This tag would contain the the value you expect the browser to have. This can be either a url, page title, page source, or page name Eg: <expected_value>http://www.google.com</expected_value> 5. value_type = This <value_type> tag is a child of the <browser> tag in the data file. This tag would contain the type of browser information that you want to verify. It can either be current_url, title, name, or page_source Eg: <value_type>title</value_type> 6. element_config_file = This <element_config_file> tag is a child of the <browser> tag in the data file. This stores the location of the element configuration file that contains all element locators. Eg: <element_config_file> ../Config_files/selenium_config.json </element_config_file> 7. element_tag = This element_tag refers to a particular element in the json fie which contains relevant information to that element. If you want to use this one element through out the testcase for a particular browser, you can include it in the data file. If this not the case, then you should create an argument tag in the relevant testcase step and add the value directly in the testcase step. FOR DATA FILE Eg: <element_tag>json_name_1</element_tag> FOR TEST CASE Eg: <argument name="element_tag" value="json_name_1"> :Arguments: 1. system_name(str) = the system name. 2. expected_value (str) = The expected value of the information retrieved from the web page. 3. value_type (str) = Type of page information that you wat to verify: current_url, name, title, or page_source 4. browser_name(str) = Unique name for this particular browser 5. url(str) = URL to which the browser should be directed 6. element_config_file (str) = location of the element configuration file that contains all element locators 7. element_tag (str) = particular element in the json fie which contains relevant information to that element :Returns: 1. status(bool)= True / False. """ arguments = locals() arguments.pop('self') status = True wdesc = "The browser will verify page by {0}".format(value_type) pNote("KEYWORD: verify_page_by_property | Description: {0}".format( wdesc)) pSubStep(wdesc) browser_details = {} system = xml_Utils.getElementWithTagAttribValueMatch( self.datafile, "system", "name", system_name) browser_list = system.findall("browser") try: browser_list.extend(system.find("browsers").findall("browser")) except AttributeError: pass if not browser_list: browser_list.append(1) browser_details = arguments for browser in browser_list: arguments = Utils.data_Utils.get_default_ecf_and_et( arguments, self.datafile, browser) if browser_details == {}: browser_details = selenium_Utils. \ get_browser_details(browser, datafile=self.datafile, **arguments) if browser_details is not None: current_browser = Utils.data_Utils.get_object_from_datarepository( system_name + "_" + browser_details["browser_name"]) if current_browser: obtained_value = self.verify_oper_object.get_page_property( current_browser, browser_details["value_type"]) if str(obtained_value) == expected_value: pNote("The obtained {0}: {1} matches the expected " "value: {2}. Verification success!".format( value_type, obtained_value, expected_value)) else: pNote( "The obtained {0}: {1} does not match the " "expected value: {2}. Verification failed!".format( value_type, obtained_value, expected_value), "Error") status = False else: pNote( "Browser of system {0} and name {1} not found in the " "datarepository".format( system_name, browser_details["browser_name"]), "Exception") status = False browser_details = {} Utils.testcase_Utils.report_substep_status(status) if current_browser: selenium_Utils.save_screenshot_onerror(status, current_browser) return status