Пример #1
0
 def select_user(self, user_id, error=None):
     """
     Assumes current browser is on the user selection page
     :param user_id:
     :return:
     """
     xpath_candidates = ("xpath=//select[@name='dnqualifier']",)
     for xpath in xpath_candidates:
         logger.debug("Try xpath %s " % xpath)
         logger.warn("Try xpath %s " % xpath)
         ele = self._element_find(xpath, True, False)
         if ele is not None:
             ele = self._element_find("xpath=//option[@value='%s']" % user_id, True, False)
             if ele is not None:
                 self.select_from_list(xpath, user_id)
             else:
                 logger.warn("xpath=//option[contains(@value,'%s')]" % user_id, True)
                 ele = self._element_find("xpath=//option[contains(@value,'%s')]" % user_id, True, False)
                 if ele is not None:
                     full_value = ele.get_attribute("value")
                     self.select_from_list(xpath, full_value)
                 else:
                     raise RuntimeError("Not able to find user selection by value %s " % user_id)
             return
     raise AssertionError("Could not find user selection")
    def delete(
            self,
            alias,
            uri,
            data=(),
            headers=None,
            allow_redirects=None,
            timeout=None):
        """ * * *   Deprecated- See Delete Request now   * * *

        Send a DELETE request on the session object found using the
        given `alias`

        `alias` that will be used to identify the Session object in the cache

        `uri` to send the DELETE request to

        `headers` a dictionary of headers to use with the request

        `timeout` connection timeout
        """
        logger.warn("Deprecation Warning: Use Delete Request in the future")
        session = self._cache.switch(alias)
        data = self._utf8_urlencode(data)
        redir = True if allow_redirects is None else allow_redirects

        response = self._delete_request(
            session, uri, data, None, headers, redir, timeout)

        return response
Пример #3
0
 def get_logcat_from_device(self,path):
     log = AndroidAppiumLibrary.driver.get_log("logcat")
     with open(path, 'w+') as logfile:
         logfile.write("\n".join(str(x) for x in log))
         open(path+'_retrofit','w').writelines([ line.replace("u'", "'").replace(", 'level': 'ALL'", "") for line in open(path) if 'Retrofit' in line])
         logger.warn('<a href="{0}" style="width:1000px; height:20px">Retrofit log</a>'.format(path+'_retrofit')+'<br><div style="width:1000px;height:450px;line-height:1.5em;overflow:scroll; padding:5px;border:1px solid black; background:#FFFFE0;">{0}</div>'.format(open(path+'_retrofit').read()), html=True)
         logger.warn('<a href="{0}" style="width:1000px; height:20px">Full logcat</a>'.format(path), html=True)
    def get(
            self,
            alias,
            uri,
            params=None,
            headers=None,
            allow_redirects=None,
            timeout=None):
        """ **Deprecated- See Get Request now**

        Send a GET request on the session object found using the
        given `alias`

        `alias` that will be used to identify the Session object in the cache

        `uri` to send the GET request to

        `headers` a dictionary of headers to use with the request

        `timeout` connection timeout
        """
        logger.warn("Deprecation Warning: Use Get Request in the future")
        session = self._cache.switch(alias)

        redir = True if allow_redirects is None else allow_redirects

        response = self._get_request(
            session, uri, params, headers, redir, timeout)

        return response
 def _find_euh_dropdown(self,label_name, widget_name=None, index=0,first_call=True):
     '''find the dropdown by label, and then ensure we have an element with tag = select'''
     dropdown_div = self.get_euh_element_by_label(label_name, widget_name=widget_name,index=index)[0]
     
     #this can take a long time do to the implict wait functionality
     #TODO: this should use the quick check function from wait.py
     wait = self.get_selenium_implicit_wait()
     try:
         self.set_browser_implicit_wait(0)
         if self._element_or_children_contains_class_name(DC.Dropdown, dropdown_div):
             #get underlying select
             retval =  (dropdown_div.find_element_by_tag_name("select"), DC.Dropdown)
         elif self._element_or_children_contains_class_name(DC.AutocompleteDropDown, dropdown_div):
             retval = (dropdown_div.find_element_by_tag_name("input"), DC.AutocompleteDropDown)
         else:
             logger.warn("element %s with widget_name = %s and index = %s does not appear to be a dropdown" %
                 (label_name, widget_name, index))
             retval = (dropdown_div, None)
     except StaleElementReferenceException as e:
         #we got the element too soon try one more time
         #TODO: these need to be refactored into a retry find type of structure / reusable function
         if first_call: 
             self._find_euh_dropdown(label_name, widget_name,index,first_call=False)
         raise e
     finally:
         self.set_browser_implicit_wait(wait)
         return retval
Пример #6
0
 def get_user_password(self, user_login_id):
     if self.db_conn == None:
         logger.warn("Please use conn to initialize the connection first")
         return False
     self.db_cursor = self.db_conn.cursor()
     query = ''
     self.cursor.execute()
    def patch(self, alias, uri, data={}, headers=None, files={}, allow_redirects=None, timeout=None):
        """ **Deprecated- See Patch Request now**

        Send a PATCH request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the PATCH request to

        ``data`` a dictionary of key-value pairs that will be urlencoded
               and sent as PATCH data
               or binary data that is sent as the raw body content

        ``headers`` a dictionary of headers to use with the request

        ``files`` a dictionary of file names containing file data to PATCH to the server
        
        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``timeout`` connection timeout
        """
        logger.warn("Deprecation Warning: Use Patch Request in the future")
        session = self._cache.switch(alias)
        data = self._utf8_urlencode(data)
        redir = True if allow_redirects is None else allow_redirects

        response = self._body_request("patch", session, uri, data, None, files, headers, redir, timeout)

        return response
 def get_blns(self):
     if platform.system() == 'Windows':
         logger.warn('Rading Big List of Naughty Strings does not work in Windows OS')
         return []
     cur_dir = os.path.dirname(os.path.abspath(__file__))
     with open(os.path.join(cur_dir, 'blns.json'), 'r') as blns:
         return json.load(blns)
