Run Selenium test suites from within Zope2
Zelenium: Selenium Tests on Zope2
This product allows developers to create TTW Selenium test suites inside their Zope instance, in order to do browser-based functional testing of their site.
Installing the Product
If you’re using buildout, add Products.Zelenium to the eggs = parameter of the instance part.
If using the virtualenv approach to developing Zope2 software, add Products.Zelenium to the install_requires parameter in the setup.py of your package or just run bin/easy_install Products.Zelenium after installing Zope2.
Finally, if you’re using the traditional INSTANCE_HOME installation:
Unpack the tarball in a temporary location.
Copy or move the Zelenium directory to the Products directory of your INSTANCE_HOME.
You can add a Zuite object at any location within your Zope site. It behaves as a standard ordered folder, with a couple of differences:
It’s index_html is the “TestRunner.html” view familiar from Selenium.
It derives the test suite (in the upper left corner iframe) from all OFS.Image.File objects whose names start with test. You can use the OrderedFolder support to modify the order in which the test case files are run.
Reporting Bugs against Zelenium
Please use Launchpad to report bugs you find against the product, as well as to submit patches, request features, etc.
Tests are just File instances whose names begin with test. They should have a content type of text/html, and should contain a table which defines the steps which make up the test case.
See http://selenium.thoughtworks.com/testrunner.html for documentation on the table structure and the Selenese language.
Using Additional Metatypes as Test Cases
On the “Properties” tab of your test suite, you can add / modify the list of meta_types which the suite will allow as test cases. Adding “Script (Python)”, for instance, allows you to define test cases in PythonScripts.
Nesting Test Suites
Each test suite automatically includes the test cases of any suite it contains. You can take advantage of this feature to organize your test cases in a hierarchy, running them in separate segments, or all at once.
Including Tests from the Filesystem
Test suites now have a property, filesystem_path; if set, the suite will recursively load testcases from files in / under the directory pointed to by that path.
The list of files to be included is computed via the following rules:
If the testsuite_name property contains the name of a file that exists in the directory, it is presumed to contain a list of files containing tests, one per line. The test cases will be presented in the order indicated in the file, and test cases may be included more than once.
If the testsuite_name property is empty but the directory contains a file, .objects, it is presumed to contain a list of files to be included, one per line; only those files / subdirectories (if present) will be included. In this case, the test cases will be presented in the order indicated in the file, followed by any test cases from subdirectories.
Otherwise, if the suite’s property, filename_glob is non-empty, it will be expanded (via Python’s glob.glob) to compute the list of filenames. The test cases will be presented in alphabetical order, followed by any test cases from subdirectories.
Otherwise, any file will be considered a testcase. The test cases will be presented in alphabetical order, followed by any test cases from subdirectories.
Exporting an Archive
On the “Zip” tab, supply a filename and click the “Download” button. The Zuite object will construct a zip file with the following contents:
the “TestRunner.html” framework page
the list of test case files (rendered as static HTML)
your test case files (appending .html if the IDs do not have extensions)
The archive will also contain each of the supporting .js and .css files which drive the browserbot.
Creating a Snapshot
On the “Zip” tab, supply a filename and click the “Download” button. The Zuite object will construct a zip file with the same contents described above, and then save it as a File object in its own contents.
Generating Testcases using tcpwatch
Download the tcpwatch product from Shane Hathaway’s site:
Unpack and run tcpwatch in its “HTTP proxy” mode, with recoring turned on. E.g., the following command runs the proxy on port 9999, recording the request / response data to the directory /tmp/recorded_scenario:
$ python /path/to/tcpwatch/ tcpwatch.py \ -p 9999 -r /tmp/recorded_scenario
Configure your browser to use an HTTP proxy on localhost, port 9999.
Click through your site, exercising the features you are testing.
Stop the proxy. Run the generator.py script, pointing to the directory where tcpwatch was recording:
$ python /path/to/Zelenium/generator.py \ --logfile-directory=/tmp/recorded_scenario \ --output-file=test_case_name.html
Edit the generated test case, removing / correcting the various steps.
Upload the test case to a Zelenium Zuite and run it.
Capturing Results from the Test Run
Selenium has a feature which allows the testrunner to upload result data from an automated test run to the server.
Invoke the test suite from your browser as usual, but append the query string ?auto=true, to the URL, e.g.:
Selenium will run all test cases, and then upload its result data to the postResults method of your suite. (Note that you no longer need the postResults PythonScript in the root of your site, because the latest version of Selenium posts to that name relative to the test suite).
Zelenium Product Changelog
Remove setuptools_bzr requirement, since that package was causing installs to break. Instead, add a replacement sdist command which aborts if setuptools_bzr cannot be imported.
Add setuptools_bzr as a setup requirement to avoid future brown-bag releases.
Fix rendering of results views which contain non-ASCI text. Thanks to Leo Rochael for the test and the fix. Fixes lp:575415.
Updated README to indicate Zope2 prerequisite, and point to its installation documentation.
Packaging update only, fixin brown-bag release (minus metadata files). Also, note move of bug tracker from www.zope.org to Launchpad.
Eggified, tested and removed deprecations under Zope 2.12.
Moved from svn.zope.org to Launchpad.
Updated included selenium to selenium-core 0.8.3.
Applied a fix from Rob Miller to make Zelenium Zuite objects functional in the presence of five:traverse, making index_html the explicit default view.
Corrected the documentation in the README for capturing results of a test run (auto=1 -> auto=true, in line with the Selenium documentation). Thanks to Yoshinori Okuji for pointing this out.
Fixed unit tests by wrapping filesystem objects that are rendered during ZIP file creation - code in OFS.Image wants to acquire REQUEST and use RESPONSE.
Found how to make the dependency on ExternalEditor optional (thanks to Andreas Jung for the bug report).
Stripped empty filenames out of manifest, to avoid infinite recursion.
Added the testsuite_name property that allows multiple test suites to be built up from test cases within a single filesystem directory.
Upgrade to selenium version 0.6
Suites now recurse through all “folderish” subobjects, looking for tests (allows, for instance, tests to be loaded from disk via CMF’s FileSystemDirectoryView). Thanks to Malcom Cleaton for the patch!
Define zelenium_globals in __init__.py to be able to register the selenium directory for use as a CMF skin directory.
If debug-mode is set to “on” in zope.conf, filesystem-based testcases files are reloaded every time they are used, to ease development of filesystem-based test suites. This behavior emulates what the CMF Filesystem Directory Views do with debug-mode on.
Moved repository to Subversion: svn+ssh://svn.zope.org/repos/main/Zelenium/
Upgrade to use the Selenium “core application” from Selenium 0.4.0. See http://selenium.thoughtworks.com/release-notes.html for a summary of changes.
Add ability to suppress inclusion of Selenium support files in snapshot / download.
Add support for returning testcases from a mapped directory path, including recursion through subdirectories of that path. Currently, the implementation has the following issues:
- o It only creates OFS.Image.File objects for test cases (no templates,
Add unit tests for Zuite.__getitem__ behavior, including support files.
Make passing / failing test cases in results view more obvious in printed representation by adding icons. N.B.: at the moment, we do this by sniffing the HTML of the test case for the “pink” backgrounds.
Apply patch from the selenium-devel list to fix regression in testcase HTML extraction in postTestResults.
Make the posted results folder into its own class, derived from Folder (moving the template out to a PageTemplateFile).
Further repaired recursive ZIPfile generation, including normalizing URLs in generated HTML.
Extended zuite unittests to test listTestCases and manage_createSnapshot, as well as recursive ZIPfile generation.
Updated to use the “TestRunner core” from Selenium version 0.3.0. See http://selenium.thoughtworks.com/release-notes.html for more information.
Add unit tests for Zuite class.
Make ZIPfile generation work with nested suites.
Repair breakage of ExternalEditor link in manage_main.
Compensate in display of test tables for non-padded integers in the IDs (make them sort properly).
Make Zuite instances recursively include their Zuite children’s test cases (to allow easier organization of the test cases in a hierarchy).
Allow indiviual zuites to override the list of metatypes which can be test cases, via a new testcase_metatypes property.
Force Zuite objects to show order support, even in the presence of ExternalEditor, whose monkey patching seems to trip it up. Surface the EE icon, if the product is available
Note: we are forking OFS/dtml/main.dtml and the version in ExteranalEditor/manage_main.dtml to surface order support, which is a pretty brutal hack. We should probably get ExteranalEditor fixed, instead, and rip out the forked copy.
Record server-side data during postResults: Zope version string, product names and versions.
Captured additional request parameters in postResults: user agent, HTTP host, remote address).
Added postResults handling code to capture results as a sub- folder of the suite.
Correct the emitted HTML for input widgets (close the tr tag).
Fix unpack bug in code which punts on requests to “foreign” hosts.
Punt on handling XML-RPC requests (e.g., Epoz calls back to the server to run Tidy).
Added script, generator.py, to create Selenium testcase files from the request / response logfiles created by tcpwatch.
Allowed test cases to be PageTemplates, as well as Files, to permit indirecting through properties of the test suite (e.g., for user id / password).
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.