示例#1
0
 def __get_parsed_classes(self, field):
     classes = ParsedPageObjectClass.get_parsed_classes(self.__cur_po_class.file_path)
     if len(classes) > 0 and len(classes[0].methods) == 0:
         classes = []
     classes += [ParsedModule.get_parsed_module(tools)]
     if field:
         classes += ParsedMouseClass.get_parsed_classes()
         classes += ParsedBrowserClass.get_parsed_classes()
     return classes
示例#2
0
    def test_parsed_browser_class_contains_only_methods_with_element(self):
        parsed_class = ParsedBrowserClass.get_parsed_classes()[0]
        self.assertNotIn('webdriver_wait', parsed_class.methods)
        self.assertNotIn('execute_js', parsed_class.methods)

        self.assertIn('find_descendant', parsed_class.methods)
        self.assertIn('find_descendants', parsed_class.methods)
        self.assertIn('find_element', parsed_class.methods)
        self.assertIn('find_elements', parsed_class.methods)
        self.assertIn('type', parsed_class.methods)
        self.assertIn('get_attribute', parsed_class.methods)
        self.assertIn('get_text', parsed_class.methods)
        self.assertIn('wait_for_visible', parsed_class.methods)
        self.assertIn('get_title', parsed_class.methods)
        self.assertIn('get_current_url', parsed_class.methods)

        self.assertIn('switch_to_frame', parsed_class.methods)
        self.assertIn('switch_to_default_content', parsed_class.methods)
    def test_parsed_browser_class_contains_only_methods_with_element(self):
        parsed_class = ParsedBrowserClass.get_parsed_classes()[0]
        self.assertNotIn('webdriver_wait', parsed_class.methods)
        self.assertNotIn('execute_js', parsed_class.methods)

        self.assertIn('find_descendant', parsed_class.methods)
        self.assertIn('find_descendants', parsed_class.methods)
        self.assertIn('find_element', parsed_class.methods)
        self.assertIn('find_elements', parsed_class.methods)
        self.assertIn('type', parsed_class.methods)
        self.assertIn('get_attribute', parsed_class.methods)
        self.assertIn('get_text', parsed_class.methods)
        self.assertIn('wait_for_visible', parsed_class.methods)
        self.assertIn('get_title', parsed_class.methods)
        self.assertIn('get_current_url', parsed_class.methods)

        self.assertIn('switch_to_frame', parsed_class.methods)
        self.assertIn('switch_to_default_content', parsed_class.methods)
示例#4
0
    def append_method_call(self, field, method_name, method, arg_spec):
        is_po_class_file_selected = type(self) == PyFileUI
        # removing arguments with default value
        args = arg_spec.args
        if arg_spec.defaults:
            args = args[:-len(arg_spec.defaults)]

        # removing 'self' argument
        self_txt = 'self'
        if self_txt in args:
            args.remove(self_txt)

        po_class = self.grandparent.get_current_pageobject_class()
        lowered_class_name = po_class.name.lower()

        is_assert_method = method_name.startswith('assert')
        is_browser_method = method_name in ParsedBrowserClass.get_parsed_classes(
        )[0].methods
        is_mouse_method = method_name in ParsedMouseClass.get_parsed_classes(
        )[0].methods
        is_page_object_method = method_name in ParsedPageObjectClass.get_parsed_classes(
            po_class.file_path)[0].methods

        # replacing 'element' with correctly formatted string - self.obj.field
        element_txt = 'element'
        if element_txt in args:
            element_index = args.index(element_txt)
            if is_po_class_file_selected:
                args[element_index] = u"self.%s" % field.name
            else:
                args[element_index] = u"self.%s.%s" % (lowered_class_name,
                                                       field.name)

        if is_browser_method:
            caller = 'self.browser'
        elif is_mouse_method:
            caller = 'self.browser.mouse'
        elif is_page_object_method and not is_po_class_file_selected:
            caller = 'self.' + lowered_class_name
        elif is_assert_method:
            caller = None
        else:
            caller = 'self'

        get_prefix = 'get_'
        is_getter_method_and_no_args = method_name.startswith(get_prefix)
        method_kwargs = {}
        if is_getter_method_and_no_args:
            var = method_name.replace(get_prefix, '')
            method_call_template = u"        {var} = {caller}.{method}({method_args})" + LINESEP
            method_kwargs['var'] = var
        elif caller is None:
            method_call_template = u"        {method}({method_args})" + LINESEP
        else:
            method_call_template = u"        {caller}.{method}({method_args})" + LINESEP

        if (len(args) > 1 and (is_browser_method or is_mouse_method)
                or len(args) > 0 and
            (is_assert_method or is_page_object_method)):
            if is_assert_method or is_page_object_method:
                dialog = MultipleTextEntry(self, 'Please enter values', args)
            else:
                dialog = MultipleTextEntry(self, 'Please enter values',
                                           args[1:])
            if dialog.ShowModal() == ID_OK:
                for name, value in dialog.values.items():
                    args[args.index(name)] = value
                method_kwargs.update({
                    'caller': caller,
                    'method': method_name,
                    'method_args': u', '.join(args)
                })
                code_line = method_call_template.format(**method_kwargs)
                code = self.txt_content.GetValue() + LINESEP + code_line
                root_folder = self.GetTopLevelParent().get_root_folder()
                formatted_exception = check_py_code_for_errors(
                    code, root_folder)

                if formatted_exception:
                    show_dialog(self, formatted_exception,
                                u'Values are not Python expressions')
                else:
                    method_kwargs.update({
                        'caller': caller,
                        'method': method_name,
                        'method_args': u', '.join(args)
                    })
                    self.append_text(
                        method_call_template.format(**method_kwargs))
        else:
            method_kwargs.update({
                'caller': caller,
                'method': method_name,
                'method_args': u', '.join(args)
            })
            self.append_text(method_call_template.format(**method_kwargs))
