Skip to content

Commit 02ce698

Browse files
committed
update test selenium
1 parent 75703c1 commit 02ce698

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
venv*
2-
users.json
3-
log.txt
2+
users*
3+
log*
44
imgs/*.png
55
chromedriver*
66
test_bot.py

requirements.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
beautifulsoup4==4.12.2
2-
certifi==2023.5.7
3-
charset-normalizer==3.1.0
4-
idna==3.4
5-
pyTelegramBotAPI==4.11.0
6-
requests==2.30.0
2+
pyTelegramBotAPI==4.12.0
3+
Requests==2.31.0
74
schedule==1.2.0
8-
soupsieve==2.4.1
9-
urllib3==2.0.2
5+
selenium==4.10.0
6+
urllib3==2.0.3

test_selenium.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,43 @@
22

33
from selenium import webdriver
44
from selenium.webdriver.chrome.service import Service
5+
from selenium.webdriver.chrome.options import Options
6+
from selenium.webdriver.support import expected_conditions
7+
from selenium.webdriver.common.by import By
8+
from selenium.webdriver.support.ui import WebDriverWait
9+
from bs4 import BeautifulSoup
510

6-
#driver = webdriver.Chrome(service = service) # Optional argument, if not specified will search path.
11+
DEFAULT_TEXT = " Schritt 3 von 5 : Terminvorschläge - Keine Zeiten verfügbar "
12+
URL1 = "https://termine.staedteregion-aachen.de/auslaenderamt/"
13+
URL2 = "https://termine.staedteregion-aachen.de/auslaenderamt/select2?md=1"
14+
URL3 = "https://termine.staedteregion-aachen.de/auslaenderamt/suggest?mdt=75&select_cnc=1&cnc-204=0&cnc-205=0&cnc-198=0&cnc-201=0&cnc-202=0&cnc-227=0&cnc-189=0&cnc-203=0&cnc-196=0&cnc-190=0&cnc-185=0&cnc-187=0&cnc-188=0&cnc-186=0&cnc-192=0&cnc-191=1&cnc-194=0&cnc-197=0&cnc-193=0&cnc-183=0&cnc-184=0&cnc-195=0&cnc-200=0&cnc-225=0"
715

16+
print("Starting Selenium Test")
17+
18+
options = Options()
19+
options.add_argument("--headless=new")
820
service = Service(executable_path="/usr/bin/chromedriver")
9-
driver = webdriver.Chrome(service = service)
21+
driver = webdriver.Chrome(service = service, options=options)
22+
driver.get(URL1)
23+
time.sleep(3) # Let the user actually see something!
24+
cookie = driver.find_element(by="id", value="cookie_msg_btn_yes")
25+
cookie.click()
26+
time.sleep(2)
27+
driver.get(URL2)
28+
time.sleep(2)
29+
driver.get(URL3)
30+
WebDriverWait(driver, 20).until(expected_conditions.visibility_of_element_located((By.NAME, "select_location")))
31+
element = driver.find_element(by=By.NAME, value="select_location")
1032

11-
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
12-
time.sleep(5) # Let the user actually see something!
33+
element.click()
1334

35+
time.sleep(2)
1436
driver.save_screenshot('screen.png')
15-
time.sleep(5) # Let the user actually see something!
1637

17-
driver.quit()
38+
soup = BeautifulSoup(driver.page_source, "html.parser")
39+
inhalt = soup.find(id="inhalt")
40+
title_element = inhalt.find("h1")
41+
driver.quit()
42+
43+
print(title_element.text)
44+
print(title_element.text == DEFAULT_TEXT)

0 commit comments

Comments
 (0)