diff options
author | brian avery <avery.brian@gmail.com> | 2016-11-30 19:35:27 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-12-07 10:42:22 +0000 |
commit | da22be9904da257a168d72c2b00a6b839b0ed434 (patch) | |
tree | 0e6a0b8b1d8159e0a9720e575652e0ebcc14768b /bitbake/lib/toaster/tests/browser | |
parent | e74831eba7ddd910de33fbdb8f9fa1bd93fe893c (diff) | |
download | poky-da22be9904da257a168d72c2b00a6b839b0ed434.tar.gz |
bitbake: toaster: browser tests - add Selenium Docker container as driver
Adds the ability to specify a Selenium Docker container server as
a driver. This allows for repeatable tests independent of host.
Currently we assume you are using the Firefox container. Instructions
are located in the README in tests/browser.
(Bitbake rev: 7df842f8f8b2ae640109ed06729ab59c9469fc64)
Signed-off-by: brian avery <brian.avery@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/tests/browser')
-rw-r--r-- | bitbake/lib/toaster/tests/browser/README | 21 | ||||
-rw-r--r-- | bitbake/lib/toaster/tests/browser/selenium_helpers_base.py | 13 |
2 files changed, 30 insertions, 4 deletions
diff --git a/bitbake/lib/toaster/tests/browser/README b/bitbake/lib/toaster/tests/browser/README index 6b09d20d87..e841a3f12a 100644 --- a/bitbake/lib/toaster/tests/browser/README +++ b/bitbake/lib/toaster/tests/browser/README | |||
@@ -18,7 +18,7 @@ To run tests against Chrome: | |||
18 | * On Windows, put chromedriver.exe in the same directory as chrome.exe | 18 | * On Windows, put chromedriver.exe in the same directory as chrome.exe |
19 | 19 | ||
20 | To run tests against PhantomJS (headless): | 20 | To run tests against PhantomJS (headless): |
21 | 21 | --NOTE - Selenium seems to be deprecating support for this mode --- | |
22 | * Download and install PhantomJS: | 22 | * Download and install PhantomJS: |
23 | http://phantomjs.org/download.html | 23 | http://phantomjs.org/download.html |
24 | * On *nix systems, put phantomjs on PATH | 24 | * On *nix systems, put phantomjs on PATH |
@@ -43,13 +43,30 @@ Marionette driver.) | |||
43 | The test cases will instantiate a Selenium driver set by the | 43 | The test cases will instantiate a Selenium driver set by the |
44 | TOASTER_TESTS_BROWSER environment variable, or Chrome if this is not specified. | 44 | TOASTER_TESTS_BROWSER environment variable, or Chrome if this is not specified. |
45 | 45 | ||
46 | To run tests against the Selenium Firefox Docker container: | ||
47 | More explanation is located at https://wiki.yoctoproject.org/wiki/TipsAndTricks/TestingToasterWithContainers | ||
48 | * Run the Selenium container: | ||
49 | ** docker run -it --rm=true -p 5900:5900 -p 4444:4444 --name=selenium selenium/standalone-firefox-debug:2.53.0 | ||
50 | *** 5900 is the default vnc port. If you are runing a vnc server on your machine map a different port e.g. -p 6900:5900 and connect vnc client to 127.0.0.1:6900 | ||
51 | *** 4444 is the default selenium sever port. | ||
52 | * Run the tests | ||
53 | ** TOASTER_TESTS_BROWSER=http://127.0.0.1:4444/wd/hub TOASTER_TESTS_URL=http://172.17.0.1:8000 ./bitbake/lib/toaster/manage.py test --liveserver=172.17.0.1:8000 tests.browser | ||
54 | ** TOASTER_TESTS_BROWSER=remote TOASTER_REMOTE_HUB=http://127.0.0.1:4444/wd/hub ./bitbake/lib/toaster/manage.py test --liveserver=172.17.0.1:8000 tests.browser | ||
55 | *** TOASTER_REMOTE_HUB - This is the address for the Selenium Remote Web Driver hub. Assuming you ran the contianer with -p 4444:4444 it will be http://127.0.0.1:4444/wd/hub. | ||
56 | *** --liveserver=xxx tells Django to run the test server on an interface and port reachable by both host and container. | ||
57 | **** 172.17.0.1 is the default docker bridge on linux, viewable from inside and outside the contianers. Find it with "ip -4 addr show dev docker0" | ||
58 | * connect to the vnc server to see the tests if you would like | ||
59 | ** xtightvncviewer 127.0.0.1:5900 | ||
60 | ** note, you need to wait for the test container to come up before this can connect. | ||
61 | |||
46 | Available drivers: | 62 | Available drivers: |
47 | 63 | ||
48 | * chrome (default) | 64 | * chrome (default) |
49 | * firefox | 65 | * firefox |
50 | * marionette (for newer Firefoxes) | 66 | * marionette (for newer Firefoxes) |
51 | * ie | 67 | * ie |
52 | * phantomjs | 68 | * phantomjs (deprecated) |
69 | * remote | ||
53 | 70 | ||
54 | e.g. to run the test suite with phantomjs where you have phantomjs installed | 71 | e.g. to run the test suite with phantomjs where you have phantomjs installed |
55 | in /home/me/apps/phantomjs: | 72 | in /home/me/apps/phantomjs: |
diff --git a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py index 14e9c15648..156d639b1e 100644 --- a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py +++ b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py | |||
@@ -39,7 +39,7 @@ from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |||
39 | from selenium.common.exceptions import NoSuchElementException, \ | 39 | from selenium.common.exceptions import NoSuchElementException, \ |
40 | StaleElementReferenceException, TimeoutException | 40 | StaleElementReferenceException, TimeoutException |
41 | 41 | ||
42 | def create_selenium_driver(browser='chrome'): | 42 | def create_selenium_driver(cls,browser='chrome'): |
43 | # set default browser string based on env (if available) | 43 | # set default browser string based on env (if available) |
44 | env_browser = os.environ.get('TOASTER_TESTS_BROWSER') | 44 | env_browser = os.environ.get('TOASTER_TESTS_BROWSER') |
45 | if env_browser: | 45 | if env_browser: |
@@ -59,6 +59,15 @@ def create_selenium_driver(browser='chrome'): | |||
59 | return webdriver.Ie() | 59 | return webdriver.Ie() |
60 | elif browser == 'phantomjs': | 60 | elif browser == 'phantomjs': |
61 | return webdriver.PhantomJS() | 61 | return webdriver.PhantomJS() |
62 | elif browser == 'remote': | ||
63 | # if we were to add yet another env variable like TOASTER_REMOTE_BROWSER | ||
64 | # we could let people pick firefox or chrome, left for later | ||
65 | remote_hub= os.environ.get('TOASTER_REMOTE_HUB') | ||
66 | driver = webdriver.Remote(remote_hub, | ||
67 | webdriver.DesiredCapabilities.FIREFOX.copy()) | ||
68 | |||
69 | driver.get("http://%s:%s"%(cls.server_thread.host,cls.server_thread.port)) | ||
70 | return driver | ||
62 | else: | 71 | else: |
63 | msg = 'Selenium driver for browser %s is not available' % browser | 72 | msg = 'Selenium driver for browser %s is not available' % browser |
64 | raise RuntimeError(msg) | 73 | raise RuntimeError(msg) |
@@ -135,7 +144,7 @@ class SeleniumTestCaseBase(unittest.TestCase): | |||
135 | 144 | ||
136 | # instantiate the Selenium webdriver once for all the test methods | 145 | # instantiate the Selenium webdriver once for all the test methods |
137 | # in this test case | 146 | # in this test case |
138 | cls.driver = create_selenium_driver() | 147 | cls.driver = create_selenium_driver(cls) |
139 | cls.driver.maximize_window() | 148 | cls.driver.maximize_window() |
140 | 149 | ||
141 | @classmethod | 150 | @classmethod |