当前位置: 首页>>代码示例>>Python>>正文


Python BuiltIn.run_keyword方法代码示例

本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn.run_keyword方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn.run_keyword方法的具体用法?Python BuiltIn.run_keyword怎么用?Python BuiltIn.run_keyword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在robot.libraries.BuiltIn.BuiltIn的用法示例。


在下文中一共展示了BuiltIn.run_keyword方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DebugCmd

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword [as 别名]
class DebugCmd(BaseCmd):
    '''Interactive debug shell'''

    def __init__(self, completekey='tab', stdin=None, stdout=None):
        '''Becase raw_input using sys.stdout that RobotFramework captured,
        the prompt of Cmd is missing unless use the __stdout__'''

        BaseCmd.__init__(self, completekey, stdin, stdout)
        self.stdout = sys.__stdout__
        self.prompt = ''
        self.use_rawinput = True
        self.rf_bi = BuiltIn()

    def postcmd(self, stop, line):
        '''run after a command'''

        # print prompt
        self.stdout.write('> ')
        return stop

    def do_selenium(self, arg):
        '''initialized selenium environment, a shortcut for web test'''

        self.stdout.write('import library  SeleniumLibrary\n')
        self.rf_bi.run_keyword('import library', 'SeleniumLibrary')
        self.stdout.write('start selenium server\n')
        self.rf_bi.run_keyword('start selenium server')
        self.rf_bi.run_keyword('sleep', '2')
        if arg:
            url = arg
        else:
            url = 'http://www.google.com/'
        self.stdout.write('open browser  %s\n' % url)
        self.rf_bi.run_keyword('open browser', url)

    def help_selenium(self):
        '''Help of Selenium command'''

        self.stdout.write('Start a selenium server, ')
        self.stdout.write('and open google.com or other url in browser.\n')

    def default(self, line):
        '''Run RobotFramework keywords'''

        command = line.strip()
        if not command:
            return
        try:
            keyword = KEYWORD_SEP.split(command)
            result = self.rf_bi.run_keyword(*keyword)
            if result:
                output('< ', repr(result), '\n')
        except HandlerExecutionFailed, exc:
            output('< keyword: ', command, '\n')
            output('! ', exc.full_message, '\n')
        except Exception, exc:
            output('< keyword: ', command, '\n')
            output('! FAILED: ', repr(exc), '\n')
开发者ID:bubenkoff,项目名称:robotframework-debuglibrary,代码行数:60,代码来源:DebugLibrary.py

示例2: DebugCmd

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword [as 别名]
class DebugCmd(Cmd):
    """Interactive debug shell
    """

    use_rawinput = True
    prompt = '>>> '

    def __init__(self, completekey='tab', stdin=None, stdout=None):
        Cmd.__init__(self, completekey, stdin, stdout)
        self.rf_bi = BuiltIn()

    def default(self, line):
        """Run RobotFramework keywords
        """
        pattern = re.compile('  +|\t')
        command = line.strip()
        if not command:
            return
        try:
            keyword = pattern.split(command)
            result = self.rf_bi.run_keyword(*keyword)
            if result:
                print repr(result)
        except HandlerExecutionFailed, exc:
            print 'keyword: ', command
            print '! ', exc.full_message
        except Exception, exc:
            print 'keyword: ', command
            print '! FAILED: ', repr(exc)
开发者ID:FonPhannida,项目名称:robotx,代码行数:31,代码来源:DebugLibrary.py

示例3: DebugCmd

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword [as 别名]
class DebugCmd(BaseCmd):
    '''Interactive debug shell'''

    use_rawinput = True
    prompt = '> '

    def __init__(self, completekey='tab', stdin=None, stdout=None):
        BaseCmd.__init__(self, completekey, stdin, stdout)
        self.rf_bi = BuiltIn()

    def postcmd(self, stop, line):
        '''run after a command'''
        return stop

    def do_selenium(self, arg):
        '''initialized selenium environment, a shortcut for web test'''

        print('import library  SeleniumLibrary')
        self.rf_bi.run_keyword('import library', 'SeleniumLibrary')
        print('start selenium server')
        self.rf_bi.run_keyword('start selenium server')
        self.rf_bi.run_keyword('sleep', '2')
        if arg:
            url = arg
        else:
            url = 'http://www.google.com/'
        print('open browser  %s' % url)
        self.rf_bi.run_keyword('open browser', url)

    def help_selenium(self):
        '''Help of Selenium command'''
        print('Start a selenium server, and open google.com or other url in browser.')

    def default(self, line):
        '''Run RobotFramework keywords'''
        command = line.strip()
        if not command:
            return
        try:
            u_command = command.decode("utf-8")
            keyword = KEYWORD_SEP.split(u_command)
            result = self.rf_bi.run_keyword(*keyword)
            if result:
                print('< ', repr(result))
        except HandlerExecutionFailed as exc:
            print('< keyword: %s' % command)
            print('! %s' % exc.full_message)
        except Exception as exc:
            print('< keyword: %s' % command)
            print('! FAILED: %s' % repr(exc))
