Пример #1
0
 def get_next_slot_text(self, slot_name, slot_required):
     try:
         types_with_options = u.choices_type_list
         slot = self.get_slot(slot_name)
         useful_info = ''
         value_type = slot[u.value_type]
         required_string = fn.get_required_string(slot_required)
         if value_type in types_with_options:
             choice_list = slot[u.choice_list]
             option_string = fn.get_string_from_list(choice_list)
             if value_type in [u.dropdown, u.checkbox]:
                 string = f"Select the {slot_name} in the following list {option_string}. {required_string}"
             elif value_type == u.radio:
                 string = f"Choose your {slot_name} in the following list {option_string}. {required_string}"
             if u.DEBUG:
                 print("choice list")
                 print(choice_list)
         else:
             # we construct some useful info.
             if value_type in [u.number, u.decimal, u.integer]:
                 useful_info = f'\nThe value should be a number between {slot[u.min_value]} and {slot[u.max_value]}.'
             insert_style = styles.get_insert()
             please_style = styles.get_please()
             string = f"{please_style} {insert_style} the {slot_name}. {required_string}"
         string = f'{string}{useful_info}'
         return string
     except:
         print("ERROR: Fail to extract the text for the next slot")
         raise Exception
Пример #2
0
 def submitForm(self):
     try:
         remaining_required = self.state.get_fields_list(remaining=True,
                                                         only_required=True)
         # we first verify if all the required fields are filled
         if len(remaining_required) > 0:
             # at least one required field is still empty
             initial_string = 'Not all the required fields are completed.'
             next_step_string = self.state.manage_next_step()
             if len(remaining_required) == 1:
                 string = f'{initial_string}\nYou should complete the field {remaining_required[0]}.\n{next_step_string}'
             elif len(remaining_required) > 1:
                 string_fields = fn.get_string_from_list(remaining_required)
                 string = f"{initial_string}\nYou still have to complete the following required fields {string_fields}.\n{next_step_string}"
             return string
         if u.DEBUG or not self.state.get_all_required_filled():
             print("inside submitForm")
         if not self.state.get_submit_alarm_enabled():
             recap = fn.get_pairs(self.state.form_slots())
             string = f"\n{recap}\nIf you would like to change something, let me know, otherwise confirm that you really want to continue with the submission?"
             self.state.set_possible_next_action(u.submit_action)
             # we enable the alarm
             self.state.set_submit_alarm_enabled()
             return string
         # we disable the alarm
         self.state.set_submit_alarm_enabled(False)
         elem = self.state.get_submit_button()
         elem.click()
         # we verify if the submission effectively occured
         try:
             # The point here is to avoid the Web Form to be submitted in the internal structure
             # without being effectively submitted. It could be a matter of seconds so we put a sleep.
             elem = self.state.get_submit_button(verification=True)
             time.sleep(10)
             self.state.get_submit_button(verification=True).click()
             string = 'verification'
             if u.DEBUG:
                 print(string)
         except:
             # submission effective
             # we signify that the submit is done to have the title page
             self.state.set_submit_done()
             self.state.set_possible_next_action(None)
             string = 'Submission done'
             return string
         # submission not effective
         string = (
             'The submission is not effective due to a not valid value for a field. We advice you to restart the process from the beginning'
             + '\nDo you accept to restart the process from the beginning?')
         self.state.set_reset_alarm_enabled()
         self.state.set_possible_next_action(u.reset_all_fields_action)
         return string
     except:
         if not self.state.get_warning_present():
             print(
                 "A problem occured while a registration form bot tries to submit a form"
             )
         raise Exception
Пример #3
0
    def fillForm(self):
        try:
            # if the filling did not start, we give the form info to the user, otherwise we continue
            # with the next input_field.state variables to observe are num_camps, num_remaining, ...

            # we start by checking if the filling already started or not
            if self.state.get_filling_started():
                if self.state.get_close_prompt_enabled():
                    # we set the message to be returned to the user
                    string = fn.next_char_string()
                    self.state.set_possible_next_action(u.spelling_action)
                else:
                    string = self.state.manage_next_step()
                    _, required = self.state.get_next_slot()
                    if not required:
                        string = f'{string} otherwise, you can {u.fun_all_fields}, {u.fun_remaining_required_fields} or {u.fun_skip} '
                    else:
                        string = f'{string} otherwise, you can {u.fun_modify_field}'
                    already_filled = fn.get_pairs(self.state.form_slots(),
                                                  only_filled=True)
                    fields_to_complete = self.state.get_fields_list(
                        remaining=True)
                    if len(fields_to_complete) > 0:
                        if already_filled != '':
                            string = f'You are filling a Web Form and you still have to complete the following fields {fields_to_complete}.\nHere are the fields that you already completed:\n{already_filled}.\n{string}'
                        else:
                            string = f'You are filling a Web Form and you still have to complete the following fields {fields_to_complete}.\n{string}'
                return string
            # the filling did not start
            self.state.set_filling_started()
            form_title = self.state.get_form_title()
            if form_title is None:
                form_intro = "This form does not have a title."
            else:
                form_intro = f"The title of this form is {form_title}."
            form_desc = self.state.get_form_description()
            if form_desc is None:
                desc_intro = "it does not have a description."
            else:
                desc_intro = f"{form_desc}."
            # we format the string to retrieve
            first_string = self.state.manage_next_step()
            list_fields = self.state.get_fields_list()
            string_fields = fn.get_string_from_list(list_fields)
            string = (
                f"{form_intro} {desc_intro} this form contains the following fields: {string_fields}, from which {self.state.num_required_fields} are required"
                +
                f" and {self.state.num_optional_fields} are optional.\nhere we go:\n{first_string}"
            )
            return string
        except:
            if not self.state.get_warning_present():
                print(
                    "A problem occured while a registration form bot tries to start filling the form"
                )
            raise Exception