Пример #9
0
    def verify_resource_id_has_attributes_in_DB(self, resource_id, label, order='', label_tag='', company_typ_cd=''):
        if company_typ_cd!='':
            statement = "Select * from Presentation where PRSNTTN_LABEL='%s' and PRSNTTN_ORDER in ('%s')" \
                    "and PRSNTTN_LABEL_TAG in ('%s') and PRSNTTN_ID in " \
                    "(select PRSNTTN_ID from RESOURC where RSRC_ID='%s' and CMPNY_TYP_CD ='%s')"%(label, order, label_tag, resource_id, company_typ_cd)
        elif order!='' and label_tag!='':
            statement = "Select * from Presentation where PRSNTTN_LABEL='%s' and PRSNTTN_ORDER in ('%s')" \
                    "and PRSNTTN_LABEL_TAG in ('%s') and PRSNTTN_ID in " \
                    "(select PRSNTTN_ID from RESOURC where RSRC_ID='%s')"%(label, order, label_tag, resource_id)
        else:
            statement = "Select * from Presentation where PRSNTTN_LABEL='%s' and PRSNTTN_ID in " \
                    "(select PRSNTTN_ID from RESOURC where RSRC_ID='%s')"%(label, resource_id)

        logger.debug("fun: verify_resource_id_has_attributes_in_DB")
        logger.debug(statement)

        try:
            self.conn.check_if_exists_in_database(statement)
            msg = "==Verified Resource '%s' has attributes in DB Succeed! \nRSRC_ID %s has Label-->'%s' + Order-->'%s' + Tag-->'%s' and Company_Type_CD-->'%s'\n %s"%(resource_id, resource_id, label, order, label_tag, company_typ_cd, statement)
            logger.info(msg)
        except AssertionError, e:
            query = "select PRSNTTN_LABEL, PRSNTTN_ORDER, PRSNTTN_LABEL_TAG from Presentation where PRSNTTN_ID in "\
                    "(select PRSNTTN_ID from RESOURC where RSRC_ID='%s')"%(resource_id)
            result = self.conn.query(query)
            admin = self.conn.query("SELECT CMPNY_TYP_CD FROM RESOURC WHERE RSRC_ID='%s'"%resource_id)
            msg = "!!!Expected:['%s', '%s', '%s', '%s'] --> Actual: [%s, %s]"%(label, order, label_tag, company_typ_cd, result[0], admin[0][0])

            logger.warn(e.message)
            raise AssertionError(msg)
Пример #10
0
    def check_off_permission(self, db_name, driver, group_label, single_label, type):
        db_conn = Call_Oracle()
        db_conn.login(db_name)
        group_perm_id = db_conn.get_permission_id_from_label(group_label, "group", type)
        single_perm_id = db_conn.get_permission_id_from_label(single_label, "single", type)
        db_conn.close_connection()

        group_elem_xpath = self.page.get_xpath(group_perm_id, "group")
        single_elem_xpath = self.page.get_xpath(single_perm_id, "single")
        try:
            comp_elem = self.page.find_element_by_xpath(driver, single_elem_xpath)
            if comp_elem.get_attribute("checked") is None:
                logger.warn("..The permission '%s' was NOT checked before. Continue without change" % single_label)
            else:
                time.sleep(1)
                comp_elem.click()
                logger.info("====Revoked %s permission '%s/%s'" % (type, group_label, single_label))

        except (NoSuchElementException, ElementNotVisibleException):
            group_elem = self.page.find_element_by_xpath(driver, group_elem_xpath)
            group_elem.click()
            comp_elem = self.page.find_element_by_xpath(driver, single_elem_xpath)
            if comp_elem.get_attribute("checked") is None:
                logger.warn("..The permission '%s' was NOT checked before. Continue without change" % single_label)
            else:
                time.sleep(1)
                comp_elem.click()
                logger.info("====Revoked the %s permission '%s/%s'" % (type, group_label, single_label))
Пример #11
0
 def cliPrompt(self,cluster="yes"):
     logger.info("Switching to cli Prompt",also_console=True)
     ssh.set_client_configuration(prompt="#")
     ssh.write("cli -m config",loglevel="DEBUG") 
     output = ssh.read_until_prompt(loglevel="DEBUG")
     logger.info("Showing Prompt %s"%output,also_console=True)
     if output.find("% Unrecognized command") != -1:  
        logger.warn("You are logging from Root user", html=True)
        self.SwitchToReflex()
        ssh.set_client_configuration(prompt="#")
        ssh.write("cli -m config",loglevel="DEBUG")
        output = ssh.read_until_prompt(loglevel="DEBUG")
     if cluster == "no":
        m1 = re.search("^(?P<cliPrompt>\S+\s\(\S+\)\s*\#)\s*",output.strip(),re.MULTILINE)
     else:
        for lines in output.splitlines():
            m1 = re.search("^(?P<cliPrompt>\S+\s\[\S+:\s\S+\]\s\(\S+\)\s*\#)\s*",lines.strip(),re.MULTILINE) 
            #logger.console(lines, newline=True, stream='stdout')
     #m1 = re.search("^(?P<cliPrompt>.*\$\s.*config\S+\s\(\S+\)\s*\#)\s*",output.strip(),re.MULTILINE)
     #logger.console(m1)
     if m1:
             cliPrompt = m1.group("cliPrompt")
             logger.console(cliPrompt)
     else:
             logger.warn("Not able to grep cliPrompt")
     ssh.set_client_configuration(prompt=cliPrompt)
    def head(
            self,
            alias,
            uri,
            headers=None,
            allow_redirects=None,
            timeout=None):
        """ **Deprecated- See Head Request now**

        Send a HEAD request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the HEAD request to

        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``headers`` a dictionary of headers to use with the request
        """
        logger.warn("Deprecation Warning: Use Head Request in the future")
        session = self._cache.switch(alias)
        redir = False if allow_redirects is None else allow_redirects
        response = self._head_request(session, uri, headers, redir, timeout)

        return response
    def publish(self, topic, message=None, qos=0, retain=False):

        """ Publish a message to a topic with specified qos and retained flag.
        It is required that a connection has been established using `Connect`
        keyword before using this keyword.

        `topic` topic to which the message will be published

        `message` message payload to publish

        `qos` qos of the message

        `retain` retained flag

        Examples:

        | Publish | test/test | test message | 1 | ${false} |

        """
        logger.info('Publish topic: %s, message: %s, qos: %s, retain: %s'
            % (topic, message, qos, retain))
        self._mid = -1
        self._mqttc.on_publish = self._on_publish
        result, mid = self._mqttc.publish(topic, message, int(qos), retain)
        if result != 0:
            raise RuntimeError('Error publishing: %s' % result)

        timer_start = time.time()
        while time.time() < timer_start + self._loop_timeout:
            if mid == self._mid:
                break;
            self._mqttc.loop()

        if mid != self._mid:
            logger.warn('mid wasn\'t matched: %s' % mid)