开发者ID:neithere,项目名称:robotframework-debuglibrary,代码行数:52,代码来源:DebugLibrary.py

示例4: _wait_until_keyword_returns_true

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword [as 别名]
 def _wait_until_keyword_returns_true(self, timeout, retry_interval, name, *args):
     """Helper method for wait_until_page_contains"""
     timeout = timestr_to_secs(timeout)
     retry_interval = timestr_to_secs(retry_interval)
     starttime = time.time()
     while time.time() - starttime < timeout:
         try:
             self._info("Waiting %s for condition '%s' to be true." 
                 % (secs_to_timestr(timestr_to_secs(retry_interval)), args[0]))  
             if not BuiltIn.run_keyword(BuiltIn(), name, *args):
                 time.sleep(retry_interval)
             else:
                 self._info("Return True in '%s' " % (secs_to_timestr(time.time() - timestr_to_secs(starttime))))
                 return True              
         except Exception:
             time.sleep(retry_interval)
     raise AssertionError("did not become true")
开发者ID:AlexGreat007,项目名称:wikia,代码行数:19,代码来源:wb_actions.py

示例5: ExtendedSelenium2Library

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword [as 别名]

#.........这里部分代码省略.........
        self._wait_until_page_ready()
        self.wait_until_angular_ready()

    def _element_trigger_change(self, locator):
        """Trigger change event on target element when AngularJS is ready."""
        element = self._element_find(locator, True, True)
        if element is None:
            raise AssertionError("Element '%s' not found." % locator)
        if self._is_angular_control(element):
            # you will operating in different scope
            script = self.NG_WRAPPER % {'prefix': 'var obj=arguments[0];',
                                        'handler': 'function(){$(obj).trigger(\'change\').'
                                                   'trigger(\'focusout\')}',
                                        'suffix': ''}
            self._current_browser().execute_script(script, element)
            self._wait_until_page_ready()
            self.wait_until_angular_ready()
        else:
            self._wait_until_page_ready()

    def _get_browser_name(self):
        """Returns current browser name."""
        return self._current_browser().capabilities['browserName'].strip().lower()

    def _input_text_into_text_field(self, locator, text):
        """Send keys to text field with AngularJS synchronization."""
        super(ExtendedSelenium2Library, self)._input_text_into_text_field(locator, text)
        element = self._element_find(locator, True, True)
        if self._is_angular_control(element):
            self._wait_until_page_ready()
            self.wait_until_angular_ready()

    def _is_angular_control(self, element):
        """Returns true if target element is an AngularJS control, otherwise false."""
        if self._is_angular_page():
            return element.get_attribute('data-ng-model') != '' \
                or element.get_attribute('ng-model') != ''
        else:
            return False

    def _is_angular_page(self):
        """Returns true if current page is an AngularJS page, otherwise false."""
        script = 'return !!window.angular'
        try:
            return self._current_browser().execute_script(script)
        except:
            self._debug(exc_info()[0])
            return False

    def _is_internet_explorer(self, browser_name=None):
        """Returns true if current browser is Internet Explorer."""
        if not browser_name:
            browser_name = self._get_browser_name()
        return browser_name == 'internetexplorer' or browser_name == 'ie'

    def _scroll_into_view(self, locator):
        """Scroll target element into view. (Internet Explorer only)."""
        if self._is_internet_explorer():
            element = self._element_find(locator, True, True)
            if element is None:
                raise AssertionError("Element '%s' not found." % locator)
            script = 'arguments[0].scrollIntoView(false)'
            self._current_browser().execute_script(script, element)

    def _select_checkbox_or_radio_button(self, element):
        """Select checkbox or radio button with AngularJS support."""
        if self._is_angular_control(element):
            self._angular_select_checkbox_or_radio_button(element)
        else:
            element.click()
            self._wait_until_page_ready()

    def _wait_until_page_ready(self, timeout=None):
        """Semi blocking API that incorporated different strategies for cross-browser support."""
        if self._block_until_page_ready:
            delay = self._browser_breath_delay
            if delay < 1:
                delay *= 10
            # let the browser take a deep breath...
            sleep(delay)
            timeout = self._implicit_wait_in_secs \
                if timeout is None else utils.timestr_to_secs(timeout)
            browser = self._current_browser()
            try:
                WebDriverWait(None, timeout, self._poll_frequency).\
                    until_not(staleness_of(browser.find_element_by_tag_name('html')), '')
            except:
                # instead of halting the process because document is not ready
                # in <TIMEOUT>, we try our luck...
                self._debug(exc_info()[0])
            try:
                WebDriverWait(browser, timeout, self._poll_frequency).\
                    until(lambda driver: driver.
                          execute_async_script(self._page_ready_bootstrap), '')
            except:
                # instead of halting the process because document is not ready
                # in <TIMEOUT>, we try our luck...
                self._debug(exc_info()[0])
            for keyword in self._page_ready_keyword_list:
                self._builtin.run_keyword(keyword)
