def __init__(self):
        self.result_tiempo_de_ejecucion = ResultStep()

        # establece el tiempo de inicio de ejecucion
        self.result_validacion_ingreso_url = ResultStep()
        self.result_validacion_acceso_portal_owa = ResultStep()
        self.result_validacion_navegacion_carpetas = ResultStep()
        self.result_validacion_cierre_sesion = ResultStep()
    def iniciar_sesion_en_owa(webdriver: WebDriver, correo: Correo,
                              result_list: ValidacionResultList):

        EvaluacionesHtml.cuenta_sin_dominio = FormatUtils.formatear_correo(
            correo.correo)
        EvaluacionesHtml.url_owa_exchange = correo.url

        resultado = ResultStep()

        resultado.tiempo_inicio_de_ejecucion = Temporizador.obtener_tiempo_timer(
        )
        resultado.datetime_inicial = Temporizador.obtener_fecha_tiempo_actual()

        # verifica que haya ingresado correctamente a la url
        if not result_list.result_validacion_ingreso_url.validacion_correcta:
            resultado.validacion_correcta = False
            resultado.mensaje_error = 'No fue posible el inicio de sesion dentro de la plataforma Exchange. ' \
                                      'No se ingreso correctamente a la pagina principal de la plataforma'

            resultado.finalizar_tiempo_de_ejecucion()
            resultado.establecer_tiempo_de_ejecucion()
            result_list.result_validacion_acceso_portal_owa = resultado

            return result_list

        try:
            input_usuario = BusquedaElementosHtml.buscar_elemento_por_id_timeout(
                webdriver, constantes_webdriver_actions.
                INICIAR_SESION_EN_OWA_ID_INPUT_USER, 7)

            input_usuario.send_keys(correo.correo)

            input_password = BusquedaElementosHtml.buscar_elemento_por_id_timeout(
                webdriver, constantes_webdriver_actions.
                INICIAR_SESION_EN_OWA_ID_INPUT_PASSWORD, 7)

            input_password.send_keys(correo.password)

            boton_ingreso_correo = None

            if ValidacionesHTML.verificar_elemento_encontrado_por_id(
                    webdriver, constantes_webdriver_actions.
                    INICIAR_SESION_EN_OWA_ID_CHECKBOX_PORTAL_LIGHTWEIGHT_OWA_2010
            ):
                check_casilla_owa_2010_version_ligera = BusquedaElementosHtml.buscar_elemento_por_id_timeout(
                    webdriver, constantes_webdriver_actions.
                    INICIAR_SESION_EN_OWA_ID_CHECKBOX_PORTAL_LIGHTWEIGHT_OWA_2010,
                    7)

                check_casilla_owa_2010_version_ligera.click()
                constantes_utils.owa_descubierto = 2010

            if ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    webdriver, constantes_webdriver_actions.
                    INICIAR_SESION_EN_OWA_XPATH_BTN_OWA_2010):

                boton_ingreso_correo = BusquedaElementosHtml.buscar_elemento_por_xpath_timeout(
                    webdriver, constantes_webdriver_actions.
                    INICIAR_SESION_EN_OWA_XPATH_BTN_OWA_2010, 7)

                constantes_utils.owa_descubierto = 2010

            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    webdriver, constantes_webdriver_actions.
                    INICIAR_SESION_EN_OWA_XPATH_BTN_OWA_2013_2016):

                boton_ingreso_correo = BusquedaElementosHtml.buscar_elemento_por_xpath_timeout(
                    webdriver, constantes_webdriver_actions.
                    INICIAR_SESION_EN_OWA_XPATH_BTN_OWA_2013_2016, 7)

                constantes_utils.owa_descubierto = 2016

            boton_ingreso_correo.click()

        except sel_excep.NoSuchElementException as e:
            resultado.mensaje_error = constantes_webdriver_actions.INICIAR_SESION_MSG_NOSUCHELEM_EXCEP_MSG_ERROR. \
                format(FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False

        except sel_excep.TimeoutException as e:
            resultado.mensaje_error = constantes_webdriver_actions.INICIAR_SESION_MSG_NOSUCHELEM_EXCEP_MSG_ERROR. \
                format(FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False

        except sel_excep.WebDriverException as e:

            resultado.mensaje_error = constantes_webdriver_actions.INICIAR_SESION_MSG_WEBDRIVER_EXCEP_MSG_ERROR. \
                format(FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False

        if not resultado.validacion_correcta:
            try:
                if constantes_utils.owa_descubierto == 2010:

                    mensaje_error_de_credenciales = webdriver.find_element_by_xpath(
                        constantes_webdriver_actions.
                        INICIAR_SESION_EN_OWA_XPATH_ERROR_CREDENCIALES_OWA_2010
                    )

                    texto_mensaje_error = mensaje_error_de_credenciales.get_attribute(
                        'innerHTML')
                    resultado.msg_error_de_credenciales = texto_mensaje_error

                    resultado.mensaje_error = constantes_webdriver_actions. \
                        INICIAR_SESION_LOG_MSG_ERROR_CREDENCIALES_OWA.format(texto_mensaje_error)

                    resultado.validacion_correcta = False
                    resultado.error_inicio_de_sesion_credenciales_erroneas = True

                elif constantes_utils.owa_descubierto == 2016 or constantes_utils.owa_descubierto == 2013:

                    mensaje_error_de_credenciales = webdriver.execute_script(
                        constantes_webdriver_actions.
                        INICIAR_SESION_JS_LOCATE_ID_MSG_ERROR_CREDENCIALES_OWA_2016_2013
                    )

                    resultado.mensaje_error = constantes_webdriver_actions. \
                        INICIAR_SESION_LOG_MSG_ERROR_CREDENCIALES_OWA.format(mensaje_error_de_credenciales)

                    resultado.msg_error_de_credenciales = mensaje_error_de_credenciales

                    resultado.validacion_correcta = False
                    resultado.error_inicio_de_sesion_credenciales_erroneas = True

            except sel_excep.NoSuchElementException:
                resultado.mensaje_error = constantes_json.OUTPUT_EXITOSO_1_1
                resultado.validacion_correcta = True

            except sel_excep.InvalidSessionIdException as e:
                resultado.mensaje_error = constantes_webdriver_actions. \
                    INICIAR_SESION_CREDENCIALES_INVALIDSESION_ID_EXCEP_MSG_ERROR.format(e)

                resultado.validacion_correcta = False

            except sel_excep.JavascriptException:
                # Se ingresa correctamente, debido a que no se encontro el mensaje de error de credenciales incorrectas
                resultado.mensaje_error = constantes_json.OUTPUT_EXITOSO_1_1
                resultado.validacion_correcta = True

            except sel_excep.WebDriverException:
                # Se ingresa correctamente, debido a que no se encontro el mensaje de error de credenciales incorrectas
                resultado.mensaje_error = constantes_json.OUTPUT_EXITOSO_1_1
                resultado.validacion_correcta = True

        # realiza la validacion de ingreso correcto de sesion se verifica que no haya algun error que se presente en la
        # plataforma en caso contrario se obtiene el mensaje del error y se establecer en el objeto resultado

        if ValidacionesHTML.verificar_error_plataforma(webdriver):
            msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(
                webdriver)
            resultado.mensaje_error = constantes_webdriver_actions.INICIAR_SESION_MSG_ERROR_EN_PLATAFORMA. \
                format(msg_error)

            resultado.validacion_correcta = False
            resultado.error_plataforma_inicio_de_sesion = True

        resultado.finalizar_tiempo_de_ejecucion()
        resultado.establecer_tiempo_de_ejecucion()
        result_list.result_validacion_acceso_portal_owa = resultado

        return result_list
    def cerrar_sesion(webdriver: WebDriver, result_list: ValidacionResultList,
                      correo: Correo):

        resultado_cierre_sesion = ResultStep()
        resultado_cierre_sesion.inicializar_tiempo_de_ejecucion()
        cierre_sesion_exitosa = False

        # verifica si se tiene error de credenciales, por lo cual si se tiene este error, se establece el mensaje
        # de error y envia el result como finalizado, esto debido a que no puede localizar el boton de cierre de
        # sesion sin antes haberse loggeado dentro de la plataforma
        if result_list.result_validacion_acceso_portal_owa.error_inicio_de_sesion_credenciales_erroneas:
            resultado_cierre_sesion.finalizar_tiempo_de_ejecucion()
            resultado_cierre_sesion.establecer_tiempo_de_ejecucion()
            resultado_cierre_sesion.validacion_correcta = False

            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_MSG_ERROR_CREDENCIALES_OWA.format(result_list.result_validacion_acceso_portal_owa.
                                                                msg_error_de_credenciales)

            result_list.result_validacion_cierre_sesion = resultado_cierre_sesion

            return result_list

        # verifica si hay error en plataforma, en caso de ser asi, intenta realizar n intentos para volver a loggearse
        # y verificar si ingreso correctamente al buzon de entrada para navegar entre las carpetas
        if ValidacionesHTML.verificar_error_plataforma(webdriver):
            resultado_cierre_sesion = ValidacionesHTML.intento_ingreso_nuevamente_al_portal(
                resultado_cierre_sesion,
                correo,
                webdriver,
                step_evaluacion='cierre de sesion')

        try:
            if constantes_utils.owa_descubierto == 2013 or constantes_utils.owa_descubierto == 2016:
                btn_perfil_usuario = BusquedaElementosHtml.localizar_boton_perfil_usuario(
                    webdriver)
                btn_perfil_usuario.click()

                btn_cierre_de_sesion = BusquedaElementosHtml.localizar_boton_cierre_sesion_owa_2013_2016(
                    webdriver)
                btn_cierre_de_sesion.click()

            elif constantes_utils.owa_descubierto == 2010:
                enlace_cierre_sesion = BusquedaElementosHtml.localizar_enlace_cierre_sesion_owa_2010(
                    webdriver)
                enlace_cierre_sesion.click()

            webdriver.get(correo.url)

            ValidacionesHTML.verificar_ingreso_exitoso_pagina_principal(
                webdriver, constantes_webdriver_actions.
                INICIAR_SESION_EN_OWA_ID_INPUT_PASSWORD, 10)

            cierre_sesion_exitosa = True

        except sel_excep.NoSuchElementException as e:
            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_NO_SUCH_ELEM_EXCEP.format(FormatUtils.formatear_excepcion(e))

            resultado_cierre_sesion.validacion_correcta = False

        except sel_excep.ElementClickInterceptedException:
            webdriver.refresh()
            EvaluacionesHtml.cerrar_sesion(webdriver, result_list, correo)

        except sel_excep.TimeoutException as e:
            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_TIMEOUT_EXCEP.format(FormatUtils.formatear_excepcion(e))

            resultado_cierre_sesion.validacion_correcta = False

        except sel_excep.WebDriverException as e:
            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_WEBDRIVER_EXCEP.format(FormatUtils.formatear_excepcion(e))

            resultado_cierre_sesion.validacion_correcta = False

        except AttributeError:
            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_ATRIBUTE_ERROR_EXCEP

            resultado_cierre_sesion.validacion_correcta = False

        finally:

            # verifica que no haya algun mensaje de error en la plataforma, en caso contrario se muestra el mensaje de
            # error que aparace en la plataforma dentro del result
            if ValidacionesHTML.verificar_error_plataforma(webdriver):
                resultado_cierre_sesion.validacion_correcta = False
                msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(
                    webdriver)

                resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions.CERRAR_SESION_ERROR_PLATAFORMA. \
                    format(msg_error)

                cierre_sesion_exitosa = False

        if cierre_sesion_exitosa:
            resultado_cierre_sesion.mensaje_error = constantes_json.OUTPUT_EXITOSO_3_1
            resultado_cierre_sesion.validacion_correcta = True

        resultado_cierre_sesion.finalizar_tiempo_de_ejecucion()
        resultado_cierre_sesion.establecer_tiempo_de_ejecucion()
        result_list.result_validacion_cierre_sesion = resultado_cierre_sesion

        return result_list
    def navegar_a_portal_principal_owa(web_driver: WebDriver, url: str,
                                       result_list: ValidacionResultList):

        resultado = ResultStep()
        resultado.tiempo_inicio_de_ejecucion = 0
        resultado.inicializar_tiempo_de_ejecucion()
        segundos_por_esperar_elemento_html = 10

        try:
            web_driver.get(url)
            ValidacionesHTML.verificar_ingreso_exitoso_pagina_principal(
                web_driver, constantes_webdriver_actions.
                INICIAR_SESION_EN_OWA_ID_INPUT_PASSWORD,
                segundos_por_esperar_elemento_html)

            resultado.mensaje_error = constantes_webdriver_actions.NAVEGAR_SITIO_MSG_INGRESO_SITIO_CON_EXITO. \
                format(url)

            resultado.validacion_correcta = True

        except sel_excep.TimeoutException as e:
            resultado.mensaje_error = constantes_webdriver_actions.NAVEGAR_SITIO_MSG_TIMEOUT_EXCEP_MSG_ERROR.format(
                segundos_por_esperar_elemento_html, url,
                FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False

        except sel_excep.WebDriverException as e:
            resultado.mensaje_error = constantes_webdriver_actions.NAVEGAR_SITIO_MSG_WEBDRIVER_EXCEP_MSG_ERROR. \
                format(FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False

        resultado.finalizar_tiempo_de_ejecucion()
        resultado.establecer_tiempo_de_ejecucion()
        result_list.result_validacion_ingreso_url = resultado

        return result_list
    def navegacion_de_carpetas_por_segundos(correo: Correo,
                                            driver: WebDriver,
                                            result_list: ValidacionResultList,
                                            numero_de_segundos: int = 120):

        result_navegacion_carpetas = ResultStep()
        result_navegacion_carpetas.inicializar_tiempo_de_ejecucion()
        tiempo_por_verificar = numero_de_segundos + Temporizador.obtener_tiempo_timer(
        )
        lista_carpetas = BusquedaElementosHtml.obtener_carpetas_en_sesion(
            driver)

        total_contadores_errores = 0
        contador_errores_staleelementreferenceexception = 0
        contador_errores_elementclickinterceptedexception = 0
        contador_errores_nosuchelementexception = 0
        contador_errores_timeoutexception = 0
        contador_errores_webdriverexception = 0
        intento_de_clicks_en_carpeta = 0

        # verifica si se tiene error de credenciales, por lo cual si se tiene este error, se establece el mensaje
        # de error y envia el result como finalizado, esto debido a que no se podra navegar entre carpetas por no
        # estar loggeado y sin tener acceso al buzon de la plataforma
        if result_list.result_validacion_acceso_portal_owa.error_inicio_de_sesion_credenciales_erroneas:
            result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
            result_navegacion_carpetas.establecer_tiempo_de_ejecucion()
            result_navegacion_carpetas.validacion_correcta = False

            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions.\
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_CREDENCIALES_OWA.format(
                    result_list.result_validacion_acceso_portal_owa.msg_error_de_credenciales)

            result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

            return result_list

        # verifica si hay error en plataforma, en caso de ser asi, intenta realizar n intentos para volver a loggearse
        # y verificar si ingreso correctamente al buzon de entrada para navegar entre las carpetas
        if ValidacionesHTML.verificar_error_plataforma(driver):
            result_navegacion_carpetas = ValidacionesHTML.intento_ingreso_nuevamente_al_portal(
                result_navegacion_carpetas,
                correo,
                driver,
                step_evaluacion='Navegacion carpetas y buzon de entrada')

        # verifica si aun se sigue mostrando el mensaje de error en la plataforma, en caso contrario la prueba falla
        # y notificaria al cliente de presentar un error de plataforma

        if ValidacionesHTML.verificar_error_plataforma(driver):

            result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
            result_navegacion_carpetas.establecer_tiempo_de_ejecucion()
            result_navegacion_carpetas.validacion_correcta = False
            msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(
                driver)
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions. \
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_PLATAFORMA_OWA.format(msg_error)

            result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

            return result_list

        elif len(lista_carpetas) == 0:

            result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
            result_navegacion_carpetas.establecer_tiempo_de_ejecucion()
            result_navegacion_carpetas.validacion_correcta = False
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions. \
                NAVEGACION_CARPETAS_SEG_LOG_ERROR_LISTA_CARPETAS_VACIA

            result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

            return result_list

        while Temporizador.obtener_tiempo_timer() < tiempo_por_verificar:
            for carpeta in lista_carpetas:
                try:
                    elemento_html_carpeta = BusquedaElementosHtml.obtener_carpeta_con_timeout(
                        driver, carpeta, 7)
                    elemento_html_carpeta.click()

                except sel_excep.StaleElementReferenceException:
                    contador_errores_staleelementreferenceexception += 1

                except sel_excep.ElementClickInterceptedException:
                    contador_errores_elementclickinterceptedexception += 1

                except sel_excep.NoSuchElementException:
                    contador_errores_nosuchelementexception += 1

                except sel_excep.TimeoutException:
                    contador_errores_timeoutexception += 1

                except sel_excep.WebDriverException:
                    contador_errores_webdriverexception += 1

                time.sleep(8)
                intento_de_clicks_en_carpeta += 1

        result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
        result_navegacion_carpetas.establecer_tiempo_de_ejecucion()

        total_contadores_errores = contador_errores_staleelementreferenceexception + \
                                   contador_errores_elementclickinterceptedexception + \
                                   contador_errores_nosuchelementexception + \
                                   contador_errores_timeoutexception + \
                                   contador_errores_webdriverexception

        # verifica que no haya algun mensaje de error en la plataforma, en caso contrario se muestra el mensaje de
        # error que aparace en la plataforma dentro del result
        if ValidacionesHTML.verificar_error_plataforma(driver):
            msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(
                driver)
            result_navegacion_carpetas.validacion_correcta = False
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions. \
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_PLATAFORMA_OWA.format(msg_error)
        elif total_contadores_errores == intento_de_clicks_en_carpeta:
            result_navegacion_carpetas.validacion_correcta = False
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions.\
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_INTENTOS_CLICK.format(intento_de_clicks_en_carpeta)
        else:
            result_navegacion_carpetas.validacion_correcta = True
            result_navegacion_carpetas.mensaje_error = constantes_json.OUTPUT_EXITOSO_2_1

        result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

        return result_list
Ejemplo n.º 6
0
    def intento_ingreso_nuevamente_al_portal(result: ResultStep, correo: Correo, driver: WebDriver,
                                             numero_de_intentos_por_ingresar: int = 3, step_evaluacion: str = ''):

        for intento in range(numero_de_intentos_por_ingresar):
            try:
                boton_inicio_sesion = None
                driver.delete_all_cookies()
                driver.refresh()

                driver.get(correo.url)

                WebDriverWait(driver, 18).until(EC.visibility_of_element_located((By.ID, 'username')))

                input_usuario = driver.find_element_by_id('username')
                input_password = driver.find_element_by_id('password')

                input_usuario.clear()
                input_password.clear()

                if ValidacionesHTML.verificar_elemento_encontrado_por_id(driver, 'chkBsc'):
                    check_casilla_owa_2010_version_ligera = driver.find_element_by_id('chkBsc')
                    check_casilla_owa_2010_version_ligera.click()

                if ValidacionesHTML.verificar_elemento_encontrado_por_xpath(driver, "//input[@type='submit'][@class='btn']"):
                    boton_inicio_sesion = driver.find_element_by_xpath("//input[@type='submit'][@class='btn']")

                elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(driver, "//div[@class='signinbutton']"):
                    boton_inicio_sesion = driver.find_element_by_xpath("//div[@class='signinbutton']")

                # num_random = randint(1,1000)
                # driver.save_screenshot('./Logs/{}_0.png'.format(num_random))
                time.sleep(1)
                input_usuario.send_keys(correo.correo)
                # driver.save_screenshot('./Logs/{}_1.png'.format(num_random))
                time.sleep(1)
                input_password.send_keys(correo.password)
                # driver.save_screenshot('./Logs/{}_2.png'.format(num_random))
                time.sleep(1)
                boton_inicio_sesion.click()
                # driver.save_screenshot('./Logs/{}_5.png'.format(num_random))

                time.sleep(10)
                # driver.save_screenshot('./Logs/{}_6.png'.format(num_random))

                # se verifica si encuentra al menos las carpetas en la bandeja
                if ValidacionesHTML.verificar_elemento_encontrado_por_clase_js(driver, "_n_C4") or \
                        ValidacionesHTML.verificar_elemento_encontrado_por_clase_js(driver, "_n_Z6") or \
                        ValidacionesHTML.verificar_elemento_encontrado_por_xpath(driver, "//a[@name='lnkFldr']"):

                    result.validacion_correcta = True
                    result.mensaje_error = 'Se ingresa nuevamente de manera correcta al buzon de entrada de la ' \
                                           'cuenta {}'.format(correo.correo)

                    break

                elif ValidacionesHTML.verificar_error_plataforma(driver):
                    msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(driver)
                    result.validacion_correcta = False
                    result.mensaje_error = 'Ingreso al buzon de entrada no exitosa, se presenta el siguiente error ' \
                        'dentro de la plataforma Exchange OWA: {}'.format(msg_error)

                else:
                    result.validacion_correcta = False
                    result.mensaje_error = 'Ingreso al buzon de entrada no exitosa. Se intento ingresar a la ' \
                        'bandeja de entrada de la plataforma Exchange OWA, se presenta problemas de carga de pagina'


            except SelExcept.NoSuchElementException as e:
                result.validacion_correcta = False
                result.mensaje_error = 'No fue posible ingresar nuevamente a la bandeja de entrada. No se ' \
                                       'localizaron correctamente los inputs para el ingreso de usuario y password'

            except SelExcept.TimeoutException as e:
                result.validacion_correcta = False
                result.mensaje_error = 'No fue posible ingresar nuevamente a la bandeja de entrada. Se tiene un ' \
                                       'problema de tiempo de carga en la pagina'


        return result
Ejemplo n.º 7
0
    def validacion_json_inicio_sesion(result_url,
                                      result_sesion,
                                      objeto_json):
        result_final = ResultStep()

        # valida el estatus de ambos steps
        if not result_url.validacion_correcta:
            result_final.mensaje_error = result_url.mensaje_error
            result_final.validacion_correcta = False
        elif not result_sesion.validacion_correcta:
            result_final.mensaje_error = result_sesion.mensaje_error
            result_final.validacion_correcta = False
        else:
            result_final.mensaje_error = result_sesion.mensaje_error
            result_final.validacion_correcta = True

        # establece el datetime de inicio
        result_final.datetime_inicial = result_url.datetime_inicial

        # establece el datetime final
        result_final.datetime_final = result_sesion.datetime_final

        # establece el tiempo total de la ejecucion de ambos steps
        result_final.tiempo_inicio_de_ejecucion = result_url.tiempo_inicio_de_ejecucion
        result_final.tiempo_fin_de_ejecucion = result_sesion.tiempo_fin_de_ejecucion

        # establece el tiempo total de ejecucion
        result_final.establecer_tiempo_de_ejecucion()

        objeto_json['steps'][0]['status'] = constantes_json.STATUS_CORRECTO if \
            result_final.validacion_correcta else constantes_json.STATUS_FALLIDO

        objeto_json['steps'][0]['output'][0]['output'] = result_final.mensaje_error

        objeto_json['steps'][0]['output'][0]['status'] = constantes_json.STATUS_CORRECTO if \
            result_final.validacion_correcta else constantes_json.STATUS_FALLIDO

        objeto_json['steps'][0]['start'] = result_final.datetime_inicial
        objeto_json['steps'][0]['end'] = result_final.datetime_final
        objeto_json['steps'][0]['time'] = result_final.tiempo_total_de_la_ejecucion

        return objeto_json
    def cerrar_sesion(webdriver: WebDriver, result_list: ValidacionResultList, correo: Correo):

        timeout_cierre_sesion = 10
        resultado_cierre_sesion = ResultStep()
        resultado_cierre_sesion.inicializar_tiempo_de_ejecucion()
        cierre_sesion_exitosa = False

        # verifica si se tiene error de credenciales, por lo cual si se tiene este error, se establece el mensaje
        # de error y envia el result como finalizado, esto debido a que no puede localizar el boton de cierre de
        # sesion sin antes haberse loggeado dentro de la plataforma
        if result_list.result_validacion_acceso_portal_owa.error_inicio_de_sesion_credenciales_erroneas:
            resultado_cierre_sesion.finalizar_tiempo_de_ejecucion()
            resultado_cierre_sesion.establecer_tiempo_de_ejecucion()
            resultado_cierre_sesion.validacion_correcta = False

            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions.\
                CERRAR_SESION_MSG_ERROR_CREDENCIALES_OWA.format(result_list.result_validacion_acceso_portal_owa.
                                                                msg_error_de_credenciales)

            result_list.result_validacion_cierre_sesion = resultado_cierre_sesion

            AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_MSG_ERROR_CREDENCIALES_OWA.format(
                result_list.result_validacion_acceso_portal_owa.msg_error_de_credenciales))

            webdriver.close()
            webdriver.quit()

            return result_list

        # verifica si hay error en plataforma, en caso de ser asi, intenta realizar n intentos para volver a loggearse
        # y verificar si ingreso correctamente al buzon de entrada para navegar entre las carpetas
        if ValidacionesHTML.verificar_error_plataforma(webdriver):
            resultado_cierre_sesion = ValidacionesHTML.intento_ingreso_nuevamente_al_portal(
                resultado_cierre_sesion, correo, webdriver, step_evaluacion='cierre de sesion')

        try:
            webdriver.refresh()
            time.sleep(5)

            # verifica que no haya algun dialogo que impida el cierre de sesion
            ValidacionesHTML.verificar_dialogo_de_interrupcion(
                webdriver, resultado_cierre_sesion)

            # intenta salir de la sesion ejecutando un script js el cual simula un clic en el boton de cierre de sesion

            if AccionesHtml.owa_descubierto == 2010:
                time.sleep(4)
                elemento_html_btn_cerrar_sesion = webdriver.find_element_by_id(
                    constantes_webdriver_actions.CERRAR_SESION_CIERRE_SESION_ID_BTN_CIERRE_SESION_OWA_2010)
                time.sleep(4)
                elemento_html_btn_cerrar_sesion.click()
                time.sleep(4)
            elif AccionesHtml.owa_descubierto == 2016:
                time.sleep(4)

                boton_cierre_sesion_owa_2016 = webdriver.execute_script(
                    constantes_webdriver_actions.JS_LOCATE_DIV_CONTENT_BTN_CIERRE_SESION_OWA_2016)

                time.sleep(4)
                boton_cierre_sesion_owa_2016.click()
                time.sleep(8)

                boton_cierre_sesion_owa_2016 = webdriver.execute_script(
                    constantes_webdriver_actions.JS_LOCATE_BTN_CIERRE_SESION_OWA_2016)

                boton_cierre_sesion_owa_2016.click()

            elif AccionesHtml.owa_descubierto == 2013:

                boton_cierre_sesion_owa_2013 = webdriver.execute_script(
                    constantes_webdriver_actions.JS_LOCATE_DIV_CONTENT_BTN_CIERRE_SESION_OWA_2013)

                boton_cierre_sesion_owa_2013.click()
                time.sleep(8)

                boton_cierre_sesion_owa_2013 = webdriver.execute_script(
                    constantes_webdriver_actions.JS_LOCATE_BTN_CIERRE_SESION_OWA_2013_SPANISH)

                if boton_cierre_sesion_owa_2013 is None:
                    AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_LOG_ERROR_BTN_CIERRE_SIGN_OUT)

                    boton_cierre_sesion_owa_2013 = webdriver.execute_script(
                        constantes_webdriver_actions.JS_LOCATE_BTN_CIERRE_SESION_OWA_2013_ENGLISH)

                boton_cierre_sesion_owa_2013.click()

            # obtiene la url actual como una cadena
            time.sleep(2)

            AccionesHtml.log.info(constantes_webdriver_actions.CERRAR_SESION_LOG_INFO_CIERRE_SESION_TITLE_URL
                                  .format(webdriver.title, webdriver.current_url))

            webdriver.refresh()

            time.sleep(2)

            # verifica que nos encontremos en la pagina de cierre de sesion del OWA verifica que el title de la pagina
            # contenfa Outlook
            condicion_contenido_en_title = EC.title_contains(constantes_webdriver_actions.
                                                             CERRAR_SESION_TITLE_CIERRE_SESION)

            WebDriverWait(webdriver, timeout_cierre_sesion).until(condicion_contenido_en_title)

            cierre_sesion_exitosa = True

        except selExcep.NoSuchElementException as e:

            AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_LOG_ERROR_NO_SUCH_ELEM_EXCEP.format(
                FormatUtils.formatear_excepcion(e)))

            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_NO_SUCH_ELEM_EXCEP.format(FormatUtils.formatear_excepcion(e))

            resultado_cierre_sesion.validacion_correcta = False

        except selExcep.ElementClickInterceptedException as e:

            AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_LOG_ERROR_ELEM_INTERCEP_EXCEP.format(
                FormatUtils.formatear_excepcion(e)))

            webdriver.refresh()

            time.sleep(2)

            AccionesHtml.cerrar_sesion(webdriver, result_list, correo)

        except selExcep.TimeoutException as e:

            AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_LOG_ERROR_TIMEOUT_EXCEP.format(
                FormatUtils.formatear_excepcion(e)))

            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_TIMEOUT_EXCEP.format(FormatUtils.formatear_excepcion(e))

            resultado_cierre_sesion.validacion_correcta = False

        except selExcep.WebDriverException as e:

            AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_LOG_ERROR_WEBDRIVER_EXCEP
                                   .format(FormatUtils.formatear_excepcion(e)))

            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_WEBDRIVER_EXCEP.format(FormatUtils.formatear_excepcion(e))

            resultado_cierre_sesion.validacion_correcta = False

        except AttributeError:

            AccionesHtml.log.error(constantes_webdriver_actions.CERRAR_SESION_LOG_ERROR_ATRIBUTE_ERROR_EXCEP)
            resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions. \
                CERRAR_SESION_LOG_ERROR_ATRIBUTE_ERROR_EXCEP
            resultado_cierre_sesion.validacion_correcta = False

        finally:

            # verifica que no haya algun mensaje de error en la plataforma, en caso contrario se muestra el mensaje de
            # error que aparace en la plataforma dentro del result
            if ValidacionesHTML.verificar_error_plataforma(webdriver):
                resultado_cierre_sesion.validacion_correcta = False
                msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(webdriver)

                resultado_cierre_sesion.mensaje_error = constantes_webdriver_actions.CERRAR_SESION_ERROR_PLATAFORMA. \
                    format(msg_error)

                cierre_sesion_exitosa = False

            AccionesHtml.log.info(constantes_webdriver_actions.CERRAR_SESION_LOG_INFO_CIERRE_WEB_DRIVER)

            webdriver.close()
            webdriver.quit()

        if cierre_sesion_exitosa:
            AccionesHtml.log.info(constantes_webdriver_actions.CERRAR_SESION_LOG_INFO_CIERRE_SESION_EXITOSA)
            resultado_cierre_sesion.mensaje_error = constantes_json.OUTPUT_EXITOSO_3_1
            resultado_cierre_sesion.validacion_correcta = True

        resultado_cierre_sesion.finalizar_tiempo_de_ejecucion()
        resultado_cierre_sesion.establecer_tiempo_de_ejecucion()
        result_list.result_validacion_cierre_sesion = resultado_cierre_sesion

        return result_list
    def navegacion_de_carpetas_por_segundos(correo: Correo, lista_carpetas: list, driver: WebDriver,
                                            result_list: ValidacionResultList, numero_de_segundos: int = 120):

        result_navegacion_carpetas = ResultStep()
        result_navegacion_carpetas.inicializar_tiempo_de_ejecucion()
        tiempo_por_verificar = numero_de_segundos + Temporizador.obtener_tiempo_timer()
        tiempo_de_inicio = Temporizador.obtener_tiempo_timer()
        segundos = 0

        # verifica si se tiene error de credenciales, por lo cual si se tiene este error, se establece el mensaje
        # de error y envia el result como finalizado, esto debido a que no se podra navegar entre carpetas por no
        # estar loggeado y sin tener acceso al buzon de la plataforma
        if result_list.result_validacion_acceso_portal_owa.error_inicio_de_sesion_credenciales_erroneas:
            result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
            result_navegacion_carpetas.establecer_tiempo_de_ejecucion()
            result_navegacion_carpetas.validacion_correcta = False

            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions.\
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_CREDENCIALES_OWA.format(
                result_list.result_validacion_acceso_portal_owa.msg_error_de_credenciales)

            result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

            AccionesHtml.log.error(constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_MSG_ERROR_CREDENCIALES_OWA.
                                   format(result_list.result_validacion_acceso_portal_owa.msg_error_de_credenciales))

            return result_list

        # verifica si hay error en plataforma, en caso de ser asi, intenta realizar n intentos para volver a loggearse
        # y verificar si ingreso correctamente al buzon de entrada para navegar entre las carpetas
        if ValidacionesHTML.verificar_error_plataforma(driver):
            result_navegacion_carpetas = ValidacionesHTML.intento_ingreso_nuevamente_al_portal(
                result_navegacion_carpetas, correo, driver, step_evaluacion='Navegacion carpetas y buzon de entrada')

        # verifica si aun se sigue mostrando el mensaje de error en la plataforma, en caso contrario la prueba falla
        # y notificaria al cliente de presentar un error de plataforma

        if ValidacionesHTML.verificar_error_plataforma(driver):

            result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
            result_navegacion_carpetas.establecer_tiempo_de_ejecucion()
            result_navegacion_carpetas.validacion_correcta = False
            msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(driver)
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions. \
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_PLATAFORMA_OWA.format(msg_error)

            result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

            return result_list

        elif len(lista_carpetas) == 0:

            result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
            result_navegacion_carpetas.establecer_tiempo_de_ejecucion()
            result_navegacion_carpetas.validacion_correcta = False
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions. \
                NAVEGACION_CARPETAS_SEG_LOG_ERROR_LISTA_CARPETAS_VACIA

            result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

            AccionesHtml.log.error(constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_LOG_ERROR_LISTA_CARPETAS_VACIA)

            return result_list

        while Temporizador.obtener_tiempo_timer() <= tiempo_por_verificar:
            for carpeta in lista_carpetas:
                segundos = Temporizador.obtener_tiempo_timer() - tiempo_de_inicio

                if segundos > numero_de_segundos:
                    AccionesHtml.log.info(constantes_webdriver_actions.
                                          NAVEGACION_CARPETAS_SEG_LOG_INFO_NAVEGACION_CARPETAS_FINALIZADA)
                    break

                AccionesHtml.log.info(constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_LOG_INFO_INGRESO_CARPETA.
                                      format(carpeta))

                try:

                    if AccionesHtml.owa_descubierto == 2016:
                        elemento_html_carpeta = driver.execute_script(constantes_webdriver_actions.
                            NAVEGACION_CARPETAS_SEG_JS_LOCALIZAR_CARPETA_OWA_2016.format(
                            carpeta))

                        elemento_html_carpeta.click()
                        time.sleep(6)
                    elif AccionesHtml.owa_descubierto == 2010:
                        elemento_html_carpeta = driver.find_element_by_xpath(constantes_webdriver_actions.
                            NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2010.format(
                            carpeta))

                        time.sleep(3)
                        ValidacionesHTML.verificar_dialogo_de_interrupcion(driver, result_navegacion_carpetas)
                        time.sleep(3)
                        elemento_html_carpeta.click()
                    elif AccionesHtml.owa_descubierto == 2013:
                        elemento_html_carpeta = driver.execute_script(constantes_webdriver_actions.
                            NAVEGACION_CARPETAS_SEG_JS_LOCALIZAR_CARPETA_OWA_2013.format(
                            carpeta))

                        elemento_html_carpeta.click()
                        time.sleep(6)

                except selExcep.StaleElementReferenceException as e:

                    AccionesHtml.log.error(
                        constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_LOG_ERROR_STA_ELEM_REF_EXCEP
                            .format(FormatUtils.formatear_excepcion(e)))

                    driver.refresh()
                    time.sleep(3)
                except selExcep.ElementClickInterceptedException as e:

                    AccionesHtml.log.error(constantes_webdriver_actions.
                        NAVEGACION_CARPETAS_SEG_LOG_ERROR_ELEM_CLICK_INTERCEP_EXCEP.format(
                        FormatUtils.formatear_excepcion(e)))

                    driver.refresh()
                    time.sleep(3)
                except selExcep.NoSuchElementException as e:

                    AccionesHtml.log.error(
                        constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_LOG_ERROR_NO_SUCH_ELEM_EXCEP.format(
                            FormatUtils.formatear_excepcion(e)))

                    driver.refresh()
                    time.sleep(3)
                except selExcep.TimeoutException as e:

                    AccionesHtml.log.error(constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_LOG_ERROR_TIMEOUT_EXCEP.
                                           format(FormatUtils.formatear_excepcion(e)))

                    driver.refresh()
                    time.sleep(3)
                except selExcep.WebDriverException as e:

                    AccionesHtml.log.error(
                        constantes_webdriver_actions.NAVEGACION_CARPETAS_SEG_LOG_ERROR_WEBDRIVER_EXCEP.format(
                            FormatUtils.formatear_excepcion(e)))

                    time.sleep(3)

        result_navegacion_carpetas.finalizar_tiempo_de_ejecucion()
        result_navegacion_carpetas.establecer_tiempo_de_ejecucion()

        # verifica que no haya algun mensaje de error en la plataforma, en caso contrario se muestra el mensaje de
        # error que aparace en la plataforma dentro del result
        if ValidacionesHTML.verificar_error_plataforma(driver):
            msg_error = ValidacionesHTML.obtener_mensaje_error_plataforma(driver)
            result_navegacion_carpetas.validacion_correcta = False
            result_navegacion_carpetas.mensaje_error = constantes_webdriver_actions. \
                NAVEGACION_CARPETAS_SEG_MSG_ERROR_PLATAFORMA_OWA.format(msg_error)
        else:
            result_navegacion_carpetas.validacion_correcta = True
            result_navegacion_carpetas.mensaje_error = constantes_json.OUTPUT_EXITOSO_2_1

        result_list.result_validacion_navegacion_carpetas = result_navegacion_carpetas

        return result_list
