|
| 1 | +#! /usr/bin/env python3 |
| 2 | + |
| 3 | +from http.server import HTTPServer, SimpleHTTPRequestHandler |
| 4 | +from selenium import webdriver |
| 5 | +from selenium.webdriver.common.by import By |
| 6 | +from selenium.webdriver.chrome.service import Service |
| 7 | +import sys |
| 8 | +import time |
| 9 | +import threading |
| 10 | + |
| 11 | +port = "8050" |
| 12 | +httpd = HTTPServer(("127.0.0.1", int(port)), SimpleHTTPRequestHandler) |
| 13 | + |
| 14 | +def run_server(): |
| 15 | + print("Serving HTTP on localhost port " + port + " (http://localhost:" + port + "/) ...") |
| 16 | + httpd.serve_forever() |
| 17 | + |
| 18 | +server_thread = threading.Thread(target=run_server) |
| 19 | +server_thread.start() |
| 20 | + |
| 21 | +service = Service(executable_path=r'/usr/bin/chromedriver') |
| 22 | +options = webdriver.ChromeOptions() |
| 23 | +options.add_argument('--headless') |
| 24 | +options.add_argument('--no-sandbox') |
| 25 | +options.add_argument('--disable-dev-shm-usage') |
| 26 | +options.add_argument('--disable-gpu') |
| 27 | +driver = webdriver.Chrome(service=service, options=options) |
| 28 | +print(f"connecting web driver to http://localhost:{port}/") |
| 29 | +driver.get(f"http://localhost:{port}/demo.html") |
| 30 | +asc_button = driver.find_element(By.ID, "btnAsc") |
| 31 | +desc_button = driver.find_element(By.ID, "btnDesc") |
| 32 | + |
| 33 | +asc_button.click() |
| 34 | +print("Wait for Asc button press") |
| 35 | +time.sleep(0.5) |
| 36 | +value = driver.find_element(By.ID, "txt").get_attribute("value") |
| 37 | +is_ascending_ok = value == "item1\nitem2\nitem3\nitem4\nitem5" |
| 38 | +print(f"text area on Sort Asc pressed:\n{value}") |
| 39 | +desc_button.click() |
| 40 | +print("Wait for Desc button press") |
| 41 | +time.sleep(0.5) |
| 42 | +value = driver.find_element(By.ID, "txt").get_attribute("value") |
| 43 | +print(f"text area on Sort Desc pressed:\n{value}") |
| 44 | +is_descending_ok = value == "item5\nitem4\nitem3\nitem2\nitem1" |
| 45 | + |
| 46 | +driver.quit() |
| 47 | +httpd.shutdown() |
| 48 | +server_thread.join() |
| 49 | +if is_ascending_ok and is_descending_ok: |
| 50 | + exit(0) |
| 51 | +print(f"is_ascending_ok = {is_ascending_ok}") |
| 52 | +print(f"is_descending_ok = {is_descending_ok}") |
| 53 | +exit(1) |
0 commit comments