| 1 | #!/bin/sh |
| 2 | |
| 3 | set -exu |
| 4 | |
| 5 | python3 -m http.server 8088 --bind 127.0.0.1 --directory="$(pwd)" & |
| 6 | pid=$! |
| 7 | trap "kill $pid" EXIT |
| 8 | |
| 9 | cat << END | python3 |
| 10 | import sys |
| 11 | sys.path.remove('') |
| 12 | import selenium |
| 13 | from selenium import webdriver |
| 14 | from selenium.webdriver.common.by import By |
| 15 | from selenium.webdriver.chrome.options import Options |
| 16 | from selenium.webdriver.chrome.service import Service as ChromeService |
| 17 | |
| 18 | chrome_options = Options() |
| 19 | chrome_options.add_argument("--headless") |
| 20 | chrome_options.add_argument("--remote-debugging-port=9229") |
| 21 | chrome_options.add_argument("--window-size=1024x768") |
| 22 | chrome_options.add_argument("--disable-setuid-sandbox") |
| 23 | chrome_options.add_argument("--no-sandbox") |
| 24 | |
| 25 | service = ChromeService(executable_path="/usr/bin/chromedriver") |
| 26 | driver = webdriver.Chrome(options = chrome_options, service = service) |
| 27 | |
| 28 | print("\nTry to get data from http://127.0.0.1:8088") |
| 29 | |
| 30 | if driver.get("http://127.0.0.1:8088") == None: |
| 31 | print("Success.") |
| 32 | else: |
| 33 | print("Failed!") |
| 34 | sys.exit(1) |
| 35 | |
| 36 | print("\nLooking for a link named 'debian/'") |
| 37 | link = driver.find_element(By.LINK_TEXT, "debian/").get_attribute("href") |
| 38 | |
| 39 | if driver.page_source != None and link != "": |
| 40 | print(f"Success.\nFound href content '{link}'.") |
| 41 | else: |
| 42 | print("Failed!") |
| 43 | sys.exit(1) |
| 44 | |
| 45 | print("\nTest seems to be successful!\nTest was using the following HTML data to test the Chrome webdriver.\n") |
| 46 | print("------------------------------- %< -------------------------------") |
| 47 | print(driver.page_source) |
| 48 | print("------------------------------- >% -------------------------------") |
| 49 | |
| 50 | END |