-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypos.py
More file actions
65 lines (50 loc) · 2.25 KB
/
Copy pathtypos.py
File metadata and controls
65 lines (50 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
from pyunitreport import HTMLTestRunner
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from time import sleep
import webbrowser
import os
class Typos(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver = self.driver
driver.maximize_window()
driver.get("http://the-internet.herokuapp.com/")
sleep(2)
driver.find_element(By.LINK_TEXT, 'Typos').click()
sleep(3)
def test_typos(self):
driver = self.driver
paragraph_to_check = driver.find_element(By.CSS_SELECTOR, '#content > div > p:nth-child(3)')
text_to_check = paragraph_to_check.text
print(text_to_check)
tries = 1
found = False
correct_text = "Sometimes you'll see a typo, other times you won't."
while text_to_check != correct_text:
paragraph_to_check = driver.find_element(By.CSS_SELECTOR, '#content > div > p:nth-child(3)')
text_to_check = paragraph_to_check.text
driver.refresh()
while not found:
if text_to_check == correct_text:
tries += 1
driver.refresh()
found = True
self.assertEqual(found, True)
print(f"It took {tries} tries to find the typo")
def tearDown(self) -> None:
driver = self.driver
driver.implicitly_wait(3)
self.driver.close()
# Ruta al ejecutable de Google Chrome:
chrome_path = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
# Abrir el archivo HTML generado como reporte al finalizar el script:
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
webbrowser.get('chrome').open('file://' + os.path.realpath('reports/single-reports/typos-report.html'))
if __name__ == '__main__':
unittest.main(verbosity= 2, testRunner= HTMLTestRunner(output= './single-reports', report_name='typos-report'))