Ejemplo n.º 10
0
    def navegar_a_portal_principal_owa(driver: WebDriver, url: str, result_list: ValidacionResultList):
        resultado = ResultStep()
        resultado.tiempo_inicio_de_ejecucion = 0
        resultado.inicializar_tiempo_de_ejecucion()

        AccionesHtml.log.info(constantes_webdriver_actions.NAVEGAR_SITIO_MSG_INGRESO_SITIO.format(url))

        try:
            driver.set_page_load_timeout(100)
            driver.get(url)

            resultado.mensaje_error = constantes_webdriver_actions.NAVEGAR_SITIO_MSG_INGRESO_SITIO_CON_EXITO. \
                format(url)

            resultado.validacion_correcta = True
            AccionesHtml.log.info(resultado.mensaje_error)

        except selExcep.TimeoutException as e:

            resultado.mensaje_error = constantes_webdriver_actions.NAVEGAR_SITIO_MSG_TIMEOUT_EXCEP_MSG_ERROR. \
                format(url, FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False
            AccionesHtml.log.error(resultado.mensaje_error)

        except selExcep.WebDriverException as e:

            resultado.mensaje_error = constantes_webdriver_actions.NAVEGAR_SITIO_MSG_WEBDRIVER_EXCEP_MSG_ERROR. \
                format(FormatUtils.formatear_excepcion(e))

            resultado.validacion_correcta = False
            AccionesHtml.log.error(resultado.mensaje_error)

        resultado.finalizar_tiempo_de_ejecucion()
        resultado.establecer_tiempo_de_ejecucion()
        result_list.result_validacion_ingreso_url = resultado

        return result_list