Пример #14
0
    def revoke_company_permission(self, driver, group_label, group_id, company_label, company_id):
        '''
        From the Design document, you already know the group_label, group_id, company_label, company_id
        So, we use this parameter to select the new permission and check it.
        '''
        group_elem_xpath = self.page.get_xpath(group_id, 'group')
        comp_elem_xpath = self.page.get_xpath(company_id, 'single')
        try:
            comp_elem = self.page.find_element_by_xpath(driver, comp_elem_xpath)
            if comp_elem.get_attribute('checked') is None:
                logger.warn("..The permission '%s' was NOT checked before. Continue without change"%company_label)
            else:
                time.sleep(1)
                comp_elem.click()
                logger.info("====Revoked the company permission '%s/%s'"%(group_label, company_label))

        except (NoSuchElementException, ElementNotVisibleException):
            group_elem = self.page.find_element_by_xpath(driver, group_elem_xpath)
            group_elem.click()
            comp_elem = self.page.find_element_by_xpath(driver, comp_elem_xpath)
            if comp_elem.get_attribute('checked') is None:
                logger.warn("..The permission '%s' was NOT checked before. Continue without change"%company_label)
            else:
                time.sleep(1)
                comp_elem.click()
                logger.info("====Revoked the company permission '%s/%s'"%(group_label, company_label))
Пример #15
0
def HAdoopReport():
    var = robo.get_variable_value("${shellPrompt}")
    ssh.set_client_configuration(prompt=var)
    ssh.write("hdfs dfsadmin -report")
    output = ssh.read_until_prompt()
    #logger.info(output.splitlines())
    for line in output.splitlines():
        #match = re.search('Safemode.*',line)
        #logger.warn(line.find("Safe mode is ON"))
        if line.find("Safe mode is ON") == -1:
            safemode = "True"
            #logger.warn("Safemode is OFF")
        else: 
            safemode = "False"
            logger.warn("Safemode is ON")
        if line.find("Datanodes available") != -1:
            match = re.search('.*:\s(\d.)(?:.*,\s(\d.))',line)
            #logger.warn("datanode number %s"%match.group(2))
            logger.info(match.group(2),also_console = True)
            if match.group(2) != 0:
                Datanodes_up = "True"
            elif line.find("java.net.ConnectException:") != -1:
                logger.warn("Yarn is not UP , and throwing following exception",line)
                Datanodes_up = "False"
    #logger.warn("Inside Function safemode is %s"%safemode)
    #logger.warn("Inside Function datanodes is %s"%Datanodes_up)
    if safemode == "True" and Datanodes_up == "True":
        return True
    else:   
        return False
Пример #16
0
    def check_on_permission(self, db_name, driver, group_label, single_label, type):
        """
        If you just know the presentation label and want to select it.
        """
        db_conn = Call_Oracle()
        db_conn.login(db_name)
        group_perm_id = db_conn.get_permission_id_from_label(group_label, "group", type)
        single_perm_id = db_conn.get_permission_id_from_label(single_label, "single", type)
        db_conn.close_connection()

        group_elem_xpath = self.get_xpath(group_perm_id, "group")
        single_elem_xpath = self.get_xpath(single_perm_id, "single")
        try:
            comp_elem = self.page.find_element_by_xpath(driver, single_elem_xpath)
            if comp_elem.get_attribute("checked") is None:
                time.sleep(1)
                comp_elem.click()
                logger.info("====Assigned %s permission: '%s/%s'" % (type, group_label, single_label))
            else:
                logger.warn("..The permission '%s' was already assigned. Continue without change" % single_label)
        except (NoSuchElementException, ElementNotVisibleException):
            group_elem = self.page.find_element_by_xpath(driver, group_elem_xpath)
            group_elem.click()
            comp_elem = self.page.find_element_by_xpath(driver, single_elem_xpath)
            if comp_elem.get_attribute("checked") is None:
                time.sleep(1)
                comp_elem.click()
                logger.info("====Assigned %s permission: '%s/%s'" % (type, group_label, single_label))
            else:
                logger.warn("..The permission '%s' was already assigned. Continue without change" % single_label)
Пример #17
0
 def wait_for_telm_packet(self,timeoutSecs=60):
     if not self.session.isAlive():
         logger.warn("Can't wait for packet if session not open!")
         raise RuntimeError("Session not open!")
     logger.info("Waiting for HS packet with a timeout of %d s" % timeoutSecs)
     if not self.session.wait_for_next_telm_packet(timeoutSecs):
         raise RuntimeError("Didn't recieve packet in %s secs" % timeoutSecs)
     return True
Пример #18
0
 def select_tab(self, driver, tab_name):
     if tab_name in self.tab_name_list:
         elem = self.find_element_by_link_text(driver, tab_name)
         elem.click()
     else:
         msg = 'Sorry, the tab name ' + tab_name + 'is not defined in this page'
         logger.warn(msg)
         raise AssertionError(msg)
Пример #19
0
 def find_element(self, driver, method, value, time_out=20):
     try:
         elem = WebDriverWait(driver, time_out).until(EC.presence_of_element_located((method, value)))
     except:
         msg = "Sorry, can not find specific element: " + value
         logger.warn(msg)
         raise AssertionError(msg)
     return elem
 def listener_method(*args):
     if name in ['message', 'log_message']:
         msg = args[0]
         message = '%s: %s %s' % (name, msg['level'], msg['message'])
     else:
         message = name
     logging.info(message)
     logger.warn(message)
 def get_compare_path(self):
     try:
         if platform.system() == "Windows":
             return os.path.normpath(self.get_magick_home + "\\" + "compare.exe")
         if platform.system() == "Linux":
             return os.path.normpath("/usr/bin/compare")
     except os.error as e:
         logger.warn("Missing file compare" + e)
         return "missing"
 def timer_start(self, timer_name="Global"):
     current_time = get_current_time_for_timers()
     logger.info(current_time)
     if timer_name in self.TIMERS_DICTIONARY:
         error = "Timer with name \"%s\" already stated at %s" % (timer_name, self.TIMERS_DICTIONARY[timer_name].__str__())
         logger.warn(error)
     self.TIMERS_DICTIONARY[timer_name] = current_time
     msg = "Timer with name \"%s\" stated at %s" % (timer_name, self.TIMERS_DICTIONARY[timer_name].__str__())
     logger.info(msg)
