def localizar_boton_perfil_usuario(driver: WebDriver, timeout: int = 7):
        tiempo_limite = Temporizador.obtener_tiempo_timer() + timeout

        while Temporizador.obtener_tiempo_timer() < tiempo_limite:

            # verifica si encontro folder en caso de estar en plataforma OWA 2013
            if ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.
                    CERRAR_SESION_BTN_PERFIL_USUARIO_OWA_2013):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    CERRAR_SESION_BTN_PERFIL_USUARIO_OWA_2013)

            # verifica si encontro folder en caso de estar en plataforma OWA 2016
            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.
                    CERRAR_SESION_BTN_PERFIL_USUARIO_OWA_2016):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    CERRAR_SESION_BTN_PERFIL_USUARIO_OWA_2016)

        raise SelExcept.TimeoutException(
            msg=
            'No fue posible localizar el boton de perfil del usuario dentro de la '
            'plataforma')
    def obtener_carpeta_con_timeout(driver: WebDriver,
                                    nombre_de_la_carpeta: str,
                                    timeout: int = 7):
        tiempo_limite = Temporizador.obtener_tiempo_timer() + timeout

        while Temporizador.obtener_tiempo_timer() < tiempo_limite:

            # verifica si encontro folder en caso de estar en plataforma OWA 2010
            if ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver,
                    constantes_webdriver_actions.
                    NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2010.format(
                        nombre_de_la_carpeta)):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2010.format(
                        nombre_de_la_carpeta))

            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver,
                    constantes_webdriver_actions.
                    NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2013.format(
                        nombre_de_la_carpeta)):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2013.format(
                        nombre_de_la_carpeta))

            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver,
                    constantes_webdriver_actions.
                    NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2016.format(
                        nombre_de_la_carpeta)):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    NAVEGACION_CARPETAS_SEG_XPATH_CARPETA_OWA_2016.format(
                        nombre_de_la_carpeta))

        raise SelExcept.TimeoutException(
            msg='No fue posible localizar la carpeta dentro de la plataforma')