开发者ID:rama-bornfree,项目名称:robotframework-extendedselenium2library,代码行数:104,代码来源:__init__.py

示例6: get_variables

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword [as 别名]
def get_variables(testDataFile, testDataFileType="local"):
    robotBuiltIn = BuiltIn()
    #oraConnection = OracleLibrary.keywords()

    robotBuiltIn.log("Importing Data File: %s" % testDataFile)

    if testDataFileType == "env":
        envData = _open_yaml_file(testDataFile)
        variables = {}

        # Following Code adds the servers from each group to the Global Variables DICT
        if "applicationGroups" in envData:
            for applicationGroup in envData['applicationGroups'].keys():
                variables["LIST__" + applicationGroup] = envData['applicationGroups'][applicationGroup]['servers'].keys()
                for value, server in enumerate(envData['applicationGroups'][applicationGroup]['servers'].keys()):
                    variables[applicationGroup + str(value)] = server

        # The following Code will parse for environment variables and it them to the Global Variables DICT
        if "environment" in envData:
            for envVarKey, envVarValue in envData['environment'].items():
                if isinstance(envVarValue, basestring) or isinstance(envVarValue, dict):
                    variables[envVarKey] = envVarValue
                if isinstance(envVarValue, list):
                    variables["LIST__" + envVarKey] = envVarValue

    else:
        variables = _open_yaml_file(testDataFile)
        patternSQL = re.compile(r'''^SELECT(.+?)WHERE''', re.UNICODE |
                                                          re.VERBOSE)

        patternRFVar = re.compile(r'''\${(.*?)}''', re.UNICODE |
                                                    re.VERBOSE |
                                                    re.S)

        patternRFKeyword = re.compile(r'''\Get.Data''', re.UNICODE |
                                                        re.VERBOSE)

        for key, item in variables.items():

            """
            THIS CODE IS USED FOR SQL EXECUTION.
            DUE TO CROSS PLATFORM ISSUES THIS HAS BEEN DISABLED.

            if isinstance(item, list):
                dbName = item[0]
                dbQuery = item[1]

                if patternSQL.match(dbQuery): # If an SQL pattern is found, then run it to get the data
                    if patternRFVar.search(dbQuery):
                        for match in patternRFVar.finditer(dbQuery):
                            rfVarValue = robotBuiltIn.get_variable_value(match.group(0))
                            dbQuery = dbQuery.replace(match.group(0), rfVarValue)

                    result = oraConnection.ora_execute_sql(dbQuery, dbName)

                    if isinstance(result, basestring):
                        variables[key] = result

                    if isinstance(result, list):
                        del variables[key] # Delete the key from the dict
                        listKey = "LIST__" + key # Create a new key with LIST__ at the front

                        # The returned result set from the oracle query is not in the correct format
                        # The below code corrects the format.
                        resultList = []
                        for resultLine in result:
                            for resultLineItem in resultLine:
                                resultList.append(resultLineItem)

                        variables[listKey] = resultList # Updates the dict with the results and new key value
            """
            if isinstance(item, basestring):
                if patternRFVar.search(item):
                    rfVar = patternRFVar.search(item).group()
                    rfVarValue = robotBuiltIn.get_variable_value(rfVar)
                    variables[key] = item.replace(rfVar, rfVarValue)
                    item = variables[key]

                if patternRFKeyword.match(item):
                    itemList = item.split("|")
                    keywordName = itemList[0]
                    itemList.pop(0)
                    itemListLen = len(itemList)

                    if itemListLen == 0:
                        results = robotBuiltIn.run_keyword(keywordName)
                    else:
                        results = robotBuiltIn.run_keyword(keywordName, *itemList)

                    if isinstance(results, basestring):
                        variables[key] = results

                    if isinstance(results, list):
                        del variables[key]
                        listKey = "LIST__" + key
                        variables[listKey] = results

    return variables
开发者ID:jbarnes007,项目名称:robotframework-yamlvariableslibrary,代码行数:100,代码来源:_keywords.py


注:本文中的robot.libraries.BuiltIn.BuiltIn.run_keyword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。