Пример #23
0
 def get_table_cell_data(self, driver, row_num, column_num):
     max_row_num = self.get_table_row_number(driver)
     if row_num<max_row_num:
         index = r'//div[@class="xzw"]//table//tr['+row_num+r']/td'
         cell = driver.find_elements_by_xpath(index)
         return cell.text
     else:
         logger.warn("No such cell")
         raise AssertionError
 def _run_on_failure(self):
     if not self.keyword_on_failure:
         return
     try:
         BuiltIn().run_keyword(self.keyword_on_failure)
     except Exception as e:
         LOGGER.debug(e)
         LOGGER.warn('Failed to take a screenshot. '
                     'Is Robot Framework running?')
Пример #25
0
    def get_deployment_settings(self, *asked):
        """
            Returns the deployment settings asked in a dict where key is the
            asked setting. It makes a get request to eden/default/edentest
            and uses s3cfg to get the settings.
            It uses env. proxy settings
        """

        logger.info("base_url %s" % (self.base_url))

        # Create the request_url for the get request
        request_url = "%s/default/get_settings/deployment_settings" % (self.base_url)

        for key in asked:
            request_url = "%s/%s" % (request_url, key)
        logger.info("request_url %s" % (request_url))

        # Create the headers
        b64_auth_string = b64encode("%s:%s" % (self.admin_email, self.admin_password))
        headers = {
            "content-type" : "application/json",
            "Authorization" : "Basic %s" % b64_auth_string
            }

        # Send the response and get the response
        response = requests.get(request_url, headers=headers)
        if response.status_code != requests.codes.ok:
            if response.status_code == 403:
                logger.warn("Could not login")
                m = "Check variable ADMIN_EMAIL and ADMIN_PASSWORD\
                 or allow_testing in config.py. request %s" % request_url

            elif response.status_code == 401:
                logger.warn("Insufficent priviledges")
                m = "You do not have admin rights. request %s" \
                % request_url

            elif response.status_code in (405, 500):
                logger.warn("Testing not allowed/Internal server error")
                m = "allow_testing set to False in 000_config.py. request %s" \
                % request_url

            else:
                logger.warn("Could not contact the Eden server")
                m = "Check 000_config.py/config.py/server/internet settings. request %s" \
                % request_url

            BuiltIn().fail(msg=m)

        output = response.json()

        for key in asked:
            if key not in output:
                logger.warn("Could not fetch the setting %s" % key)

        return output
 def _get_xpath(self, xpath):
     try:
         return str(xpath)
     except UnicodeError:
         if not xpath.replace('/', '').isalnum():
             logger.warn('XPATHs containing non-ASCII characters and '
                         'other than tag names do not always work with '
                         'Python/Jython versions prior to 2.7. Verify '
                         'results manually and consider upgrading to 2.7.')
         return xpath
Пример #27
0
    def link_should_visible_in_navigation_bar(self, link_name):
        """Check If Link Is Visible In Crossroads6
        :param link_name:
        :return:
        """
        # select navigation frame
        self._switch_to_nav_frame()

        selenium.page_should_contain_element(self.xroads6_home_page_elements[link_name])
        logger.warn("%s In The Navigation Bar!" % link_name)
Пример #28
0
    def _wait_for_loading_div_to_clear(self):
        """Check to see if loading div is on the screen and return only when it is not"""
        div_gone = self._with_timeout(
            self._is_loading_div_not_visible, None, test_name_for_logger="wait for loading div to clear"
        )
        if div_gone[0] == False:
            logger.warn("Waited for %s seconds but loading div is still displayed" % (div_gone[1]))
        else:
            self._info("Waited for %s seconds until loading div disappeared" % (div_gone[1]))

        return div_gone[0]
Пример #29
0
 def _screenshot_to_file(self, path):
     path = self._validate_screenshot_path(path)
     logger.debug('Using %s modules for taking screenshot.'
                  % self._screenshot_taker.module)
     try:
         self._screenshot_taker(path)
     except:
         logger.warn('Taking screenshot failed: %s\n'
                     'Make sure tests are run with a physical or virtual display.'
                     % utils.get_error_message())
     return path
 def get_element_from_OR(self,OR_name):
     locator = OR.get(OR_name.lower())
     if locator:
         logger.warn("Found an overwrite in the OR for name %s with locator %s. Not using dummy classes" % (OR_name, locator))
         element = self._element_find(locator,True,True)
         #try to slow things down a little bit here
         #self._wait_for_elem(element)
         self._prep_element(element)
         return element
     
     raise RuntimeError("Trying to lookup %s in OR but item not found" % (OR_name))
Пример #31
0
    def create_and_link_recon(self,
                              tool,
                              target_name,
                              file_name=None,
                              tags=None):
        '''
        Links recon with the following params
        :param tool: tool name => zap, burp, nmap, etc
        :param target_name: target name, should be already loaded as a target. Name is unique
        :param file_name: file name of the recon results. This is optional
        :param tags: tags of the tool to link by. This will query the tags with the test cases and link the recon to the specific test case.

        | create and link recon  | tool  | target_name  | file_name (optional)  | tags (optional)  |

        '''
        recon = Recon()
        recon.tool = tool
        if file_name:
            recon.result = file_name
        else:
            logger.warn(
                "there's no file. There will be no results stored from your recon results"
            )

        relevant_tests = []
        if tags:
            tags = tags.split(',')
            for single in tags:
                all_tests_for_single = TestCase.objects(tags=single)
                for one in all_tests_for_single:
                    relevant_tests.append(one)

            test_ids = [test.id for test in relevant_tests]

            recon.cases = test_ids

        get_target = Target.objects.get(name=target_name)
        if get_target:
            recon.target = get_target

        recon.session = self.session
        recon.save()
