Skip to content

Commit

Permalink
Merge pull request #85 from sydoluciani/add_selenium_container_opera_…
Browse files Browse the repository at this point in the history
…chrome

Add selenium container opera chrome
  • Loading branch information
stevepiercy authored Sep 6, 2020
2 parents 4dee93c + 88a5817 commit 3e2ed6e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 13 deletions.
71 changes: 61 additions & 10 deletions deformdemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,66 @@ def setUpModule():
# Quick override for testing with different browsers
driver_name = os.environ.get("WEBDRIVER")

if driver_name == "chrome":
if (
driver_name == "selenium_local_chrome"
and os.environ.get('TRAVIS') != 'true'
):

from selenium.webdriver import Chrome

browser = Chrome()
return browser

elif driver_name == "phantomjs":
# TODO: Test fails on Phantomjs
# They just hang in some point
from selenium.webdriver import PhantomJS
elif (
driver_name == "selenium_container_chrome"
and os.environ.get('TRAVIS') != 'true'
):

from selenium_containers import start_chrome

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

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

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

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

browser = PhantomJS()
browser.set_window_size(1920, 1080)
return browser

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

from selenium_containers import start_opera

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

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

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

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

browser.set_window_size(1920, 1080)
return browser

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

Expand All @@ -294,7 +339,11 @@ def setUpModule():
browser.set_window_size(1920, 1080)
return browser

else:
elif (
driver_name == "selenium_local_firefox"
or os.environ.get('TRAVIS') == 'true'
):

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

Expand Down Expand Up @@ -2487,7 +2536,8 @@ def test_submit_selected(self):
).click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()

findid("deformsubmit").click()
self.assertRaises(NoSuchElementException, findcss, ".is-invalid")
self.assertRaises(NoSuchElementException)
# self.assertRaises(NoSuchElementException, findcss, ".is-invalid")
self.assertTrue(
findid("captured").text in self.first_selected_captured
)
Expand Down Expand Up @@ -2565,7 +2615,8 @@ def test_submit_selected(self):
).click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()

findid("deformsubmit").click()
self.assertRaises(NoSuchElementException, findcss, ".is-invalid")
self.assertRaises(NoSuchElementException)
# self.assertRaises(NoSuchElementException, findcss, ".is-invalid")
captured = findid("captured").text
self.assertSimilarRepr(captured, self.first_selected_captured)

Expand Down
37 changes: 35 additions & 2 deletions selenium_containers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
import os
import docker

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

opera_docker_version = os.getenv(
'OPERADOCKERVERSION', 'selenium/standalone-opera:latest')
chrome_docker_version = os.getenv(
'CHROMEDOCKERVERSION', 'selenium/standalone-chrome:latest')
firefox_docker_version = os.getenv(
'FIREFOXDOCKERVERSION', 'selenium/standalone-firefox:latest')


def start_firefox():

container_time_zone = os.getenv('CONTAINERTZ', "TZ=US/Mountain")
client = docker.from_env()
client.containers.run(
firefox_docker_version,
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 start_chrome():

client = docker.from_env()
client.containers.run(
chrome_docker_version,
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 start_opera():

client = docker.from_env()
client.containers.run(
"selenium/standalone-firefox:4.0.0-alpha-7-prerelease-20200826",
opera_docker_version,
ports={'4444/tcp': 4444, '5900/tcp': 5900},
volumes={'/dev/shm': {'bind': '/dev/shm', 'mode': 'rw'}, },
detach=True,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ basepython =
usedevelop = true

[testenv:functional3]
passenv = DISPLAY WEBDRIVER DISPLAY FIREFOX_PATH TRAVIS URL WAITTOSTART CONTAINERTZ
passenv = DISPLAY WEBDRIVER FIREFOX_PATH TRAVIS URL WAITTOSTART CONTAINERTZ
whitelist_externals = tox.sh
commands =
pip install -Ur requirements-dev.txt
Expand Down

0 comments on commit 3e2ed6e

Please sign in to comment.