def finalizar_tiempo_de_ejecucion(self):
     self.datetime_final = Temporizador.obtener_fecha_tiempo_actual()
     self.tiempo_fin_de_ejecucion = Temporizador.obtener_tiempo_timer()
     self.establecer_tiempo_de_ejecucion()
 def inicializar_tiempo_de_ejecucion(self):
     self.datetime_inicial = Temporizador.obtener_fecha_tiempo_actual()
     self.tiempo_inicio_de_ejecucion = Temporizador.obtener_tiempo_timer()
 def establecer_fecha_tiempo_de_inicio(objeto_json):
     objeto_json['start'] = Temporizador.obtener_fecha_tiempo_actual()
     return objeto_json
    def establecer_tiempo_de_finalizacion(objeto_json):
        objeto_json['time'] = Temporizador.obtener_tiempo_timer()
        # objeto_json['status'] = constantes_json.STATUS_CORRECTO
        objeto_json['end'] = Temporizador.obtener_fecha_tiempo_actual()

        return objeto_json
    def iniciar_sesion_en_owa(driver, correo_en_prueba, result_list):
        # verificacion en texto de mensajes de error en inicio de sesion
        error_security_context = 'NegotiateSecurityContext'

        # se obtiene la cuenta sin el origen del dominio
        SeleniumTesting.cuenta_sin_dominio = FormatUtils.formatear_correo(
            correo_en_prueba.correo)
        SeleniumTesting.url_owa_exchange = correo_en_prueba.url

        #xpath de botones owa 2010, 2016, 2013
        xpath_btn_owa_2010 = "//input[@type='submit'][@class='btn']"
        xpath_btn_owa_2013_2016 = "//div[@class='signinbutton']"

        driver.accept_insecure_certs = True
        driver.accept_untrusted_certs = True

        resultado = Result()

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

        # resultado.inicializar_tiempo_de_ejecucion()
        mensaje_error_de_credenciales = None

        try:
            # obtiene los elementos html para los campos de usuario, password y el boton de inicio de
            # sesion
            time.sleep(3)

            input_usuario = driver.find_element_by_id('username')
            input_password = driver.find_element_by_id('password')
            check_casilla_owa_2010_version_ligera = None
            boton_ingreso_correo = None

            # verifica si se encuentra la casilla con el id chkBsc, el cual pertenece a la version
            # ligera de la plataforma de Exchange 2010
            if SeleniumTesting.verificar_elemento_encontrado_por_id(
                    driver, 'chkBsc'):

                # selecciona el check para ingresar a la plataforma ligera
                check_casilla_owa_2010_version_ligera = driver.find_element_by_id(
                    'chkBsc')
                check_casilla_owa_2010_version_ligera.click()
                SeleniumTesting.owa_descubierto = 2010

            if SeleniumTesting.verificar_elemento_encontrado_por_xpath(
                    driver, xpath_btn_owa_2010):
                boton_ingreso_correo = driver.find_element_by_xpath(
                    xpath_btn_owa_2010)
                SeleniumTesting.owa_descubierto = 2010

            elif SeleniumTesting.verificar_elemento_encontrado_por_xpath(
                    driver, xpath_btn_owa_2013_2016):
                boton_ingreso_correo = driver.find_element_by_xpath(
                    xpath_btn_owa_2013_2016)

                # establece la bandera version owa por analizar
                SeleniumTesting.owa_descubierto = 2016

            # ingresa los datos en cada uno de los inputs localizados en el sitio de owa, uno por
            # cada segundo
            time.sleep(1)
            input_usuario.send_keys(correo_en_prueba.correo)

            time.sleep(1)
            input_password.send_keys(correo_en_prueba.password)

            time.sleep(1)
            boton_ingreso_correo.click()

            time.sleep(18)

            SeleniumTesting.log.info(
                'Titulo actual de la plataforma: {}'.format(driver.title))
            SeleniumTesting.log.info('URL actual de la plataforma: {}'.format(
                driver.current_url))

        except NoSuchElementException as e:

            resultado.mensaje_error = 'No fue posible iniciar sesion dentro de la plataforma OWA, '\
                                      'no se localizaron los inputs para ingresar las credenciales de la cuenta '\
                                      'de correo electronico Exchange: {}'.format(SeleniumTesting.formatear_excepcion(e))

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

        except WebDriverException as e:

            resultado.mensaje_error = 'No fue posible ingresar a la plataforma de Exchange OWA, favor de verificar'\
                ' si se tiene conectividad por internet, error detallado : {}'.format(SeleniumTesting.formatear_excepcion(e))
            resultado.validacion_correcta = False
            SeleniumTesting.log.error(resultado.mensaje_error)

        # verifica que se haya ingresado correctamente al OWA, se localiza si esta establecido
        # el mensaje de error de credenciales dentro del aplicativo del OWA

        if resultado.validacion_correcta == False:
            try:

                if SeleniumTesting.owa_descubierto == 2010:

                    mensaje_error_de_credenciales = driver.find_element_by_id(
                        'trInvCrd')

                    SeleniumTesting.log.error(
                        'No fue posible ingresar a la plataforma OWA, se tiene error de credenciales'
                    )
                    mensaje_error_de_credenciales = driver.find_element_by_xpath(
                        "//tr[@id='trInvCrd']/td")

                    texto_mensaje_error = mensaje_error_de_credenciales.get_attribute(
                        'innerHTML')

                    SeleniumTesting.log.error('Se muestra el siguiente mensaje de error de credenciales: {} '\
                                            .format(texto_mensaje_error))

                    resultado.mensaje_error = 'No fue posible ingresar a la plataforma OWA, se tiene error de credenciales: {}'\
                        .format(mensaje_error_de_credenciales.get_attribute('innerHTML'))

                    resultado.validacion_correcta = False

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

                    mensaje_error_de_credenciales = driver.execute_script('''
                    var mensaje_error = document.querySelector("#signInErrorDiv").innerText;
                    return mensaje_error;
                    ''')

                    SeleniumTesting.log.error(
                        'No se puede ingresar al aplicativo debido a error de credenciales:'
                    )
                    SeleniumTesting.log.error('Se muestra el siguiente mensaje de advertencia: {} '\
                                             .format(mensaje_error_de_credenciales))

                    resultado.mensaje_error = 'No fue posible ingresar a la plataforma OWA, se tiene error de credenciales: '\
                                              '{}'.format(mensaje_error_de_credenciales)

                    resultado.validacion_correcta = False

            except NoSuchElementException as e:
                resultado.mensaje_error = constantes_json.OUTPUT_EXITOSO_1_1
                resultado.validacion_correcta = True
                SeleniumTesting.log.info(resultado.mensaje_error)
            except InvalidSessionIdException as e:
                resultado.mensaje_error = 'No fue posible ingresar a la plataforma de Exchange OWA, favor de verificar '\
                                          'si se tiene conectividad por internet, error detallado : {}'.format(e)
                resultado.validacion_correcta = False
                SeleniumTesting.log.error(resultado.mensaje_error)
            except JavascriptException as e:
                # 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
                SeleniumTesting.log.info(resultado.mensaje_error)
            except WebDriverException as e:
                # 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
                SeleniumTesting.log.info(resultado.mensaje_error)

        # 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 SeleniumTesting.verificar_error_plataforma(driver):
            resultado.mensaje_error = 'No fue posible ingresar a la sesion, se presenta '\
                'el siguiente mensaje de error en la plataforma: {}'.format(SeleniumTesting.txt_mensaje_error_encontrado_owa)
            resultado.validacion_correcta = False

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

        return result_list