Skip to content

Commit

Permalink
Merge pull request #84 from sydoluciani/add_selenium_firefox_container
Browse files Browse the repository at this point in the history
Add selenium firefox container
  • Loading branch information
stevepiercy authored Sep 6, 2020
2 parents 9af08be + 6ceb42c commit 3a6bd63
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
29 changes: 29 additions & 0 deletions deformdemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,38 @@ def setUpModule():

browser = Chrome()
return browser

elif driver_name == "phantomjs":
# TODO: Test fails on Phantomjs
# They just hang in some point
from selenium.webdriver import PhantomJS

browser = PhantomJS()

elif (
driver_name == "selenium_standalone_firefox"
and os.environ.get('TRAVIS') != 'true'
):

from selenium_containers import start_firefox

from selenium.webdriver import DesiredCapabilities
from selenium.webdriver import Remote

start_firefox()
time.sleep(os.getenv('WAITTOSTART', 30))

selenium_grid_url = "http://localhost:4444/wd/hub"
capabilities = DesiredCapabilities.FIREFOX.copy()

browser = Remote(
command_executor=selenium_grid_url,
desired_capabilities=capabilities,
)

browser.set_window_size(1920, 1080)
return browser

else:
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
Expand All @@ -291,6 +317,9 @@ def setUpModule():

def tearDownModule():
browser.quit()
from selenium_containers import stop_selenium_containers

stop_selenium_containers()


def _getFile(name="test.py"):
Expand Down
26 changes: 26 additions & 0 deletions selenium_containers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import docker


def start_firefox():

container_time_zone = os.getenv('CONTAINERTZ', "TZ=US/Mountain")

client = docker.from_env()
client.containers.run(
"selenium/standalone-firefox:4.0.0-alpha-7-prerelease-20200826",
ports={'4444/tcp': 4444, '5900/tcp': 5900},
volumes={'/dev/shm': {'bind': '/dev/shm', 'mode': 'rw'}, },
detach=True,
remove=True,
auto_remove=True,
environment=[container_time_zone])


def stop_selenium_containers():
client = docker.from_env()
image_name = "selenium/standalone"

for container in client.containers.list():
if image_name in str(container.image.tags):
container.stop()
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ envlist =
py37,
py38,
pypy3,
py39
py39,
functional3

[testenv]
# Most of these are defaults but if you specify any you can't fall back
Expand All @@ -21,11 +22,15 @@ basepython =
py3: python3.8

usedevelop = true
passenv = DISPLAY

[testenv:functional3]
passenv = DISPLAY WEBDRIVER DISPLAY FIREFOX_PATH TRAVIS URL WAITTOSTART CONTAINERTZ
whitelist_externals = tox.sh
commands =
pip install -Ur requirements-dev.txt
./tox.sh --with-flaky --max-runs=4 {posargs}
deps =
docker

[testenv:lint]
basepython = python3.8
Expand Down

0 comments on commit 3a6bd63

Please sign in to comment.