Ejemplo n.º 1
0
 def __is_authenticated_session(driver: webdriver):
     """
     Return True if authenticated session cookie is set, False otherwise
     :param driver: webdriver
     :return:
     """
     return driver.get_cookie('li_at') is not None
Ejemplo n.º 2
0
def cycle_cita(driver: webdriver, context: CustomerProfile):
    driver.delete_all_cookies()
    try:
        driver.execute_script("window.localStorage.clear();")
        driver.execute_script("window.sessionStorage.clear();")
    except Exception as e:
        logging.error(e)
        pass

    fast_forward_url = "https://sede.administracionespublicas.gob.es/icpplustieb/acInfo?p={}&tramite={}".format(
        context.province, context.operation_code
    )
    while True:
        try:
            driver.set_page_load_timeout(300 if context.first_load else 50)
            driver.get(fast_forward_url)
        except TimeoutException:
            speaker.say("ATTENTION")
            logging.error("Timed out loading initial page")   # TODO add speaker
            continue
        break
    context.first_load = False
    session_id = driver.get_cookie("JSESSIONID").get("value")
    logging.info(session_id)

    # 3. Instructions page:
    try:
        WebDriverWait(driver, DELAY).until(EC.presence_of_element_located((By.ID, "btnEntrar")))
    except TimeoutException:
        logging.error("Timed out waiting for Instructions page to load")
        return None

    btn = driver.find_element_by_id("btnEntrar")
    btn.send_keys(Keys.ENTER)

    # 4. Data form:
    success = False
    if context.operation_code == OperationType.TOMA_HUELLAS:
        success = toma_huellas_step2(driver, context)
    elif context.operation_code == OperationType.RECOGIDA_DE_TARJETA:
        success = recogida_de_tarjeta_step2(driver, context)
    elif context.operation_code == OperationType.SOLICITUD:
        success = solicitud_step2(driver, context)
    elif context.operation_code == OperationType.BREXIT:
        success = brexit_step2(driver, context)
    elif context.operation_code == OperationType.CERTIFICADOS_UE:
        success = certificados_ue_step2(driver, context)
    elif context.operation_code == OperationType.AUTORIZACION_DE_REGRESO:
        success = autorizacion_de_regreso_step2(driver, context)
    elif context.operation_code == OperationType.FAMILIARES_RESIDENTES:
        success = familiares_residentes(driver, context)

    if not success:
        return None

    try:
        wait_exact_time(driver, context)
    except TimeoutException:
        logging.error("Timed out waiting for exact time")
        return None

    # 5. Solicitar cita:
    solcitar = solicitar_cita(driver, context)   # TODO need to fix or is catalan?
    if solcitar is None:
        return None

    # 6. phone-mail:
    return phone_mail(driver, context)
Ejemplo n.º 3
0
def cycle_cita(driver: webdriver, context: CustomerProfile):
    driver.delete_all_cookies()
    try:
        driver.execute_script("window.localStorage.clear();")
        driver.execute_script("window.sessionStorage.clear();")
    except Exception as e:
        logging.error(e)
        pass

    if context.fast_forward_url:
        while True:
            try:
                driver.set_page_load_timeout(300 if context.first_load else 50)
                driver.get(context.fast_forward_url)
            except TimeoutException:
                logging.error("Timed out loading initial page")
                continue
            break
        context.first_load = False
        session_id = driver.get_cookie("JSESSIONID").get("value")
        logging.info(session_id)
    else:
        driver.get(
            "https://sede.administracionespublicas.gob.es/icpplus/index.html")
        time.sleep(1)  # Let the user actually see something!

        # Select "Barcelona"
        select = Select(driver.find_element_by_id("form"))
        select.select_by_visible_text(context.city)

        btn = driver.find_element_by_id("btnAceptar")
        btn.send_keys(Keys.ENTER)

        # 2. Tramite selection:
        try:
            WebDriverWait(driver, DELAY).until(
                EC.presence_of_element_located((By.ID, "tramiteGrupo[1]")))
        except TimeoutException:
            logging.error("Timed out waiting for tramite to load")
            return None

        select = Select(driver.find_element_by_id("tramiteGrupo[1]"))
        # Select "Huellos"
        select.select_by_value(context.operation_code.value)

        btn = driver.find_element_by_id("btnAceptar")
        btn.send_keys(Keys.ENTER)

    # 3. Instructions page:
    try:
        WebDriverWait(driver, DELAY).until(
            EC.presence_of_element_located((By.ID, "btnEntrar")))
    except TimeoutException:
        logging.error("Timed out waiting for Instructions page to load")
        return None

    btn = driver.find_element_by_id("btnEntrar")
    btn.send_keys(Keys.ENTER)

    # 4. Data form:
    success = False
    if context.operation_code == OperationType.TOMA_HUELLAS:
        success = toma_huellas_step2(driver, context)
    elif context.operation_code == OperationType.RECOGIDA_DE_TARJETA:
        success = recogida_de_tarjeta_step2(driver, context)
    elif context.operation_code == OperationType.SOLICITUD:
        success = solicitud_step2(driver, context)

    if not success:
        return None

    try:
        wait_exact_time(driver, context)
    except TimeoutException:
        logging.error("Timed out waiting for exact time")
        return None

    # 5. Solicitar cita:
    btn = driver.find_element_by_id("btnEnviar")
    btn.send_keys(Keys.ENTER)

    for i in range(REFRESH_PAGE_CYCLES):
        try:
            WebDriverWait(driver, DELAY).until(
                EC.presence_of_element_located((By.TAG_NAME, "body")))
        except TimeoutException:
            logging.error("Timed out waiting for body to load")
            return None

        resp_text = driver.find_element_by_tag_name("body").text

        if "Seleccione la oficina donde solicitar la cita" in resp_text:
            logging.info("Towns hit! :)")

            # 6. Office selection:
            time.sleep(0.3)
            try:
                WebDriverWait(driver, DELAY).until(
                    EC.presence_of_element_located((By.ID, "btnSiguiente")))
            except TimeoutException:
                logging.error("Timed out waiting for offices to load")
                return None

            res = select_office(driver, context)
            if res is None:
                time.sleep(5)
                driver.refresh()
                continue

            btn = driver.find_element_by_id("btnSiguiente")
            btn.send_keys(Keys.ENTER)
            break
        elif "En este momento no hay citas disponibles" in resp_text:
            time.sleep(5)
            driver.refresh()
            continue
        else:
            logging.info("No towns")
            return None

    # 7. phone-mail:
    try:
        WebDriverWait(driver, DELAY).until(
            EC.presence_of_element_located((By.ID, "emailDOS")))
        logging.info("Email page hit")
    except TimeoutException:
        logging.error("Timed out waiting for phone/email to load")
        return None

    element = driver.find_element_by_id("txtTelefonoCitado")
    element.send_keys(context.phone)  # phone num

    element = driver.find_element_by_id("emailUNO")
    element.send_keys(context.email)

    element = driver.find_element_by_id("emailDOS")
    element.send_keys(context.email)

    btn = driver.find_element_by_id("btnSiguiente")
    btn.send_keys(Keys.ENTER)

    return cita_selection(driver, context)