Exemple #1
0
class Close(BasePage):
    def __init__(self, driver: WebDriver):
        """ Close NCR E2E Actions """
        super().__init__(driver)
        self.login_page = LoginPage(self._driver)
        self.home_page = HomePage(self._driver)
        self.close_requests = CloseRequests(self._driver)
        self.create_requests = CreateRequests(self.close_requests._driver)

    def closeRequest(self):
        # Login to the Page
        self.login_page.enter_username_textbox()
        self.login_page.enter_password_textbox()
        self.login_page.click_login_button()
        # Parse all the change number from home page
        all_changes_list = self.home_page.get_all_change_numbers()
        # Parse all the closing change request shared by user
        user_list_for_close = make_data.list_of_change(
            StaticData.CLOSE_CHANGE_TXT_FILE_PATH)
        tasks = len(user_list_for_close)
        ClosePrettify.make_layout()
        ClosePrettify.make_table()
        my_progress = ClosePrettify.progress_bar(tasks)
        ClosePrettify.merge_layout(my_progress, ClosePrettify.get_table())
        print(user_list_for_close)
        # Iterate through each user shared Change Number
        with Live(ClosePrettify.get_layout(),
                  refresh_per_second=5,
                  vertical_overflow="visible") as live:
            for job in my_progress.tasks:
                for _index, a_change in enumerate(user_list_for_close):
                    if a_change in all_changes_list:
                        # get the Index number for the change calculated by algorithm get_index_for_change()
                        index = self.close_requests.get_index_for_change_number(
                            a_change, all_changes_list)
                        if index is not None:
                            # Select the change request shared by user
                            self.close_requests.find_the_change_request(
                                a_change, index)
                            if not self.close_requests.is_change_status_closed(
                            ):
                                # check if Change is opened
                                if not self.close_requests.is_status_scheduled_for_approval(
                                ):
                                    # check if Change is Scheduled for approval
                                    actual_open_time = self.close_requests.get_actual_start_date(
                                    )
                                    if actual_open_time is not None:
                                        # make closing time depending on Actual Open Time
                                        # actual_closing_time = make_data.make_downtime_from_open_time(
                                        # actual_open_time)
                                        # Grab the current sys time
                                        current_sys_time = make_data.get_current_system_time(
                                        )
                                        self.close_requests.goto_task_page()
                                        # Close the 2nd task
                                        self.close_requests.close_service_downtime_duration_task(
                                            actual_open_time)
                                        # Close the 3rd task
                                        self.close_requests.close_service_downtime_window_task(
                                            actual_open_time, current_sys_time)
                                        # Close the 4th task
                                        self.close_requests.close_system_downtime_duration_task(
                                            actual_open_time)
                                        self.create_requests.go_back_to_homepage(
                                        )
                                        ClosePrettify.add_row_table(
                                            str(_index + 1),
                                            self.close_requests.
                                            get_change_number(),
                                            "[green]SUCCESS")
                                        live.update(ClosePrettify.get_layout())
                                    else:
                                        self.close_requests.add_change_to_invalid_list(
                                            a_change)
                                        self.create_requests.go_back_to_homepage(
                                        )
                                        ClosePrettify.add_row_table(
                                            str(_index + 1),
                                            self.close_requests.
                                            get_change_number(),
                                            "[red]NCR NOT OPENED")
                                        live.update(ClosePrettify.get_layout())
                                else:
                                    self.close_requests.add_change_to_invalid_list(
                                        a_change)
                                    self.create_requests.go_back_to_homepage()
                                    ClosePrettify.add_row_table(
                                        str(_index + 1),
                                        self.close_requests.get_change_number(
                                        ), "[red]SFA")

                                    live.update(ClosePrettify.get_layout())
                            else:
                                self.create_requests.go_back_to_homepage()
                                ClosePrettify.add_row_table(
                                    str(_index + 1),
                                    self.close_requests.get_change_number(),
                                    "[red]AC")
                                live.update(ClosePrettify.get_layout())
                        else:
                            self.close_requests.add_change_to_invalid_list(
                                a_change)
                            ClosePrettify.add_row_table(
                                str(_index + 1),
                                self.close_requests.get_change_number(),
                                "[red]INVALID")
                            live.update(ClosePrettify.get_layout())
                    else:
                        self.close_requests.add_change_to_invalid_list(
                            a_change)
                        ClosePrettify.add_row_table(
                            str(_index + 1),
                            self.close_requests.get_change_number(),
                            "[red]INVALID")
                        live.update(ClosePrettify.get_layout())
                if not job.finished:
                    my_progress.advance(job.id)

        self.home_page.click_logout_button()
