This commit is contained in:
2022-07-07 21:40:37 +02:00
parent c03c13886f
commit e1a50c88df
17 changed files with 352 additions and 322 deletions

1
python_flask/selenium/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/venv/

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
xtightvncviewer 127.0.0.1::5900 -passwd <(printf %s secret | vncpasswd -f)

View File

@@ -0,0 +1,3 @@
helium==3.0.8
selenium==3.141.0
urllib3==1.26.10

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
docker run \
--rm \
--publish 4444:4444 \
--env SE_OPTS="--session-timeout 36000" \
--shm-size="2g" \
--net=host \
--name docker-selenium \
selenium/standalone-firefox:4.3.0-20220706

11
python_flask/selenium/setup.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -p pipefail
python3 -m venv ./venv
source ./venv/bin/activate
python3 -m pip install -r requirements.txt
sudo apt install tigervnc-common xtightvncviewer

66
python_flask/selenium/test.py Executable file
View File

@@ -0,0 +1,66 @@
#!/usr/bin/env python3
import time
from helium import *
import selenium
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
opts = selenium.webdriver.firefox.options.Options()
profile = selenium.webdriver.FirefoxProfile()
profile.set_preference("javascript.enabled", "false")
profile.DEFAULT_PREFERENCES['frozen']['javascript.enabled'] = False
opts.profile = profile
driver = selenium.webdriver.Remote(
command_executor="http://localhost:4444/wd/hub",
options=opts,
)
driver.implicitly_wait(0)
Config.implicit_wait_secs = 1
try:
helium.set_driver(driver)
helium.go_to("http://localhost:5000")
assert driver.title == "Packager"
new_entry = Text("Add new package list")
lists_before = find_all(S("table > tbody > tr", below=Text("Package Lists")))
write("newlist", into=TextField(to_right_of="Name"))
write("newlistdesc", into=TextField(to_right_of="Description"))
click(Button("Add"))
lists_after = find_all(S("table > tbody > tr", below=Text("Package Lists")))
assert len(lists_before) == len(lists_after) - 1
nameidx = next(i for i,v in enumerate(find_all(S("table > thead > tr > th"))) if v.web_element.text == "Name")
descidx = next(i for i,v in enumerate(find_all(S("table > thead > tr > th"))) if v.web_element.text == "Description")
new_entry = lists_after[-1]
cells = new_entry.web_element.find_elements_by_tag_name("td")
assert cells[nameidx].text == "newlist"
assert cells[descidx].text == "newlistdesc"
lists_before = lists_after
deletebtn = new_entry.web_element.find_element_by_class_name("mdi-delete")
click(deletebtn)
lists_after = find_all(S("table > tbody > tr", below=Text("Package Lists")))
assert len(lists_before) - 1 == len(lists_after)
import code; code.interact(local=locals())
time.sleep(5)
finally:
driver.quit()