Пример #32
0
 def __init__(self):
     self.os_atf_path = ""
     self.is_mt = BuiltIn().get_variable_value('${is_runtype_mt}')
     logger.warn("MT enabled: %s " % self.is_mt)
     
     if _platform == "linux" or _platform == "linux2":
         # linux
         self.os_atf_path = LINUX_ATF_PATH
     elif _platform == "darwin":
         self.os_atf_path = MAC_ATF_PATH
         # OS X
     elif _platform == "win32":
         # Windows...
         self.os_atf_path = WIN_ATF_PATH
     
     self.pphoneutil_path = self.os_atf_path + 'util\pphoneutil\phoneutil.exe'
     if self.is_mt is not "false":
         self.pphoneutil_hq_rsa = self.os_atf_path + 'util\pphoneutil\mt_hq_rsa'
     else:
         self.pphoneutil_hq_rsa = self.os_atf_path + 'util\pphoneutil\hq_rsa'
Пример #33
0
def handle_stale_element(method, *args, **kwargs):
    '''This is a decorator which means it is a function used
    to wrap other functions.  It will wrap a function and if that
    function throws a StaleElementReferenceException, which usually
    happens becaue an AJAX call has changed an element we are trying
    to operate on, it will retry the function one more time, the idea
    is the function would just try to find the element again and then
    performe an operation on the element.
    To use this decorator on a function declare the function like:
    @handle_stale_element
    def myfunction():
    a good example is euh_set_text_value
    '''
    try:
        return method(*args, **kwargs)
    except StaleElementReferenceException:
        logger.warn("Found a stale element in %s trying again.  Consider using"
                " an explicit wait such as wait until page contains element to"
                " avoid the stale element and speed up script playback time." % (method.__name__))
        return method(*args, **kwargs)
Пример #34
0
	def read_mcp_port(self, port):
		str_read_a = str(hex(SPI_READ_A))
		str_read_b = str(hex(SPI_READ_B))

		_MCP23S17_DEVICE_1 = '4'
		_MCP23S17_ADDR_0 = '0'

		if port == str_read_a:
			logger.info('Read MCP23S17 port A')
			item = {'Device':_MCP23S17_DEVICE_1, 'SPI-addr':_MCP23S17_ADDR_0, 'Reg':hex(SPI_READ_A)}

		elif port == str_read_b:
			logger.info('Read MCP23S17 port B')
			item = {'Device':_MCP23S17_DEVICE_1, 'SPI-addr':_MCP23S17_ADDR_0, 'Reg':hex(SPI_READ_B)}

		else:
			logger.warn('Illegal port declaration when port is read')

		rv = self.config_mcp(item)
		return rv
Пример #35
0
    def copy_object_attributes(result, attributes):
        """Method attempts to assign all attributes in robot.result.model object to corresponding values from
        attributes dictionary

        :param result: robot.result.model object
        :param attributes: dictionary passed to listener methods by robot
        :return:
        """
        for attr, value in attributes.iteritems():
            try:
                if attr.lower() == u'status' and type(result) != RRM.TestSuite:
                    result.passed = value.lower() == u'pass'
                    continue
                if attr.lower() in \
                        [u'elapsedtime', u'critical', u'longname', u'id', u'type', u'tests', u'statistics', u'status']:
                    continue
                if hasattr(result, attr):
                    setattr(result, attr, value)
            except (AttributeError, TypeError) as e:
                logger.warn("Cann't set {} to {}: {}".format(attr, value, e))
Пример #36
0
    def unsubscribe(self, topic):
        """ Unsubscribe the client from the specified topic.

        `topic` topic to unsubscribe from

        Example:
        | Unsubscribe | test/mqtt_test |

        """
        self._unsubscribed = False
        self._mqttc.on_unsubscribe = self._on_unsubscribe
        self._mqttc.unsubscribe(str(topic))

        timer_start = time.time()
        while (not self._unsubscribed
               and time.time() < timer_start + self._loop_timeout):
            self._mqttc.loop()

        if not self._unsubscribed:
            logger.warn('Client didn\'t receive an unsubscribe callback')
Пример #37
0
    def get_cust_manager(self, name):
        """
        查询管户经理
        :param name:
        :return:

        "http://lambda-web-test.ronaldinho.svc.cluster.local/transfer/cust/manager/record/selectCustManager?_ukey=5381&r=0.13963574590581307&custManagerName=admin"
        """
        params = {
            "custManagerName": name,
        }
        url = '%s/transfer/cust/manager/record/selectCustManager' % self._lambda_url
        res = self._request.get(url, params=params)
        ret = check_json_response(res)
        if len(ret['data']) == 0:
            raise AssertionError("没有找到名为 %s 的管户经理 !" % name)
        elif len(ret['data']) > 1:
            logger.warn("%s 对应不止一个管户经理,暂时只选择第一个!")
        c = ret['data'][0]
        return c['custManagerName'], c['custManagerId'], c['custOrgId']
Пример #38
0
 def setup_database(self):
     for alias, db in settings.DATABASES.items():
         if 'postgresql' in db['ENGINE']:
             db_wrapper = self._root_db_wrapper(db)
             try:
                 with db_wrapper.cursor() as cursor:
                     cursor.execute('CREATE DATABASE {} OWNER {}'.format(
                         db['NAME'], db['USER']))
             except ProgrammingError as e:
                 logger.warn(str(e))
         elif 'sqlite3' in db['ENGINE']:
             try:
                 os.makedirs(os.path.dirname(db['NAME']))
             except OSError as e:
                 # Raise unless it's because it already exists
                 if e.errno != 17:
                     raise
     call_command('migrate')
     if 'modeltranslation' in settings.INSTALLED_APPS:
         call_command('sync_translation_fields', interactive=False)
Пример #39
0
 def run_keyword(self, name, args, kwargs):
     self._running_keyword = name
     try:
         return DynamicCore.run_keyword(self, name, args, kwargs)
     except robot.errors.TimeoutError:
         logger.warn('Test timeout. Force stop puppeteer server')
         # Force
         self.loop.run_until_complete(
             self.get_current_library_context().stop_server())
         raise
     except Exception:
         if name.lower().replace(
                 ' ', '_') == 'close_puppeteer' or name.lower().replace(
                     ' ', '_') == 'open_browser':
             logger.warn('Can\'t close puppeteer...')
         elif name.lower().replace(' ', '_') != 'capture_page_screenshot':
             self.failure_occurred()
         raise
     finally:
         self._running_keyword = None
