Skip to content

Commit

Permalink
first try of Dockerfile_selenium
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinaProsche committed Feb 23, 2024
1 parent 0145493 commit 83e8fa4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
13 changes: 13 additions & 0 deletions Dockerfile_selenium
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM selenium/standalone-chrome:121.0-chromedriver-121.0-grid-4.18.0-20240220

WORKDIR /usr/src/project

USER root
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
rm -rf /var/lib/apt/lists/*

COPY tests ./tests
RUN pip install -r tests/requirements.txt

CMD ["python3", "tests/main.py", "--login", "admin", "--password", "admin"]
16 changes: 12 additions & 4 deletions tests/basic_selenium_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import unittest
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.common.by import By
from webdriver_manager.firefox import GeckoDriverManager #pip install webdriver-manager
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

class BasicSeleniumTest(unittest.TestCase):

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install())) #you should have Firefox, installed not from snap
chrome_options = Options()
service = Service(executable_path='/usr/bin/chromedriver')
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--disable-gpu")

driver = webdriver.Chrome(options=chrome_options, service=service)

def authorization(self):
host, login_param, password_param = self.param
URL = self.getUrl('/login')
print(111111111111111)
print(URL)
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
login = self.getDriver().find_element(By.ID, "login_text_field")
Expand Down
5 changes: 3 additions & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
selenium==4.16.0 #in this version you don't need to download geckodriver
webdriver-manager==4.0.1 #to avoid problem with binary
selenium==4.18.0
# webdriver-manager==4.0.1 #to avoid problem with binary
# ipython==7.0.1
10 changes: 5 additions & 5 deletions tests/test_statistic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import unittest
from basic_selenium_test import BasicSeleniumTest
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
Expand All @@ -11,8 +11,8 @@ def test_open_statistic(self):
self.getDriver().get(URL)
self.getDriver().implicitly_wait(30)
try:
string_in_table = self.getDriver().find_element(By.XPATH, "//table[@id='check-list-table']//tr/td/a")
self.assertNotEquals(string_in_table, None)
string_in_table = self.driver.find_element(By.XPATH, "//table[@id='check-list-table']//tr/td/a")
self.assertNotEqual(string_in_table, None)
except NoSuchElementException:
empty_table = self.getDriver().find_element(By.CLASS_NAME, "no-records-found")
self.assertNotEquals(empty_table, None)
empty_table = self.driver.find_element(By.CLASS_NAME, "no-records-found")
self.assertNotEqual(empty_table, None)

0 comments on commit 83e8fa4

Please sign in to comment.