Travis-CI is a free hosted continuous integration platform for the open source community. It has a good integration with Github, so each push to a project runs the tests of the project.
gocept.selenium is a python package our company has developed as a test-friendly Python API for Selenium which allows to run tests in a browser.
Travis-CI uses YML-Files to configure the test run. I found only little documentation how to run Selenium tests on Travis-CI. But it is straight forward. The following YML file I took from a personal project of mine. (I simplified it a bit for this blog post.):
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar"
- "java -jar selenium-server-standalone-2.31.0.jar &"
- "export GOCEPT_SELENIUM_BROWSER='*firefox'"
- python bootstrap.py
- Lines 1 – 4: My project is a Python project which currently only runs on Python 2.6. But other Python versions will work as well.
- Lines 5, 6: Firefox needs a running XServer, so we start it first as it takes some seconds to launch. See Travis-CI documentation, too.
- Lines 7, 8: The Selenium server seems not to be installed by default, so get it and launch it.
- Line 9: Tell gocept.selenium to use Firefox to run the tests. (Note: To use the new Webdriver-API in the upcoming version 2 of gocept.selenium you have to set other environment variables.)
- Lines 10 – 14: Install the project and run the tests as usual. (The example uses zc.buildout to do this.)
Note: Although I use the Firefox which is installed by default on the Travis-CI machine, I did not yet find out which version it is.
In a new Pyramid project we used deform to render forms. We did not really like it. (The reasons might be detailed in another post.)
To see if other form libraries do better I gave yafowil a try at our gocept Developer Punsch 3: yafowil comes with written documentation. To get a form in our Pyramid application I had to find out some things which are not so clearly documented:
- Let the project depend on yafowil.webob via setup.py as it contains the necessary WebOb integration.
- Import the
loader from yafowil like below, to allow yafowil to register all its known components (even all the packages in the yafowil.wiget namespace). Otherwise I got strange errors. (The loader symbol is not needed at all in the rest of the code of the form.)
from yafowil import loader
- To get a value displayed in the rendered form use
value keyword parameter in the factory like this:
form['name'] = factory('field:label:text',
value can be a plain value or a function which gets the widget and the runtime data of the widget as parameters.
yafowil.base.Factory.resources_for could be a starting point. (I did not do this yet, so it might be wrong.)
Conclusion: yafowil looks like an interesting framework and after getting a starting point it should be useable in Pyramid, too. Maybe this post can help to ease it a bit.
zope.formlib has the ability to customize the used widget like this:
form_fields = zope.formlib.form.Fields(IKeywords)
form_fields['keywords'].custom_widget = KWSelectWidgetFactory
I do not like this approach for two reasons:
- the widget has to be set manually every time the specific field is used
- there is no easy way to get a display widget if the form or field is not editable for the user
Defining a new schema field and registering the widget for this field seems a bit heavy, so I came up with providing a marker interface on the field:
"""Marker interface to get a special keywords widget."""
keywords = zope.schema.List(
title = _("Edit Keywords"),
value_type = zope.schema.Choice(
I registered the edit widget and display widget for the
IHaveSelectableKeywords interface, so the custom widget does not have to be set in the form like this (edit widget):