Пример #40
0
    def __init__(self, project_name, default_connection = True):
        '''
        Initialize the ThreatPlaybook API

        By default, the param ``default_connection`` is set to true. This means that ThreatPlaybook will attempt to connect to
        the local MongoDB instance on DB ``threat_playbook`` with no authentication or other params

        If you want to connect to a mongoDB instance with authentication and other params, you need to enable Environment Variables:
        ``TP_MONGO_USER`` => Mongo Username
        ``TP_MONGO_PASS`` => Mongo Password
        ``TP_MONGO_HOST`` => Mongo Host IP
        ``TP_MONGO_PORT`` => Mongo Port

        All these params have to be set if the default_connection is initialized with `False`

        | ThreatPlaybook  | project_name | default_connection=True/False |

        '''

        try:
            if not default_connection:
                logger.warn("Running MongoDB without Authentication. Highly recommend running MongoDB with Authentication")
                connect('threat_playbook')
            else:
                mongo_user = os.getenv("TP_MONGO_USER", None)
                mongo_pass = os.getenv("TP_MONGO_PASS", None)
                mongo_host = os.getenv("TP_MONGO_HOST", None)
                mongo_port = os.getenv("TP_MONGO_PORT", None)
                connect(db = 'threat_playbook', username = mongo_user, password = mongo_pass, host=mongo_host, port = mongo_port)
        except:
            logger.error("Unable to connect to DB. Disconnecting")
            exit(1)

        Project.objects(name = project_name).update_one(name = project_name, upsert = True)
        self.project = Project.objects.get(name = project_name)

        new_session = Session(project = self.project)
        new_session.name = str(uuid4())
        new_session.save()
        self.session = new_session
        self.entity_info = None
Пример #41
0
    def delete_user(self, user_index):
        """ Delete Site Users

        Delete a user within a site
        Must be logged in as administrator to delete user.

        Variable
            *json_payload*
                - string that contains json configuration for the user to delete

        .. code:: robotframework

            *** Test Cases ***
            Sample
                Delete user   USER0

        For more information, visit `/user`_.

        .. _/user: http://wiki:8090/pages/viewpage.action?pageId=4849856#DataWebServiceAPI-/api/user     
        """

        logger.warn(
            "Delete user call is out of date!  "
            "Webservice calls have been removed to be replaced by direct database management"
        )

        assert user_index in _UserManagement_Keywords.user_ids.keys(), \
            AssertionError('Invalid user {}, please selection from the following users {1}'
                           .format(user_index, _UserManagement_Keywords.user_ids.keys()))

        user_info = {
            "user-id":
            "{0}".format(_UserManagement_Keywords.user_ids[user_index])
        }
        logger.info(user_info)

        assert 'user-id' in user_info.keys(), AssertionError(
            "Invalid user parameters")

        self._assert_json_response_stop_on_error(
            self._delete('user', json.dumps(user_info)))
Пример #42
0
 def _wait_for_element(self,
                       locator_strategy=None,
                       locator_key=None,
                       locator_value=None,
                       locator_kv=None):
     """
     Custom wait method that uses polling.
     Currently unused and unstable
     :param locator_strategy:
     :param locator_key:
     :param locator_value:
     :param locator_kv:
     :return:
     """
     number_of_attempts = 0
     while number_of_attempts < 3:
         try:
             if locator_strategy.lower() == "xpath":
                 element = self.driver.find_element_by_xpath(
                     f"//*[@{locator_key}='{locator_value}']")
                 return element
             elif locator_strategy.lower() == "accessibility_id":
                 element = self.driver.find_element_by_accessibility_id(
                     f"{locator_value}")
                 return element
             elif locator_strategy.lower() == "name":
                 element = self.driver.find_element_by_name(
                     f"{locator_value}")
                 return element
         except Exception:
             robologger.debug(
                 f"Tried to locate element. Attempt number {number_of_attempts}"
             )
             time.sleep(0.5)
             number_of_attempts += 1
             continue
         finally:
             if number_of_attempts == 3:
                 robologger.warn(
                     "3 attempts were made but element couldn't be located."
                 )
Пример #43
0
    def get_id_by_other_message(self,jsondata,msg,msg_value):

        '''Return the value of id when we know the value of another message in the dictionary /json list.
        
        :param jsondata: the JSON string or dict or list,which is iterable
        
        :param str msg: the message which is already known.
        
        :param str msg_value: the value of message.
        
        :returns: value(s) of x. If only one value got, return it, or else return
            matched values list.
            
        Note::
        
            the default type of message and value is string.
        
        Example::
        
        
        | ${device_id}=	| Get Id By Other Message | ${json} | equipmentName | E201201922294091 |
        
        '''
        id=''
        if not jsondata:
                print("jsondata is null,please check the response data")
        else:
                try:
                        if isinstance(jsondata,list):
                                for item in jsondata:
                                        #print(type(item))
                                        if isinstance(item,dict):
                                                if item[msg]==msg_value:
                                                        id=item['id']
                                        else:
                                                logger.info(item)
                                                logger.info('is not a dictionary')
                        return id
                except Exception as e:
                        logger.warn(e)
                        logger.warn('can not get id')
 def create_safari(
     self,
     desired_capabilities,
     remote_url,
     options=None,
     service_log_path=None,
     executable_path="/usr/bin/safaridriver",
 ):
     if remote_url:
         defaul_caps = webdriver.DesiredCapabilities.SAFARI.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if options or service_log_path:
         logger.warn(
             "Safari browser does not support Selenium options or service_log_path."
         )
     if not executable_path:
         executable_path = self._get_executable_path(webdriver.Safari)
     return webdriver.Safari(executable_path=executable_path,
                             **desired_capabilities)
Пример #45
0
 def remove_old_downloaded_builds(self, branch):
     filelist = [
         f for f in os.listdir("C:\Users\Administrator\Downloads")
         if f.endswith(".zip")
     ]
     for f in filelist:
         file = "C:\\Users\\Administrator\\Downloads\\" + f
         logger.warn("Removing file %s" % file)
         os.remove(file)
     if branch == "main":
         if os.path.exists(
                 'C:\\WebFramework\\automation-gapps\\builds\\latestbuild\\'
         ):
             shutil.rmtree(
                 "C:\\WebFramework\\automation-gapps\\builds\\latestbuild\\"
             )
     else:
         if os.path.exists(
                 'C:\\WFDevGCAL\\automation-gapps\\builds\\latestbuild\\'):
             shutil.rmtree(
                 "C:\\WFDevGCAL\\automation-gapps\\builds\\latestbuild\\")
