Esempio n. 1
0
class crearCorros:
    def __init__(self):
        self.urlProtocoe = 'http://3g2upl4pq6kufc4m.onion', 'https://mail.protonmail.com/create/new', 'https://singlelogin.org/registration.php', 'https://singlelogin.org/?logoutAll'
        print(self.urlProtocoe[2])
        self.tbb_dir = "/usr/local/share/tor-browser_en-US"
        self.protocoe = TorBrowserDriver(self.tbb_dir,
                                         tbb_logfile_path='test.log')
        self.dirNombre = '/home/dgc7/ejersiciosLibros/pyaton/ejemplos/scrapin/zlibrari/crearCorreos/nombre.txt'
        self.nombre = open(self.dirNombre, 'r+')
        self.dirapellido = '/home/dgc7/ejersiciosLibros/pyaton/ejemplos/scrapin/zlibrari/crearCorreos/apellidos.txt'
        self.apellido = open(self.dirapellido, 'r+')
        self.dirContrasenna = '/home/dgc7/ejersiciosLibros/pyaton/ejemplos/scrapin/zlibrari/crearCorreos/contraseña.txt'
        self.contrasenna = open(self.dirContrasenna, 'r+')
        self.dirCotrasenna2 = '/home/dgc7/ejersiciosLibros/pyaton/ejemplos/scrapin/zlibrari/crearCorreos/contraseña2.txt'
        self.Contrasenna2 = open(self.dirCotrasenna2, 'r+')
        self.datosContrasenna = []
        self.lista = []
        for self.d in range(0, 101):
            self.lista.append(self.nombre.readline() + 'asdsdf')
            self.datosContrasenna.append(self.contrasenna.readline() +
                                         "blabal")
        for self.d in range(0, 100):
            self.lista[self.d] = re.sub('\n', 'asdaawderca',
                                        self.lista[self.d])
            self.datosContrasenna[self.d] = re.sub(
                '\n', 'radabanals', self.datosContrasenna[self.d])
            self.lista[self.d] = re.sub(
                r"([^n\u0300-\u036f]|n(?!\u0303(?![\u0300-\u036f])))[\u0300-\u036f]+",
                r"\1", normalize("NFD", self.lista[self.d]), 0, re.I)
            self.lista[self.d] = normalize('NFC', self.lista[self.d])
            self.datosContrasenna[self.d] = re.sub(
                r"([^n\u0300-\u036f]|n(?!\u0303(?![\u0300-\u036f])))[\u0300-\u036f]+",
                r"\1", normalize("NFD",
                                 self.datosContrasenna[self.d]), 0, re.I)
            self.datosContrasenna[self.d] = normalize(
                'NFC', self.datosContrasenna[self.d])
            self.lista[self.d] += '@maildrop.cc'

    def iniciarTor(self):
        self.protocoe.load_url(self.urlProtocoe[3])

    def ingresarDatos(self, fila):
        self.eamil = self.protocoe.find_element_by_name('email')
        self.eamil.click()
        sleep(random.uniform(1.0, 4))
        self.eamil.send_keys(self.lista[fila])
        self.pasword = self.protocoe.find_element_by_name("password")
        self.pasword.click()
        sleep(random.uniform(1.0, 5))
        self.pasword.send_keys(self.datosContrasenna[fila])
        sleep(random.uniform(2.0, 4.7))
        self.pasword.send_keys(Keys.RETURN)
        sleep(20)
        self.protocoe.load_url('https://b-ok.cc/profile.php')
        self.resen = self.protocoe.find_element_by_xpath(
            '//a[@id="resendConfEmail"]')
        self.resen.click()
        sleep(4)
        self.alerta = self.protocoe.switch_to_alert()
        print(self.alerta.text)
        self.alerta.accept()

    def serrarTor(self):
        self.protocoe.close()

    def imprimirDatos(self):
        #self.dirscv='/home/dgc7/ejersiciosLibros/pyaton/ejemplos/scrapin/zlibrari/emailFalsos/contraseñasYcorreos.csv'
        #self.datos=csv.writer(open(self.dirscv,'w'))
        for d in range(0, 100):
            #self.datos.writerow([self.lista[d]])
            #self.datos.writerow([self.datosContrasenna[d]])
            print(self.lista[d])
            print(self.datosContrasenna[d])
