Beispiel #1
0
def _locate_customer(driver, job_data):
    small_wait = WebDriverWait(driver, 8)
    account_nick = job_data['branch'] + job_data['account']
    account_nick = account_nick.strip()

    logger.info("Locating customer: Nick({}) Name({})".format(account_nick, job_data['fullname']))

    # 1. First locate ITAU customer by using its nickname
    try:
        search_box = driver.wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@name="FOCO"]')))
        search_box.click()
        search_box.clear()
        search_box.send_keys(account_nick)
    except TimeoutException:
        logger.critical('Unable to locate element: //input[@name="FOCO"]')
        return operation_codes.OP_TIMEOUT

    logger.info("Search box found! submitting search...")

    # 2. Submit search
    try:
        submit_btn = small_wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@name="Sub1"]')))
        submit_btn.click()
    except TimeoutException:
        logger.critical('Unable to locate submit button: //input[@name="Sub1"]')
        return operation_codes.OP_TIMEOUT

    time.sleep(2)

    navigation.switch_to_frame(driver, 'CORPO')

    logger.info("Query submitted, trying to locate customer in result table...")

    # 4. Select customer in table
    select_xpath = '//*[text()="{}"]/../..//a[@class="TabelaSelecionar"]'.format(account_nick)
    try:
        customer = small_wait.until(EC.element_to_be_clickable((By.XPATH, select_xpath)))
        customer.click()
    except TimeoutException:
        logger.info("Unable to select customer: {}".format(select_xpath))

        logger.info("Verifying if customer must be added/registered...")

        # 3. Check if customer exists.
        check_if_customer_not_exists_xtag = '//span[contains(text(), "o existe favorecido cadastrado") and @class="MsgTxt"]'
        try:
            small_wait.until(EC.visibility_of_element_located, check_if_customer_not_exists_xtag)
        except TimeoutException:
            logger.info("Customer not found! Need to be registered first.")
            return operation_codes.OP_CUSTOMER_NOT_FOUND

    # Customer was found, good.
    return operation_codes.OP_SUCCESS
Beispiel #2
0
def _register_tef(driver, job_data):
    navigation.switch_to_frame(driver, "CORPO")

    small_wait = WebDriverWait(driver, 8)

    logger.info("Filling in TEF form...")
    try:
        # TEF amount
        _fill_input(small_wait, '//input[@name="valor" and @size="16"]', job_data['amount'])

        _fill_input(small_wait, '//input[@id="FOCO"]', job_data['day'])
        _fill_input(small_wait, '//input[@name="mes"]', job_data['month'])
        _fill_input(small_wait, '//input[@name="ano"]', job_data['year'])

    except TimeoutException as ex:
        logger.critical('Timeout when filling in form: {}'.format(str(ex)))
        return operation_codes.OP_TIMEOUT

    logger.info("Submitting TEF...")
    submit_xtag = '//input[@name="Enviar" and @type="button"]'
    try:
        submit_btn = driver.find_element(By.XPATH, submit_xtag)
        submit_btn.click()
    except NoSuchElementException:
        logger.critical("Unable to locate submit button: {}".format(submit_xtag))
        return operation_codes.OP_FAILED

    time.sleep(3)

    logger.info("TEF submitted, checking if operation was approved...")
    success_xpath = '//*[contains(text(), "sucesso")]'
    try:
        small_wait.until(EC.visibility_of_element_located((By.XPATH, success_xpath)))
    except TimeoutException as ex:
        logger.critical("Unable to find operation approval status!")
        return operation_codes.OP_FAILED

    logger.info("TEF successfully registered!")

    return operation_codes.OP_SUCCESS