Пример #46
0
 def acquire_value_set(self):
     """
     Reserve a set of values for this execution.
     No other process can reserve the same set of values while the set is
     reserved. Acquired value set needs to be released after use to allow
     other processes to access it.
     """
     if self._remotelib:
         try:
             while True:
                 value = self._remotelib.run_keyword(
                     'acquire_value_set', [self._my_id], {})
                 if value:
                     logger.info('Value set "%s" acquired' % value)
                     return value
                 time.sleep(0.1)
                 logger.debug('waiting for a value set')
         except RuntimeError:
             logger.warn('no connection')
             self.__remotelib = None
     return _PabotLib.acquire_value_set(self, self._my_id)
Пример #47
0
    def convert_yaml_to_dict(self, string):
        """Convert a yaml type string to a dictionary

        example:
        | ${yaml} | execute command | cat /etc/linksdwan/applied.yaml |
        | ${dict} | convert yaml to dict | ${yaml} |
        """
        # replace ~# if console output with prompt

        if ':~#' in string:
            string = re.sub(r'root@.*:~#', '', string)

        # replace console command if command existed in output
        if 'cat /etc/linksdwan/applied.yaml' in string:
            string = re.sub(r'cat /etc/linksdwan/applied.yaml', '', string)

        try:
            data = yaml.load(string.strip(), Loader=yaml.FullLoader)
            return data
        except Exception as e:
            logger.warn(e)
def exec_cmd(cmd,ignore_exception=False):
 
    """ execute command and return stdout output - None on error """
    try:
        false = False
        true = True
        logger.info("EXCECUTING COMMAND: %s" % cmd)
        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        response = process.communicate()
        response = eval(response[0])
        return response 
    except subprocess.CalledProcessError as e:
        # exit code -2 seen on ctrl+c interrupt
        if e.returncode < 0: sys.exit("\nExiting...\n")
        if ignore_exception: 
            logger.debug("error executing cmd: %s" % e)
            logger.debug("stderr: %s" % e.output)
            return None
        logger.warn("error executing cmd: %s" % cmd)
        logger.warn("%s" % e.output)
        raise e
Пример #49
0
    def get_image_from_zone(self, zone=None):
        """Returns the image from zone. Saves image to the screenshot folder as image_from_zone.png.
            Examples:
            | Get Number With Text From Zone | zone=[x  y  w  h]

        """

        if zone is None:
            raise Exception('Search zone should be passed as argument.')
        else:
            scr = ImageProcessor(self.error_handler,
                                 self.screenshot_folder)._screenshot(zone)
            try:
                if not os.path.exists(self.screenshot_folder):
                    os.makedirs(self.screenshot_folder)
                result = os.path.join(self.screenshot_folder,
                                      'image_from_zone.png')
                scr.save(result)
                return result
            except:
                LOGGER.warn('Could not get screenshot folder dir')
Пример #50
0
 def failure_occurred(self, origin_exc, trb_text):
     """Method that is executed when a keyword fails."""
     if self._running_on_failure_keyword or not self.run_on_failure_keyword:
         return
     try:
         self._running_on_failure_keyword = True
         if self.run_on_failure_keyword.lower() == "eyes abort":
             self.current_eyes.abort_async()
         else:
             BuiltIn().run_keyword(self.run_on_failure_keyword)
     except Exception as err:
         robot_logger.warn(
             "Keyword '{}' could not be run on failure: {}".format(
                 self.run_on_failure_keyword, err))
     finally:
         self._running_on_failure_keyword = False
         raise_from(
             EyesLibraryError(
                 "Failed to run EyesLibrary\n{}".format(trb_text)),
             origin_exc,
         )
Пример #51
0
 def login(self, email, password):
     try:
         url = '{}/login'.format(self.threatplaybook)
         response = _post_req(url=url, email=email, password=password)
         if response:
             if response.get('success'):
                 self.token = response.get('token')
                 logger.info(
                     msg='Login Success: {}'.format(response.get("token")))
             elif response.get('error'):
                 raise Exception(
                     "Invalid response while attempting to login: {}".
                     format(response.get('error')))
             else:
                 raise Exception(
                     "Invalid response while attempting to login")
         else:
             logger.warn(msg='Error while logging in')
             raise Exception("Invalid response while attempting to login")
     except BaseException:
         raise Exception("Exception while attempting to login")
Пример #52
0
    def head(self,
             alias,
             uri,
             headers=None,
             allow_redirects=None,
             timeout=None):
        """ **Deprecated- See Head Request now**
        Send a HEAD request on the session object found using the
        given `alias`
        ``alias`` that will be used to identify the Session object in the cache
        ``uri`` to send the HEAD request to

        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
        ``headers`` a dictionary of headers to use with the request
        """
        logger.warn("Deprecation Warning: Use Head Request in the future")
        session = self._cache.switch(alias)
        redir = False if allow_redirects is None else allow_redirects
        response = self._head_request(session, uri, headers, redir, timeout)

        return response
Пример #53
0
	def config_channel_reg(self, reg, vec):
		if reg < CH0 or reg > CH15:
			logger.warn('Invalid channel: {}'.format(reg))
		else:
			reg_masked = reg & 0x0f
			command = 0x00 | reg

			byte1 = (vec & 0xff00) >> 8
			byte2 = vec & 0x00ff

			setup_sel = vec & 0x7000
			rv = ad4112_get_setup_name(setup_sel)

			input_n = vec & 0x3ff
			rv2 = ad4112_get_input_name(input_n)

			logger.info('Configure channel (reg: 0x{:02x}), CH{} with {}/{} - command: 0x{:02x} 0x{:02x} 0x{:02x}'.
			            format(reg, reg_masked, rv2, rv, command, byte1, byte2))

			self.spi.mode = SPI_MODE_3
			self.spi.xfer2([command, byte1, byte2])