Пример #4
0
 def repeatAllFields(self):
     try:
         all_fields = self.state.get_fields_list()
         string_fields = fn.get_string_from_list(all_fields)
         ans = f"The fields present in this form are the following: {string_fields}."
         next_step_string = self.state.manage_next_step()
         string = f"{ans}\n{next_step_string}"
         return string
     except:
         if not self.state.get_warning_present():
             print(
                 "A problem occured while a registration form bot tries to repeat all the labels"
             )
         raise Exception
Пример #5
0
 def set_choices_checkbox(self, slot_name, choice_values):
     try:
         slot = self.get_slot(slot_name)
         choice_name = slot[u.value_name].lower()
         choices_lower = []
         for choice_value in choice_values:
             choices_lower.append(choice_value.lower())
         elems = self.form_element.find_elements_by_name(choice_name)
         value_present = False
         for elem in elems:
             value = elem.get_attribute("value")
             if value in choices_lower:
                 if not elem.is_selected():
                     elem.click()
                     value_present = True
             else:
                 if elem.is_selected():
                     elem.click()
                     value_present = True
         if not value_present:
             choices_string = fn.get_string_from_list(choice_values)
             sorry_style = styles.get_sorry()
             please_style = styles.get_please()
             text = (
                 f"{sorry_style} none of the choices {choices_string} you proposed is valid for the field {slot_name}"
                 +
                 f"{please_style} choose them in the following list: {choice_list}"
             )
             self.set_warning_message(text)
             raise Exception
     except:
         if not self.get_warning_present():
             choices_list = fn.get_string_from_list(choice_values)
             print(
                 f"ERROR: A problem occured while trying to set the choices {choices_list} in the checkbox with name {choice_name}"
             )
         raise Exception
Пример #6
0
 def giveAllRemainingFields(self):
     try:
         sure_style = styles.get_sure()
         all_remaining_fields = self.state.get_fields_list(remaining=True)
         if len(all_remaining_fields) == 0:
             ans = 'There is no field remaining'
         elif len(all_remaining_fields) == 1:
             ans = f'There is one field remaining and it is {all_remaining_fields[0]}'
         else:
             string_fields = fn.get_string_from_list(all_remaining_fields)
             ans = f"{sure_style} the remaining fields present in this form are the following: {string_fields}."
         string = self.state.manage_next_step()
         string = f'{ans}\n{string}'
         return string
     except:
         if not self.state.get_warning_present():
             print(
                 "A problem occured while a registration form bot tries to give all the remaining labels"
             )
         raise Exception
Пример #7
0
 def repeatOptionalFields(self):
     try:
         sure_style = styles.get_sure()
         optional_list = []
         slots = self.state.form_slots()
         for slot in slots:
             if slot[u.slot_name] != u.REQUESTED_SLOT:
                 if not slot[u.required]:
                     optional_list.append(slot[u.slot_name])
         optional_fields = fn.get_string_from_list(optional_list)
         ans = f"{sure_style} the optional fields are the following {optional_fields}."
         string = self.state.manage_next_step()
         string = f"{ans}\n{string}"
         return string
     except:
         if not self.state.get_warning_present():
             print(
                 "A problem occured while a registration form bot tries to repeat optional labels"
             )
         raise Exception
Пример #8
0
 def repeatRequiredFields(self):
     try:
         sure_style = styles.get_sure()
         required_fields = self.state.get_fields_list(only_required=True)
         if len(required_fields) == 0:
             ans = 'There is no required field in this form'
         elif len(required_fields) == 1:
             ans = f'There is one required field in this form which is {required_fields[0]}'
         else:
             string_fields = fn.get_string_from_list(required_fields)
             ans = f"{sure_style} the required fields are the following: {string_fields}."
         string = self.state.manage_next_step()
         string = f"{ans}\n{string}"
         return string
     except:
         if not self.state.get_warning_present():
             print(
                 "A problem occured while a registration form bot tries to repeat Required labels"
             )
         raise Exception