Example #3
0
    def obtener_carpetas_en_sesion(driver: WebDriver):

        lista_de_carpetas_localizadas = []
        lista_nombres_de_carpetas_formateadas = []
        tiempo_de_inicio = Temporizador.obtener_tiempo_timer()
        tiempo_de_finalizacion = 0
        se_encontraron_carpetas = False

        while tiempo_de_finalizacion < 60:
            time.sleep(10)

            if ValidacionesHTML.verificar_elemento_encontrado_por_clase_js(
                    driver, constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_CSS_CARPETA_OWA_2016):
                AccionesHtml.owa_descubierto = 2016
                se_encontraron_carpetas = True
            elif ValidacionesHTML.verificar_elemento_encontrado_por_clase_js(
                    driver, constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_CSS_CARPETA_OWA_2013):
                AccionesHtml.owa_descubierto = 2013
                se_encontraron_carpetas = True
            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_XPATH_CARPETA_OWA_2010):
                AccionesHtml.owa_descubierto = 2010
                se_encontraron_carpetas = True

            tiempo_de_finalizacion = Temporizador.obtener_tiempo_timer() - tiempo_de_inicio

            if tiempo_de_finalizacion % 20 == 0:
                AccionesHtml.navegar_a_portal_principal_owa(AccionesHtml.url_owa_exchange)
                driver.refresh()

        if not se_encontraron_carpetas:
            tiempo_de_finalizacion = Temporizador.obtener_tiempo_timer() - tiempo_de_inicio
        else:
            time.sleep(4)

            if AccionesHtml.owa_descubierto == 2010:
                lista_de_carpetas_localizadas = driver.find_elements_by_xpath(
                    constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_XPATH_CARPETA_OWA_2010)
            elif AccionesHtml.owa_descubierto == 2013:
                lista_de_carpetas_localizadas = driver.execute_script(constantes_webdriver_actions.
                                                                      OBTENER_CARPETAS_EN_SESION_JS_OBTENER_CARPETA_2013)
            elif AccionesHtml.owa_descubierto == 2016:
                lista_de_carpetas_localizadas = driver.execute_script(constantes_webdriver_actions.
                                                                      OBTENER_CARPETAS_EN_SESION_JS_OBTENER_CARPETA_2016)

        for carpeta in lista_de_carpetas_localizadas:

            if AccionesHtml.owa_descubierto == 2010:
                nombre_de_carpeta = carpeta.text
            else:
                nombre_de_carpeta = FormatUtils.remover_backspaces(carpeta.get_attribute('innerHTML'))

            lista_nombres_de_carpetas_formateadas.append(nombre_de_carpeta)

        return lista_nombres_de_carpetas_formateadas
    def localizar_boton_cierre_sesion_owa_2013_2016(driver: WebDriver,
                                                    timeout: int = 7):
        tiempo_limite = Temporizador.obtener_tiempo_timer() + timeout

        while Temporizador.obtener_tiempo_timer() < tiempo_limite:

            # verifica si encontro folder en caso de estar en plataforma OWA 2016
            if ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.
                    CERRAR_SESION_BTN_XPATH_CIERRE_SESION_OWA_2016_ENGLISH):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    CERRAR_SESION_BTN_XPATH_CIERRE_SESION_OWA_2016_ENGLISH)

            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.
                    CERRAR_SESION_BTN_XPATH_CIERRE_SESION_OWA_2016_SPANISH):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    CERRAR_SESION_BTN_XPATH_CIERRE_SESION_OWA_2016_SPANISH)

            # verifica si encontro folder en caso de estar en plataforma OWA 2013
            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.
                    CERRAR_SESION_BTN_XPATH_CIERRE_SESION_OWA_2013):

                return driver.find_element_by_xpath(
                    constantes_webdriver_actions.
                    CERRAR_SESION_BTN_XPATH_CIERRE_SESION_OWA_2013)

        raise SelExcept.TimeoutException(
            msg=
            'No fue posible localizar el boton de cierre de sesion dentro de la '
            'plataforma')
    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 obtener_carpetas_en_sesion(driver: WebDriver):

        lista_de_carpetas_localizadas = []
        lista_nombres_de_carpetas_formateadas = []
        tiempo_de_inicio = Temporizador.obtener_tiempo_timer()
        tiempo_de_finalizacion = 0
        se_encontraron_carpetas = False

        while tiempo_de_finalizacion < 60:
            time.sleep(10)

            if ValidacionesHTML.verificar_elemento_encontrado_por_clase_js(
                    driver, constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_CSS_CARPETA_OWA_2016):
                AccionesHtml.owa_descubierto = 2016
                se_encontraron_carpetas = True
            elif ValidacionesHTML.verificar_elemento_encontrado_por_clase_js(
                    driver, constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_CSS_CARPETA_OWA_2013):
                AccionesHtml.owa_descubierto = 2013
                se_encontraron_carpetas = True
            elif ValidacionesHTML.verificar_elemento_encontrado_por_xpath(
                    driver, constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_XPATH_CARPETA_OWA_2010):
                AccionesHtml.owa_descubierto = 2010
                se_encontraron_carpetas = True

            tiempo_de_finalizacion = Temporizador.obtener_tiempo_timer() - tiempo_de_inicio

            if tiempo_de_finalizacion % 20 == 0:
                AccionesHtml.navegar_a_portal_principal_owa(AccionesHtml.url_owa_exchange)
                driver.refresh()

            if se_encontraron_carpetas:
                AccionesHtml.log.info(constantes_webdriver_actions.
                    OBTENER_CARPETAS_EN_SESION_LOG_INFO_LOCALIZACION_EXITOSA_CARPETAS.format(
                    FormatUtils.
                        truncar_float_cadena(tiempo_de_finalizacion)))
                break
            else:
                AccionesHtml.log.error(constantes_webdriver_actions.
                                       OBTENER_CARPETAS_EN_SESION_LOG_ERROR_LOCALIZACION_SIN_EXITO_CARPETAS)

                AccionesHtml.log.info(constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_MOSTRAR_TITLE_AND_URL
                                      .format(driver.title, driver.current_url))

        if not se_encontraron_carpetas:

            tiempo_de_finalizacion = Temporizador.obtener_tiempo_timer() - tiempo_de_inicio

            AccionesHtml.log.error(constantes_webdriver_actions.
                OBTENER_CARPETAS_EN_SESION_LOG_ERROR_LOCALIZACION_SIN_EXITO_CARPETAS_EXCESO_TIEMPO.format(
                FormatUtils.truncar_float_cadena(tiempo_de_finalizacion)))

            AccionesHtml.log.info(constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_MOSTRAR_TITLE_AND_URL
                                  .format(driver.title, driver.current_url))

        else:
            AccionesHtml.log.info(constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_OWA_LOCALIZADO.format(
                AccionesHtml.owa_descubierto))

            time.sleep(4)

            if AccionesHtml.owa_descubierto == 2010:
                lista_de_carpetas_localizadas = driver.find_elements_by_xpath(
                    constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_XPATH_CARPETA_OWA_2010)
            elif AccionesHtml.owa_descubierto == 2013:
                lista_de_carpetas_localizadas = driver.execute_script(constantes_webdriver_actions.
                                                                      OBTENER_CARPETAS_EN_SESION_JS_OBTENER_CARPETA_2013)
            elif AccionesHtml.owa_descubierto == 2016:
                lista_de_carpetas_localizadas = driver.execute_script(constantes_webdriver_actions.
                                                                      OBTENER_CARPETAS_EN_SESION_JS_OBTENER_CARPETA_2016)

        for carpeta in lista_de_carpetas_localizadas:

            if AccionesHtml.owa_descubierto == 2010:
                nombre_de_carpeta = carpeta.text
            else:
                nombre_de_carpeta = FormatUtils.remover_backspaces(carpeta.get_attribute('innerHTML'))

            AccionesHtml.log.info(constantes_webdriver_actions.OBTENER_CARPETAS_EN_SESION_OWA_CARPETA_OBTENIDA.
                                  format(nombre_de_carpeta))

            lista_nombres_de_carpetas_formateadas.append(nombre_de_carpeta)

        return lista_nombres_de_carpetas_formateadas