Пример #54
0
    def set_mouse_location(self, x, y):
        """Sets mouse position to (``x``, ``y``).

         Position is relative to application window top left.
        """
        window_location = self.state.window.Bounds.TopLeft
        x_target = int(x) + window_location.X
        y_target = int(y) + window_location.Y
        point = Point(x_target, y_target)
        Mouse.Instance.Location = point

        if int(x_target) != int(Mouse.Instance.Location.X):
            logger.warn(
                "Mouse X position tried to be set outside of the screen. Wanted: "
                + str(int(x_target)) + " result:" +
                str(Mouse.Instance.Location.X), True)
        if int(y_target) != int(Mouse.Instance.Location.Y):
            logger.warn(
                "Mouse Y position tried to be set outside of the screen. Wanted: "
                + str(y_target) + " result:" + str(Mouse.Instance.Location.Y),
                True)
Пример #55
0
 def create_phantomjs(self,
                      desired_capabilities,
                      remote_url,
                      options=None,
                      service_log_path=None,
                      executable_path='phantomjs'):
     warnings.warn(
         'SeleniumLibrary support for PhantomJS has been deprecated, '
         'please use headlesschrome or headlessfirefox instead.')
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.PHANTOMJS.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if options:
         logger.warn('PhantomJS browser does not support Selenium options.')
     if is_falsy(executable_path):
         executable_path = self._get_executable_path(webdriver.PhantomJS)
     return webdriver.PhantomJS(service_log_path=service_log_path,
                                executable_path=executable_path,
                                **desired_capabilities)
Пример #56
0
    def failure_occurred(self):
        """Method that is executed when a SeleniumLibrary keyword fails.

        By default, executes the registered run-on-failure keyword.
        Libraries extending SeleniumLibrary can overwrite this hook
        method if they want to provide custom functionality instead.
        """
        if self._running_on_failure_keyword or not self.run_on_failure_keyword:
            return
        try:
            self._running_on_failure_keyword = True
            if self.run_on_failure_keyword.lower() == "capture page screenshot":
                self.capture_page_screenshot()
            else:
                BuiltIn().run_keyword(self.run_on_failure_keyword)
        except Exception as err:
            logger.warn(
                f"Keyword '{self.run_on_failure_keyword}' could not be run on failure: {err}"
            )
        finally:
            self._running_on_failure_keyword = False
def _prettify_request(request, hide_auth=True):
        """Pretty prints the request for the supplied `requests.Request`
        object. Especially useful after having performed the request, in
        order to inspect what was truly sent. To access the used request
        on the `requests.Response` object use the `request` attribute.
        """
        if hide_auth:
            logger.warn(("Hiding the `Authorization' header for security "
                         "reasons. If you wish to display it anyways, pass "
                         "`hide_auth=False`."))
        result = ('{}\n{}\n{}\n\n{}{}'.format(
            '----------- REQUEST BEGIN -----------',
            request.method + ' ' + request.url,
            '\n'.join('{}: {}'.format(key, value)
                      for key, value in request.headers.items()
                      if not(key == 'Authorization' and hide_auth)),
            request.body,
            "\n"
            '------------ REQUEST END ------------'
        ))
        return result
Пример #58
0
    def put(
            self,
            alias,
            uri,
            data=None,
            headers=None,
            allow_redirects=None,
            timeout=None):
        """ **Deprecated- See Put Request now**

        Send a PUT request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the PUT request to

        ``headers`` a dictionary of headers to use with the request
        
        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``timeout`` connection timeout
        """
        logger.warn("Deprecation Warning: Use Put Request in the future")
        session = self._cache.switch(alias)
        data = self._utf8_urlencode(data)
        redir = True if allow_redirects is None else allow_redirects

        response = self._body_request(
            "put",
            session,
            uri,
            data,
            None,
            None,
            headers,
            redir,
            timeout)

        return response
Пример #59
0
    def __init__(self):
        global OS_CONFIG_PATH

        # try:
        self._robot_runmodule_dir = BuiltIn().get_variable_value(
            '${ROBOT_RUNMODULE_DIR}')
        if self._robot_runmodule_dir == "None":
            raise Exception("var: _robot_runmodule_dir is %s " %
                            self._robot_runmodule_dir)

        logger.warn("Loading %s " % self._robot_runmodule_dir)
        # global ROBOT_RUNMODULE_DIR
        print "DEBUG: In AutomationConfig init ***"
        if _platform == "linux" or _platform == "linux2":
            # linux
            OS_CONFIG_PATH = LINUX_ATF_CONFIG_PATH
        elif _platform == "darwin":
            OS_CONFIG_PATH = MAC_ATF_CONFIG_PATH
            # OS X
        elif _platform == "win32":
            # Windows...
            OS_CONFIG_PATH = WIN_ATF_CONFIG_PATH

        logger.warn("Loading %s robot parameters from %s\\%s: STARTED" %
                    (_platform, OS_CONFIG_PATH, self._robot_runmodule_dir))
        self.load_robot_automation_configs()
        logger.warn("Loading %s robot parameters from %s\\%s: COMPLETE" %
                    (_platform, OS_CONFIG_PATH, self._robot_runmodule_dir))
Пример #60
0
def wait_page_loaded():
    """Wait for webpage to be loaded.

    Examples
    --------
    .. code-block:: robotframework

        WaitPageLoaded

    Each keyword should have this in the beginning since it is crucial that
    page has been loaded fully.

    Monkeypatch this method to have different wait.
    """
    if CONFIG["DefaultDocument"]:
        driver = browser.get_current_browser()
        if driver is None:
            raise QWebDriverError("No browser open. Use OpenBrowser keyword"
                                  " to open browser first")
        try:
            driver.switch_to.default_content()
        except InvalidSessionIdException as ie:
            CONFIG.set_value("OSScreenshots", True)
            raise QWebBrowserError(
                "Browser session lost. Did browser crash?") from ie
        except (NoSuchWindowException, WebDriverException) as e:
            logger.warn(
                'Cannot switch to default context, maybe window is closed. Err: {}'
                .format(e))
            if any(s in str(e) for s in FATAL_MESSAGES):
                CONFIG.set_value("OSScreenshots", True)
                raise QWebBrowserError(e) from e
            driver.switch_to.default_content()
    timeout = CONFIG['XHRTimeout']
    if timeout.lower() == "none":
        return
    try:
        xhr.wait_xhr(timestr_to_secs(timeout))
    except (WebDriverException, QWebDriverError) as e:
        logger.info('Unable to check AJAX requests due error: {}'.format(e))