From 83e8fa43cdfeeaba691594aba907fd046597b257 Mon Sep 17 00:00:00 2001 From: Marina Date: Fri, 23 Feb 2024 15:41:46 +0300 Subject: [PATCH] first try of Dockerfile_selenium --- Dockerfile_selenium | 13 +++++++++++++ tests/basic_selenium_test.py | 16 ++++++++++++---- tests/requirements.txt | 5 +++-- tests/test_statistic.py | 10 +++++----- 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 Dockerfile_selenium diff --git a/Dockerfile_selenium b/Dockerfile_selenium new file mode 100644 index 00000000..51a519f2 --- /dev/null +++ b/Dockerfile_selenium @@ -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"] diff --git a/tests/basic_selenium_test.py b/tests/basic_selenium_test.py index 0485faa1..cf5ad0b1 100644 --- a/tests/basic_selenium_test.py +++ b/tests/basic_selenium_test.py @@ -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") diff --git a/tests/requirements.txt b/tests/requirements.txt index c384f7a9..8a20b96e 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -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 diff --git a/tests/test_statistic.py b/tests/test_statistic.py index 0da75881..6ca1ca44 100644 --- a/tests/test_statistic.py +++ b/tests/test_statistic.py @@ -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 @@ -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)