[1/1] toaster: browser tests - add Selenium Docker container as driver

Submitted by brian avery on Nov. 5, 2016, 10:47 p.m. | Patch ID: 133614

Details

Message ID 23b320c2b83b5edb108cc0f59cf13c5628b3f826.1478385813.git.brian.avery@intel.com
State Superseded
Headers show

Commit Message

brian avery Nov. 5, 2016, 10:47 p.m.
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 Firfox container. Instructions
are located in the README in tests/browser.

Signed-off-by: brian avery <brian.avery@intel.com>
---
 lib/toaster/tests/browser/README                   | 21 +++++++++++++++++++--
 lib/toaster/tests/browser/selenium_helpers_base.py |  7 +++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/toaster/tests/browser/README b/lib/toaster/tests/browser/README
index 6b09d20..09fd7ce 100644
--- a/lib/toaster/tests/browser/README
+++ b/lib/toaster/tests/browser/README
@@ -18,7 +18,7 @@  To run tests against Chrome:
 * On Windows, put chromedriver.exe in the same directory as chrome.exe
 
 To run tests against PhantomJS (headless):
-
+--NOTE - Selenium seems to be deprecating support for this mode ---
 * Download and install PhantomJS:
   http://phantomjs.org/download.html
 * On *nix systems, put phantomjs on PATH
@@ -43,13 +43,30 @@  Marionette driver.)
 The test cases will instantiate a Selenium driver set by the
 TOASTER_TESTS_BROWSER environment variable, or Chrome if this is not specified.
 
+To run tests against the Selenium Firefox Docker container:
+More explanation is located at https://wiki.yoctoproject.org/wiki/Running_Toaster_Tests_with_Containers
+* Run the Selenium container:
+  ** docker run -it --rm=true -p 5900:5900 -p 4444:4444 --name=selenium selenium/standalone-firefox-debug:2.53.0
+  *** 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 to 127.0.0.1:6900
+  *** 4444 is the default selenium sever port.
+* Run the tests
+  ** 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
+  *** TOASTER_TESTS_URL - This is the web server the selenium instance connects to to test.
+  ***  --liveserver=xxx tells Django to run the test server on an interface and port reachable by both host and container.
+  ****  These 2 MUST match
+  **** 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"
+* connect to the vnc server to see the tests if you would like
+   ** xtightvncviewer 127.0.0.1:5900
+   ** note, you need to wait for the test container to come up before this can connect.
+
 Available drivers:
 
 * chrome (default)
 * firefox
 * marionette (for newer Firefoxes)
 * ie
-* phantomjs
+* phantomjs (deprecated)
+* container
 
 e.g. to run the test suite with phantomjs where you have phantomjs installed
 in /home/me/apps/phantomjs:
diff --git a/lib/toaster/tests/browser/selenium_helpers_base.py b/lib/toaster/tests/browser/selenium_helpers_base.py
index 14e9c15..c6cf527 100644
--- a/lib/toaster/tests/browser/selenium_helpers_base.py
+++ b/lib/toaster/tests/browser/selenium_helpers_base.py
@@ -59,6 +59,13 @@  def create_selenium_driver(browser='chrome'):
         return webdriver.Ie()
     elif browser == 'phantomjs':
         return webdriver.PhantomJS()
+    elif ":" in browser:
+        driver = webdriver.Remote(browser,
+                                  webdriver.DesiredCapabilities.FIREFOX.copy())
+        env_link_url = os.environ.get('TOASTER_TESTS_URL')
+
+        driver.get(env_link_url)
+        return driver
     else:
         msg = 'Selenium driver for browser %s is not available' % browser
         raise RuntimeError(msg)

Comments

brian avery Nov. 9, 2016, 4:45 p.m.
This is a system generated Comment: Patch 133614 was automatically marked as superseded by patch 133727.