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
|
#!/bin/sh
set -exu
python3 -m http.server 8088 --bind 127.0.0.1 --directory="$(pwd)" &
pid=$!
trap "kill $pid" EXIT
cat << END | python3
import sys
sys.path.remove('')
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--remote-debugging-port=9229")
chrome_options.add_argument("--window-size=1024x768")
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--no-sandbox")
service = ChromeService(executable_path="/usr/bin/chromedriver")
driver = webdriver.Chrome(options = chrome_options, service = service)
print("\nTry to get data from http://127.0.0.1:8088")
if driver.get("http://127.0.0.1:8088") == None:
print("Success.")
else:
print("Failed!")
sys.exit(1)
print("\nLooking for a link named 'debian/'")
link = driver.find_element(By.LINK_TEXT, "debian/").get_attribute("href")
if driver.page_source != None and link != "":
print(f"Success.\nFound href content '{link}'.")
else:
print("Failed!")
sys.exit(1)
print("\nTest seems to be successful!\nTest was using the following HTML data to test the Chrome webdriver.\n")
print("------------------------------- %< -------------------------------")
print(driver.page_source)
print("------------------------------- >% -------------------------------")
END
|