示例#5
0
    def append_method_call(self, field, method_name, method, arg_spec):
        is_po_class_file_selected = type(self) == PyFileUI
        # removing arguments with default value
        args = arg_spec.args
        if arg_spec.defaults:
            args = args[:-len(arg_spec.defaults)]

        # removing 'self' argument
        self_txt = 'self'
        if self_txt in args:
            args.remove(self_txt)

        po_class = self.grandparent.get_current_pageobject_class()
        lowered_class_name = po_class.name.lower()

        is_assert_method = method_name.startswith('assert')
        is_browser_method = method_name in ParsedBrowserClass.get_parsed_classes()[0].methods
        is_mouse_method = method_name in ParsedMouseClass.get_parsed_classes()[0].methods
        is_page_object_method = method_name in ParsedPageObjectClass.get_parsed_classes(po_class.file_path)[0].methods

        # replacing 'element' with correctly formatted string - self.obj.field
        element_txt = 'element'
        if element_txt in args:
            element_index = args.index(element_txt)
            if is_po_class_file_selected:
                args[element_index] = u"self.%s" % field.name
            else:
                args[element_index] = u"self.%s.%s" % (lowered_class_name, field.name)

        if is_browser_method:
            caller = 'self.browser'
        elif is_mouse_method:
            caller = 'self.browser.mouse'
        elif is_page_object_method and not is_po_class_file_selected:
            caller = 'self.' + lowered_class_name
        elif is_assert_method:
            caller = None
        else:
            caller = 'self'

        get_prefix = 'get_'
        is_getter_method_and_no_args = method_name.startswith(get_prefix)
        method_kwargs = {}
        if is_getter_method_and_no_args:
            var = method_name.replace(get_prefix, '')
            method_call_template = u"        {var} = {caller}.{method}({method_args})" + LINESEP
            method_kwargs['var'] = var
        elif caller is None:
            method_call_template = u"        {method}({method_args})" + LINESEP
        else:
            method_call_template = u"        {caller}.{method}({method_args})" + LINESEP

        if (len(args) > 1 and (is_browser_method or is_mouse_method) or len(args) > 0 and (
            is_assert_method or is_page_object_method)):
            if is_assert_method or is_page_object_method:
                dialog = MultipleTextEntry(self, 'Please enter values', args)
            else:
                dialog = MultipleTextEntry(self, 'Please enter values', args[1:])
            if dialog.ShowModal() == ID_OK:
                for name, value in dialog.values.items():
                    args[args.index(name)] = value
                method_kwargs.update({'caller': caller,
                                      'method': method_name,
                                      'method_args': u', '.join(args)})
                code_line = method_call_template.format(**method_kwargs)
                code = self.txt_content.GetValue() + LINESEP + code_line
                root_folder = self.GetTopLevelParent().get_root_folder()
                formatted_exception = check_py_code_for_errors(code, root_folder)

                if formatted_exception:
                    show_dialog(self,
                                formatted_exception,
                                u'Values are not Python expressions')
                else:
                    method_kwargs.update({'caller': caller,
                                          'method': method_name,
                                          'method_args': u', '.join(args)})
                    self.append_text(method_call_template.format(**method_kwargs))
        else:
            method_kwargs.update({'caller': caller,
                                  'method': method_name,
                                  'method_args': u', '.join(args)})
            self.append_text(method_call_template.format(**method_kwargs))