class Create(BasePage):
    def __init__(self, driver: WebDriver):
        """ Create NCR E2E Actions"""
        super().__init__(driver)

        self._layout = get_layout()
        self._table = get_table()
        self.path = os.getcwd()
        super().__init__(driver)
        self.login = LoginPage(self._driver)
        self.homePage = HomePage(self.login._driver)
        self.createChangeRequest = CreateRequests(self.homePage._driver)
        self.read_data = Read_Data(StaticData.READ_EXCEL_FILE)
        self.export_data = Data_Export(StaticData.WRITE_EXCEL_FILE)

    def createNCR(self):
        print(self._layout)
        self.login.enter_username_textbox()
        self.login.enter_password_textbox()
        self.login.click_login_button()
        self.read_data.change_sheet()
        self.export_data.change_sheet("Main")  # Change Sheet
        EXCEL_ROW = 2  # Need to change if need to change the starting point in Excel
        MAX_CHANGE = self.read_data.get_number_change() + EXCEL_ROW
        with Live(self._table,
                  refresh_per_second=4,
                  vertical_overflow="visible") as live:
            for _excel_index in range(EXCEL_ROW, MAX_CHANGE):

                # --------------------- BMCRemedy Create the Change Request as provided data ------------ #
                if self.createChangeRequest.is_home_page("IT Home"):
                    # ------- READ ALL THE DATA ------------ #
                    date = self.read_data.parse_date(_excel_index)
                    coordinator = self.read_data.parse_project_coordinator(
                        _excel_index)
                    project_name = self.read_data.parse_project_name(
                        _excel_index)
                    change_activity = self.read_data.parse_change_activity(
                        _excel_index)
                    impact_sites = self.read_data.parse_impact_list(
                        _excel_index)
                    service_type = self.read_data.parse_service_type(
                        _excel_index)
                    duration = self.read_data.parse_downtime_hour(_excel_index)
                    company = self.read_data.get_company_group()
                    commercial_zone = self.read_data.parse_commercial_zone(
                        _excel_index)
                    change_manager = self.read_data.parse_change_manager(
                        _excel_index)
                    location_service = (company, commercial_zone)

                    summary = project_name + " // " + service_type + "\n\n"
                    notes = summary + change_activity + "\n\n"
                    impact_list = make_data.make_impact_list(impact_sites)
                    details = summary + change_activity + impact_list

                    # ---------------make_data: Task Time Calculation ---------------- #
                    cr_start_time = make_data.get_change_start_time(date)
                    start_downtime = make_data.get_service_start_downtime(date)
                    end_downtime = make_data.get_service_end_downtime(
                        start_downtime, duration)
                    activity_hour = make_data.get_change_close_start_time(date)
                    cr_end_time = make_data.get_change_close_end_time(date)
                    # ------------------------------END----------------------------- #

                    self.homePage.click_application_btn()
                    self.homePage.click_new_change()
                    # TODO: THIS THING IS BUGGING ME > NEED A WAY TO HANDLE > DON'T WANT TO USE IMPLICIT WAIT
                    time.sleep(3)
                    self.createChangeRequest.insert_text_summary(summary)
                    self.createChangeRequest.set_change_number()
                    self.createChangeRequest.insert_text_notes(details)
                    change_number = self.createChangeRequest.get_change_number(
                    )
                    live.console.print(f"Working on: [green]{change_number}")
                    self.createChangeRequest.select_manager_group()
                    self.createChangeRequest.select_change_manager(
                        change_manager)
                    self.createChangeRequest.insert_work_info(notes)
                    self.createChangeRequest.change_location(location_service)
                    self.createChangeRequest.verify_summary(summary)
                    self.createChangeRequest.insert_schedule_date_time(
                        cr_start_time, cr_end_time)
                    self.createChangeRequest.create_task_template()

                    self.createChangeRequest.fill_initiation_task(
                        cr_start_time, start_downtime)
                    self.createChangeRequest.fill_service_downtime_duration_task(
                        start_downtime, end_downtime)
                    self.createChangeRequest.fill_system_downtime_window_task(
                        start_downtime, activity_hour)
                    self.createChangeRequest.fill_system_downtime_duration_task(
                        start_downtime, end_downtime)
                    self.createChangeRequest.fill_review_closure_task(
                        activity_hour, cr_end_time)
                    # ---------------------------------- END -------------------------------------------- #

                    # ---------------------------Data_Export: Export all the data ------------------ #
                    self.export_data.insert_date(_excel_index, date)
                    self.export_data.insert_project_name(
                        _excel_index, project_name)
                    self.export_data.insert_project_coordinator(
                        _excel_index, coordinator)
                    self.export_data.insert_change_activity(
                        _excel_index, change_activity)
                    self.export_data.insert_impact_site_list(
                        _excel_index, impact_sites)
                    self.export_data.insert_service_type(
                        _excel_index, service_type)
                    self.export_data.insert_downtime_duration(
                        _excel_index, duration)
                    self.export_data.insert_commercial_zone(
                        _excel_index, commercial_zone)
                    self.export_data.insert_change_number(
                        _excel_index, change_number)
                    self.export_data.insert_change_manager(
                        _excel_index, change_manager)
                    self.export_data.save_workbook(StaticData.WRITE_EXCEL_FILE)
                    # ---------------------------- END -------------------------------------------------- #

                    console_data = (str(_excel_index - 1), commercial_zone,
                                    service_type, coordinator, change_number,
                                    "✅")

                    # Save and go back to home page, need to tag site if service effective cr
                    if service_type == 'Service Effective':
                        query_formula = make_data.make_query_string(
                            impact_sites)
                        self.createChangeRequest.add_relationship_to_change(
                            query_formula)
                        # ----------------------------------------------------------
                        # while True:
                        #     val = input("Press q after finished")
                        #     if val == 'q':
                        #         break
                        # self.createChangeRequest.save_change()
                        # ---------------------------------------------------------
                        self.createChangeRequest.goto_next_stage()
                        os.chdir(self.path)
                        add_row_table(self._table, *console_data)
                        live.update(self._table)
                        self.createChangeRequest.reset_change_number()
                        self.createChangeRequest.go_back_to_homepage()
                    else:
                        # ----------------------------------------------------------
                        # while True:
                        #     val = input("Press q after finished")
                        #     if val == 'q':
                        #         break
                        # self.createChangeRequest.save_change()
                        # ----------------------------------------------------------
                        self.createChangeRequest.goto_next_stage()
                        os.chdir(self.path)
                        add_row_table(self._table, *console_data)
                        live.update(self._table)
                        self.createChangeRequest.reset_change_number()
                        self.createChangeRequest.go_back_to_homepage()
        self.homePage.click_logout_button()
        self.export_data.close_workbook()
        self.read_data.close_workbook()
