diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 16086b5b..ec42536f 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -49,6 +49,10 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest coverage pip install -r requirements.txt + pip install -e . + mkdir bin + wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz + tar xf geckodriver-v0.30.0-linux64.tar.gz -C bin/ - name: Prepare database env: @@ -62,6 +66,17 @@ jobs: psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION citext SCHEMA public;" psql -h "localhost" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE EXTENSION pg_trgm SCHEMA public;" + - name: Selenium tests + env: + SECRET_KEY: 'f00046306835001b55c230092e3a7990485beda0bc3bf732088d1ba1b5b74110e22e3f9ec3a24890272554b37d4' + DB_DATABASE: dh_test + FLASK_APP: examples/app.py + dhi: dbtest + run: | + alembic -x inventory=dbtest upgrade head + dh dummy --yes + flask run & pytest tests/test_selenium.py + - name: Lint with flake8 run: | # stop the build if: diff --git a/requirements.txt b/requirements.txt index 6f4bb6d9..2b3c20c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -42,6 +42,7 @@ sortedcontainers==2.1.0 tqdm==4.32.2 python-decouple==3.3 python-dotenv==0.14.0 +selenium==4.1.5 pyjwt==2.4.0 pint==0.9 py-dmidecode==0.1.0 diff --git a/tests/test_selenium.py b/tests/test_selenium.py new file mode 100644 index 00000000..866c2321 --- /dev/null +++ b/tests/test_selenium.py @@ -0,0 +1,90 @@ +# Generated by Selenium IDE +import time + +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.firefox.options import Options + + +class TestSelenium: + def setup_method(self, method): + options = Options() + options.add_argument("--headless") + self.driver = webdriver.Firefox( + options=options, executable_path=r'./bin/geckodriver' + ) + self.vars = {} + + def teardown_method(self, method): + self.driver.quit() + + def test_selenium(self): + # setup + self.driver.get("http://localhost:5000/login/") + self.driver.set_window_size(1920, 1063) + + # login + self.driver.find_element(By.ID, "yourEmail").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, "yourPassword").send_keys("1234") + self.driver.find_element(By.ID, "yourEmail").send_keys("user@dhub.com") + self.driver.find_element(By.CSS_SELECTOR, ".btn").click() + self.driver.implicitly_wait(3) + + # select the first lot and get the ID of it + self.driver.find_element(By.LINK_TEXT, "Temporary Lots").click() + self.driver.implicitly_wait(3) + self.driver.find_element( + By.CSS_SELECTOR, "#temporal-lots-nav > li:nth-child(2) span" + ).click() + self.driver.implicitly_wait(3) + lot_id = self.driver.current_url.split("/")[5] + + # go to unassigned + self.driver.find_element(By.CSS_SELECTOR, ".nav-item:nth-child(3) span").click() + self.driver.implicitly_wait(3) + + # select the first device + self.driver.find_element( + By.CSS_SELECTOR, "tr:nth-child(1) .deviceSelect" + ).click() + self.driver.implicitly_wait(3) + + # add to new selenium_lot + self.driver.find_element(By.ID, "btnLots").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, lot_id).click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, "ApplyDeviceLots").click() + time.sleep(3) + self.driver.find_element(By.ID, "SaveAllActions").click() + time.sleep(3) + + # go to selenium lot + self.driver.find_element(By.LINK_TEXT, "Temporary Lots").click() + self.driver.implicitly_wait(3) + self.driver.find_element( + By.CSS_SELECTOR, "#temporal-lots-nav > li:nth-child(2) span" + ).click() + self.driver.implicitly_wait(3) + + # select the first device + self.driver.find_element(By.CSS_SELECTOR, ".deviceSelect").click() + + # remove to new selenium_lot + self.driver.find_element(By.ID, "btnLots").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, lot_id).click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.ID, "ApplyDeviceLots").click() + time.sleep(3) + self.driver.find_element(By.ID, "SaveAllActions").click() + time.sleep(3) + + self.driver.find_element(By.CSS_SELECTOR, ".nav-item:nth-child(3) span").click() + self.driver.implicitly_wait(3) + + # logout + self.driver.find_element(By.CSS_SELECTOR, ".d-md-block").click() + self.driver.implicitly_wait(3) + self.driver.find_element(By.LINK_TEXT, "Sign Out").click()