Пример #9
0
 def giveRemainingOptionalFields(self):
     try:
         sure_style = styles.get_sure()
         remaining_optional_list = []
         slots = self.state.form_slots()
         for slot in slots:
             if slot[u.slot_name] != u.REQUESTED_SLOT:
                 if not slot[u.required]:
                     if slot[u.slot_value] is None:
                         # we add remaining optional fields
                         remaining_optional_list.append(slot[u.slot_name])
         optional_fields = fn.get_string_from_list(remaining_optional_list)
         ans = f"{sure_style} the remaining optional fields are the following {optional_fields}."
         next_step_string = self.state.manage_next_step()
         string = f'{ans}\n{next_step_string}'
         return string
     except:
         if not self.state.get_warning_present():
             print(
                 "A problem occured while a registration form bot tries to give the remaining optional labels"
             )
         raise Exception
Пример #10
0
 def all_fields_present(self, slot_name_list):
     try:
         # returns True if all the fields are present and False otherwise. In ca of false retruns also the next_step string
         string = ''
         for slot_name in slot_name_list:
             present = fn.verify_presence(slot_name.lower(),
                                          self.form_slots(),
                                          only_presence=True)
             if not present:
                 sorry_style = styles.get_sorry()
                 list_fields = self.get_fields_list()
                 string_fields = fn.get_string_from_list(list_fields)
                 text = (
                     f"{sorry_style} the field {slot_name} is not present in this form.\nThe fields of this form are"
                     + f" the following: {string_fields}")
                 next_step_string = self.manage_next_step()
                 string = f'{text}\n{next_step_string}'
                 return False, string
         return True, string
     except:
         if not self.get_warning_present():
             print('ERROR: Fail to verify presence of all fields')
         raise Exception
Пример #11
0
    def fillSpellingField(self):
        try:
            if len(self.state.get_spelling_list()) == 0:
                # misinterpretation
                text = 'I did not get you well, could you precise your action please?'
                _, required = self.state.get_next_slot()
                if not required:
                    text = f'{text} otherwise, you can {u.fun_skip}, {u.fun_reset} or {u.fun_submit}'
                else:
                    text = f'{text} otherwise, you can {u.fun_remaining_fields} or {u.fun_modify_field}'
                self.state.set_warning_message(text)
                raise Exception
            # we have to verify if we just finished the spelling of a field
            if self.state.get_after_spelling():
                # after spelling is desabled since we are going to insert the vale for a field
                self.state.set_after_spelling(False)
                slot_name = self.state.get_next_slot(only_name=True)
                slot_value = self.state.get_current_spelling_input_value()
                # we go to the filling procedure. The spelling list can be modified in this phase
                string = self.state.filling_procedure(slot_name, slot_value)
                if 'inserted!' in string.lower() and 'not' in string.lower():
                    self.state.reset_current_spelling_input_value()
                    return string
                # verify if all the fields in spelling list have been completed
                if len(self.state.get_spelling_list()) - 1 == 0:
                    self.state.reset_spelling_list()
                else:
                    # there are still fields to spell
                    self.state.update_spelling_list(slot_name)
                    next_field = self.state.get_spelling_list()[0]
                    please_style = styles.get_please()
                    string = (
                        f"Web Form updated. Now you are going to spell the value for the field {next_field}.\n"
                        + f"{please_style} insert the first character")
                # after the spelling we insert the value for the given field and we reset the string
                self.state.reset_current_spelling_input_value()
                return string
            """we are not after spelling so the fillGenericField directly called this function(at the
            previous step it was triggered by the spelling function) or it is triggered by
            the mofifySpellingField function"""

            # we look if one of the fields in spelling fields has been saved to resume it. In case of many fields saved we take the first
            slot_name_list = self.state.get_spelling_list()
            saved_fields = self.state.get_saved_spelling_fields()
            if len(saved_fields) > 0:
                # there is at least one saved field
                for field in slot_name_list:
                    if field in saved_fields:
                        string = self.state.resume_spelling(field)
                        return string
            # we set the first spelling field of the list as the next field
            slot_name = slot_name_list[0]
            self.state.set_next_slot(slot_name)
            # we add styles to the output
            please_style = styles.get_please()
            end_style = styles.get_end()
            fields_string = fn.get_string_from_list(slot_name_list)
            if len(slot_name_list) == 1:
                intro = f"You will have to spell the value of the field {slot_name_list[0]}."
            else:
                intro = (
                    f"You will have to spell the values of the following fields {fields_string}.\n"
                    + f"We start by the field {slot_name_list[0]}.")
            # we set the message to be returned to the user
            string = (
                f'{intro}\n{please_style} insert the first character, you will be able to use SPACE for spacing'
                + f'and TERMINATE to {end_style} the spelling')
            self.state.set_possible_next_action(u.spelling_action)
            return string
        except:
            if not self.state.get_warning_present():
                print(
                    "A problem occured while a registration form bot tries to fill a spelling camp"
                )
            raise Exception