class Cancel(BasePage):
    def __init__(self, driver: WebDriver):
        """ Cancel NCR E2E Actions """
        super().__init__(driver)
        self.login_page = LoginPage(self._driver)
        self.home_page = HomePage(self.login_page._driver)
        self.closeRequest = CloseRequests(self.home_page._driver)
        self.cancel_requests = CancelRequests(self.closeRequest._driver)
        self.create_requests = CreateRequests(self.closeRequest._driver)

    def cancelRequest(self):
        """ All the functionalities in one function to mimic a user interactions to cancel a Change Request"""

        # Log in to the server
        self.login_page.enter_username_textbox()
        self.login_page.enter_password_textbox()
        self.login_page.click_login_button()

        # Parse all the change numbers from the home page
        all_changes_web = self.home_page.get_all_change_numbers()

        # Parse all the user requested change number from the source
        all_changes_file = make_data.list_of_change(
            StaticData.CANCEL_CHANGE_TXT_FILE_PATH)

        # Prettify tables
        CancelPrettify.make_layout()
        CancelPrettify.make_table()
        progress = CancelPrettify.progress_bar(len(all_changes_file))
        CancelPrettify.merge_layout(progress, CancelPrettify.get_table())

        with Live(CancelPrettify.show_layout(),
                  refresh_per_second=5,
                  vertical_overflow="visible") as live:
            while not progress.finished:
                for task in progress.tasks:
                    for _task_no, a_change in enumerate(all_changes_file):
                        # find the index of the change number from the list (custom algorithm is used).
                        #  Searching an element time complexity is O(1)
                        index = self.closeRequest.get_index_for_change_number(
                            a_change, all_changes_web)
                        if index is not None:
                            # select the change number after found
                            self.closeRequest.find_the_change_request(
                                a_change, index)
                            if not self.closeRequest.is_change_status_closed():
                                if not self.closeRequest.is_status_scheduled_for_approval(
                                ):
                                    if not self.cancel_requests.is_change_request_opened(
                                    ):
                                        if not self.cancel_requests.is_cancelled(
                                        ):
                                            # Perform the user interactions to cancel
                                            self.cancel_requests.wait_for_loading_icon_disappear(
                                            )
                                            self.cancel_requests.select_cancel(
                                            )
                                            self.cancel_requests.save_status()
                                            # // Cancelled //
                                            CancelPrettify.add_row_table(
                                                str(_task_no + 1),
                                                self.cancel_requests.
                                                get_cancelled_cr_number(),
                                                "CANCELLED")
                                            live.update(
                                                CancelPrettify.show_layout())
                                            self.create_requests.go_back_to_homepage(
                                            )
                                        else:
                                            #  // Already Closed //
                                            CancelPrettify.add_row_table(
                                                str(_task_no + 1),
                                                self.cancel_requests.
                                                get_cancelled_cr_number(),
                                                "A/C",
                                                style="yellow")
                                            live.update(
                                                CancelPrettify.show_layout())
                                            self.create_requests.go_back_to_homepage(
                                            )
                                    else:
                                        # // Already Opened //
                                        CancelPrettify.add_row_table(
                                            str(_task_no + 1),
                                            self.cancel_requests.
                                            get_cancelled_cr_number(),
                                            "A/O",
                                            style="red")
                                        live.update(
                                            CancelPrettify.show_layout())
                                        self.create_requests.go_back_to_homepage(
                                        )
                                else:
                                    # // Scheduled for Approval
                                    CancelPrettify.add_row_table(
                                        str(_task_no + 1),
                                        self.cancel_requests.
                                        get_cancelled_cr_number(), "S/F/A")
                                    live.update(CancelPrettify.show_layout())
                                    self.create_requests.go_back_to_homepage()
                            else:
                                # // Already Closed or Completed
                                CancelPrettify.add_row_table(
                                    str(_task_no + 1),
                                    self.cancel_requests.
                                    get_cancelled_cr_number(),
                                    "Closed/Completed")
                                live.update(CancelPrettify.show_layout())
                                self.create_requests.go_back_to_homepage()
                        if not task.finished:
                            progress.advance(task.id)

        self.home_page.click_logout_button()