Beispiel #3
0
    def transfer_bank(self, job_data):
        self.init_driver()
        try:
            if not login(self.ninja.config, self.web_driver):
                self.ninja.confirm_job(job_data, status='err_itau_login', status_message='Unable to login',
                                       admin_message='Failed to login on Itau.')
                self.ninja.take_ss(self.web_driver)
                return

            time.sleep(4)

            if not navigation.goto_screen(self.web_driver, 'transfer_bank'):
                self.ninja.confirm_job(job_data, status='err_itau_navigation', status_message='Unable to navigate',
                                       admin_message='Failed to navigate to <Transferencias> screen')
                self.logger.critical("Unable to navigate on ITAU web page as expected. Aborting...")
                self.ninja.take_ss(self.web_driver)
                return

            self.logger.debug("Trying to locate TAB Transferencias...")

            navigation.switch_to_frame(self.web_driver, 'CORPO')
            # Locate Transferencias TAB
            try:
                tab_xpath = '//td[contains(text(), "Transfer") and @class="TRNdado"]'
                tab_element = self.web_driver.wait.until(EC.element_to_be_clickable((By.XPATH, tab_xpath)))
                tab_element.click()
            except TimeoutException:
                self.logger.error('Unable to locate element: {}'.format(tab_xpath))
                self.ninja.confirm_job(job_data, status='err_itau_navigation',
                                       status_message='Unable find TAB <Transferencias>',
                                       admin_message='Unable find TAB <Transferencias>')
                self.ninja.take_ss(self.web_driver)
                return

            # -----------------------------------------------
            #  PROCESS TED/TEF/DOC
            # -----------------------------------------------
            op_code = operation_codes.OP_FAILED

            if job_data['account_type'] == 'CH':
                if job_data['bank_id'] == "341":
                    op_code = tef_ch.execute(self.web_driver, job_data)  # ITAU: TEF between checking accoun
                else:
                    op_code = ted_doc.execute(self.web_driver, job_data)  # TED

            elif job_data['account_type'] == 'SV':
                if job_data['bank_id'] == "341":
                    op_code = operation_codes.OP_FAILED
                else:
                    op_code = operation_codes.OP_FAILED

            if op_code == operation_codes.OP_SUCCESS:
                self.ninja.confirm_job(job_data)
            else:
                msg = "Operation Failed"
                if op_code == operation_codes.OP_CUSTOMER_NOT_FOUND:
                    msg += ": Customer not registered"
                elif op_code == operation_codes.OP_TIMEOUT:
                    msg += ": Timed out"

                self.ninja.confirm_job(job_data, "err_operation_failed", status_message=msg, admin_message=msg)
                self.ninja.take_ss(self.web_driver)
        finally:
            pass
Beispiel #4
0
def _register_ted(driver, job_data):
    time.sleep(1)
    navigation.switch_to_frame(driver, "CORPO")
    time.sleep(1)

    small_wait = WebDriverWait(driver, 8)

    logger.info("Filling in TED form...")
    try:
        # TEF amount
        _fill_input(small_wait, '//input[@id="dia"]', job_data['day'])
        _fill_input(small_wait, '//input[@id="mes"]', job_data['month'])
        _fill_input(small_wait, '//input[@id="ano"]', job_data['year'])

        _fill_input(small_wait, '//input[@name="valor" and @size="16"]', job_data['amount'])

    except TimeoutException as ex:
        logger.critical('Timeout when filling in form: {}'.format(str(ex)))
        return operation_codes.OP_TIMEOUT

    # If checking account, must select "Credit on account" purpose of the operation
    if job_data['account_type'] == 'CH':
        try:
            # Operation code: Credit on account
            credit_op_xpath = '//select[@id="Finalidade"]/option[@value="9"]'
            op_element = driver.find_element(By.XPATH, credit_op_xpath)
            op_element.click()
        except NoSuchElementException:
            logger.critical("Unable to select operation code element : {}".format(credit_op_xpath))
            return operation_codes.OP_FAILED

    # navigation.switch_to_frame(driver, "CORPO")

    logger.info("Locating submit button...")
    submit_xtag = '//input[@name="Incluir" and @type="button"]'

    try:
        submit_btn = small_wait.until(EC.element_to_be_clickable((By.XPATH, submit_xtag)))
        hover = ActionChains(driver).move_to_element(submit_btn)
        hover.perform()
        logger.info("Submitting TED...")

        click_action = ActionChains(driver).click(submit_btn)
        click_action.perform()
    except TimeoutException:
        logger.critical("Unable to locate submit button: {}".format(submit_xtag))
        return operation_codes.OP_FAILED

    time.sleep(3)

    logger.info("TED submitted, checking if operation was approved...")
    success_xpath = '//*[contains(text(), "sucesso")]'
    try:
        small_wait.until(EC.visibility_of_element_located((By.XPATH, success_xpath)))
    except TimeoutException as ex:
        logger.critical("Unable to find operation approval status!")
        return operation_codes.OP_FAILED

    logger.info("TEF successfully registered!")

    return operation_codes.OP_SUCCESS