Esempio n. 2
0
class UntitledTestCase(unittest.TestCase):
    def setUp(self):
        print 'Loading...'

        self.display = Display(visible=0, size=(800, 600))
        self.display.start()

        self.driver = TorBrowserDriver(
            '/scratch/zilton/troll/tor-browser_pt-BR/',
            tbb_logfile_path='test.log')

        # self.driver = webdriver.Chrome('chromium-browser')
        self.base_url = "https://lemonade.ctweb.inweb.org.br/#/workflows/1/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def is_visible(self, locator, timeout=20):
        try:
            ui.WebDriverWait(self.driver, timeout).until(
                ec.visibility_of_element_located((By.ID, locator)))
            return True
        except TimeoutException:
            return False

    def is_not_visible(self, locator, timeout=2):
        try:
            ui.WebDriverWait(self.driver, timeout).until_not(
                ec.visibility_of_element_located((By.ID, locator)))
            return True
        except TimeoutException:
            return False

    def test_untitled_test_case(self):
        global workflow_message_error_warning, workflow_message_completed

        driver = self.driver
        '''Login'''
        driver.get("https://lemonade.ctweb.inweb.org.br/#/login")
        driver.find_element_by_xpath("//input[@type='email']").clear()
        driver.find_element_by_xpath("//input[@type='email']").send_keys(
            lemonade_login)
        driver.find_element_by_xpath("//input[@type='password']").clear()
        driver.find_element_by_xpath("//input[@type='password']").send_keys(
            lemonade_password)
        driver.find_element_by_xpath("//button[@type='submit']").click()
        time.sleep(LOAD_TIME)

        count_progress = 1.0
        length = len(workflow_ids)
        index = 0
        count_problem = 1
        while index < length:
            workflow_id = workflow_ids[index]
            '''Access the page of the workflow'''
            url = self.base_url + str(workflow_id)
            driver.get(url)
            '''Execute the workflow'''
            while True:
                try:
                    time.sleep(LOAD_TIME * 0.2)
                    driver.find_element_by_id("tlb-execute-wf").click()
                    break
                except Exception:
                    pass

            while True:
                try:
                    time.sleep(LOAD_TIME * 0.2)
                    driver.find_element_by_id("mdl-execute-wf").click()
                    break
                except Exception:
                    pass
            '''Monitoring the status of the execution'''
            time.sleep(LOAD_TIME)
            status = WAITING_MSG
            current_url = driver.current_url

            # Workflow with problem
            if current_url == "https://lemonade.ctweb.inweb.org.br/#/" and count_problem < MAX_LOAD_PROBLEM:
                count_problem += 1
                continue
            elif count_problem == MAX_LOAD_PROBLEM:
                status = WARNING_MSG

            while (status is WAITING_MSG) or (status == RUNNING_MSG):
                while True:
                    try:
                        status = str(
                            driver.find_element_by_id("dtl-job-status").
                            get_attribute(name='title').upper())
                        if status:
                            break
                        time.sleep(LOAD_TIME * 0.2)
                    except Exception:
                        pass

                if (status == WAITING_MSG) or (status == RUNNING_MSG):
                    driver.refresh()
                    time.sleep(LOAD_TIME)
            '''Main message after the execution ends'''
            message = ''
            if status != WARNING_MSG:
                while message == '':
                    try:
                        message = driver.find_element_by_id(
                            "dtl-job-status-text").text
                        break
                    except Exception:
                        pass
                    driver.refresh()
                    time.sleep(LOAD_TIME)

            workflow_name = ''
            while True and count_problem < MAX_LOAD_PROBLEM:
                try:
                    time.sleep(LOAD_TIME * 0.2)
                    workflow_name = driver.find_element_by_xpath(
                        "//a[contains(@href, '#/workflows/1/%s')]" %
                        workflow_id).text
                    break
                except Exception:
                    pass

            if status == WARNING_MSG:
                message += ' - The execution presented an atypical problem. ' \
                           'Please check the workflow and the correct ' \
                           'update of the messages on the Lemonade page.'

            msg_dict = {
                'workflow_name': workflow_name,
                'workflow_id': workflow_id,
                'message': message,
                'status': status,
                'url': url
            }

            if status != COMPLETED_MSG:
                workflow_message_error_warning.append(msg_dict)
            else:
                workflow_message_completed += " " + workflow_id

            UntitledTestCase.update_progress(
                job_title='Testing Lemonade workflow: ',
                progress=count_progress)
            count_progress += 1

            index += 1
            count_problem = 1

        self.driver.close()

    @staticmethod
    def update_progress(job_title, progress):
        global workflow_ids
        length = len(workflow_ids)
        progress = progress / length
        block = int(round(length * progress))
        message = "\r{0}: [{1}] {2}%".format(
            job_title, ', '.join(workflow_ids[:int(progress * length)]) + "-" *
            (length - block), round(progress * 100, 2))
        if progress >= 1:
            message += " DONE\r\n"
        sys.stdout.write(message)
        sys.stdout.flush()

    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException:
            return False
        return True

    def is_alert_present(self):
        try:
            self.driver.switch_to_alert()
        except NoAlertPresentException:
            return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally:
            self.accept_next_alert = True

    def tearDown(self):
        UntitledTestCase.sendEmail()
        self.driver.quit()
        self.display.stop()
        self.assertEqual([], self.verificationErrors)

    @staticmethod
    def sendEmail():
        global workflow_message_error_warning, workflow_message_completed

        if len(workflow_message_error_warning) > 0:
            workflow_message_completed = re.sub("^\s+|\s+$", "",
                                                workflow_message_completed)

            message = 'WORKFLOWS THAT PERFORMED CORRECTLY: %s' % (
                workflow_message_completed.replace(' ', ', '))
            message += '\n\nWORKFLOWS THAT DID NOT RUN SUCCESSFULLY:\n'
            for m in workflow_message_error_warning:
                if m['status'] == WARNING_MSG:
                    message += '\n- WORKFLOW: %s' % m['workflow_id']
                else:
                    message += '\n- WORKFLOW: %s' % m['workflow_name']
                message += '\n\tSTATUS: %s' % m['status']
                message += '\n\tMESSAGE: %s' % m['message']
                message += '\n\tURL: %s' % m['url']
                message += '\n___________________________\n'

            subject = "[LEMONADE] - Automatic Test for Workflows"

            email_sender.main(message_status_report=message.encode('utf-8'),
                              subject=subject)