This is an automated email from the ASF dual-hosted git repository.

gjm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bloodhound-core.git


The following commit(s) were added to refs/heads/main by this push:
     new 4de51ac  Simplify working with selenium with docker
4de51ac is described below

commit 4de51aca83f4f54cf6cb6db295b6fb6c48be78e2
Author: Gary Martin <g...@apache.org>
AuthorDate: Wed Sep 8 01:04:07 2021 +0100

    Simplify working with selenium with docker
    
    With the assumption that docker can be run by the user, hopefully the
    updates to the instructions will make it more convenient to run selenium
    based tests with firefox in a consistent way across development
    platforms.
---
 README.md                  | 71 ++++++++++++++++++++++++++++------------------
 docker/docker-compose.yaml |  6 ++++
 functional_tests.py        | 20 ++++++-------
 3 files changed, 59 insertions(+), 38 deletions(-)

diff --git a/README.md b/README.md
index 50d021b..505d260 100644
--- a/README.md
+++ b/README.md
@@ -179,29 +179,37 @@ This may be replaced with pytest.
 Unit tests are run with the following command:
 
 ```
-poetry run python manage.py test
+poetry run python manage.py test trackers
 ```
 
 ## Integration Tests
 
-The [Selenium] tests currently require that Firefox is installed and
-[geckodriver] is also on the path. If you do not already have geckodriver,
-the following shows one method to get it for linux:
+The integration tests are based on [Selenium] and Firefox. For convenience of
+setup, these tests currently expect to connect to Selenium at
 
+  http://127.0.0.1:4444/wd/hub
+
+If you have docker-compose installed, the `selenium-firefox` container can be
+brought up from the `docker` directory with:
+
+```
+docker-compose up selenium-firefox -d
+```
+
+Or, with just docker (from any directory):
+
+```
+docker run -d --network host --privileged --name server \
+        docker.io/selenium/standalone-firefox
 ```
-PLATFORM_EXT="linux64.tar.gz"
-BIN_LOCATION="$HOME/.local/bin"
-TMP_DIR=/tmp/geckodriver_download
-mkdir -p "$BIN_LOCATION" "$TMP_DIR"
 
-LATEST=$(wget -O - https://github.com/mozilla/geckodriver/releases/latest 2>&1 
| awk 'match($0, /geckodriver-(v.*)-'"$PLATFORM_EXT"'/, a) {print a[1]; exit}')
-wget -N -P "$TMP_DIR" 
"https://github.com/mozilla/geckodriver/releases/download/$LATEST/geckodriver-$LATEST-$PLATFORM_EXT";
-tar -x geckodriver -zf "$TMP_DIR/geckodriver-$LATEST-$PLATFORM_EXT" -O > 
"$BIN_LOCATION"/geckodriver
-chmod +x "$BIN_LOCATION"/geckodriver
+Running the functional tests directly requires a running server and so run
+
+```
+poetry run python manage.py runserver
 ```
 
-If `$BIN_LOCATION` is on the system path, and the development server is
-running, it should be possible to run the integration tests.
+in one terminal and in a second:
 
 ```
 poetry run python functional_tests.py
@@ -211,7 +219,6 @@ There are currently not many tests - those that are there 
are in place to test
 the setup above and assume that there will be useful tests in due course.
 
 [Selenium]: https://selenium.dev/
-[geckodriver]: https://firefox-source-docs.mozilla.org/testing/geckodriver/
 
 ## Development notes:
 
@@ -276,23 +283,13 @@ The docker/db/scripts directory allows for the provision 
of valid sql commands
 in *sql files that will be copied into the container and used to initialize
 the database if required.
 
-If you have docker-compose installed, the db container can be brought up with:
+If you have docker-compose installed, the db container can be brought up from
+the `docker` directory with:
 
 ```
-docker-compose up -d
+docker-compose up db -d
 ```
 
-If you have podman instead of docker, it is possible to use docker-compose in
-a similar way. Consult [this article][Use docker-compose with podman] for the
-details but note that, at the time of writing, there is an error in the
-article and you need to use
-
-```
-export DOCKER_HOST=unix:///run/user/$UID/podman/podman.sock
-```
-
-[Use docker-compose with podman]: 
https://fedoramagazine.org/use-docker-compose-with-podman-to-orchestrate-containers-on-fedora/
-
 ### Specifying the Postgresql Backend
 
 Finally you will need to specify the database to connect to. At the moment
@@ -315,3 +312,21 @@ DATABASES = {
 
 Note that this aspect of the setup should be expected to change to smooth over
 some of the difficulties around editing a file that is in source control.
+
+## Notes on using podman instead of docker
+
+If you have podman instead of docker, the `podman` command should work as a
+drop-in replacement for `docker` commands where these are used in this README.
+
+It should also now be possible to use `docker-compose` commands directly with
+a little preparation. Consult [this article][Use docker-compose with podman]
+for details but note that, at the time of writing, there is an error in the
+article and you will need to use
+
+```
+export DOCKER_HOST=unix:///run/user/$UID/podman/podman.sock
+```
+
+to successfully run `docker-compose` commands.
+
+[Use docker-compose with podman]: 
https://fedoramagazine.org/use-docker-compose-with-podman-to-orchestrate-containers-on-fedora/
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index 5ad7b41..e00d866 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -9,3 +9,9 @@ services:
       - POSTGRES_PASSWORD=postgres
     ports:
       - 5432:5432
+
+  selenium-firefox:
+    container_name: selenium-firefox
+    image: docker.io/selenium/standalone-firefox
+    privileged: true
+    network_mode: host
diff --git a/functional_tests.py b/functional_tests.py
index 50e22fb..5ba3a99 100644
--- a/functional_tests.py
+++ b/functional_tests.py
@@ -18,31 +18,31 @@
 #  under the License.
 
 from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
 import unittest
 
 
-class HomePageViewTest(unittest.TestCase):
+class SeleniumTestCase(unittest.TestCase):
     def setUp(self):
-        self.browser = webdriver.Firefox()
+        server = "http://127.0.0.1:4444/wd/hub";
+        self.browser = webdriver.Remote(
+            command_executor=server,
+            desired_capabilities=DesiredCapabilities.FIREFOX
+        )
         self.browser.implicitly_wait(3)
 
     def tearDown(self):
         self.browser.quit()
 
+
+class HomePageViewTest(SeleniumTestCase):
     def test_user_can_see_homepage(self):
         self.browser.get('http://localhost:8000')
 
         self.assertIn('Bloodhound', self.browser.title)
 
 
-class ApiHomePageViewTest(unittest.TestCase):
-    def setUp(self):
-        self.browser = webdriver.Firefox()
-        self.browser.implicitly_wait(3)
-
-    def tearDown(self):
-        self.browser.quit()
-
+class ApiHomePageViewTest(SeleniumTestCase):
     def test_user_can_see_api_homepage(self):
         self.browser.get('http://localhost:8000/api')
 

Reply via email to