Linux; Apache; Most of our cool scripting languages start with P; and PostgreSQL. Yep, LAMP ;). (ref)
Miscellaneous twill
The next release of twill is taking a bit longer than I'd planned. I think this is mainly because of the increase in the number of people using it -- they keep finding bugs, damn them! However, bug fixing is proceeding apace, and there have been one or two amusing incidents along the way. At this rate I think it's fair to say that most of the minor burrs in twill will be ironed out by the time that the beta, 0.9, arrives. I've come to the realization that a "1.0" release should be predicated on as much actual
use of the software as possible -- that way you really do get not only a well-tested piece of software, but one that genuinely meets a variety of needs.
On that front, Grig pointed me towards a challenge on the agile-testing list. Brian Mairick presented a Watir solution, and it seemed incumbent upon me to immediately drop all other work and whip out an example using twill. A solution in twill form is here:
extend_with table_picker go http://issola.caltech.edu/~t/transfer/jjj.htmlshowforms check_cells "name1" 0 showforms
Of course, this merely punts the solution into the 'table_picker' extension module, which follows at the bottom.
A few quick notes about this solution:
- You'll need the latest version of twill, 0.8.4a11, either in egg
version from my alpha
dist directory or from the .tar.gz resting home.
- With that, Python, and setuptools, you're set; no other software is needed.
- Both the Watir solution and the twill solution rely on using the
Real Programming Language (be it Ruby or Python) to do the logic
processing necessary to find the right cell(s).
- My solution could be shorter, but it works fine as-is ;).
- The real advantage to twill in this particular situation is that it's completely and trivially automatable. Of course, it also doesn't handle JavaScript...
--titus
table_picker.py:
import re from BeautifulSoup import BeautifulSoupdef check_cells(label_regexp, label_column): """ >> check_cells <label_regexp> <label_column>
Check all checkboxes in rows where column #'label_column' matches 'label_regexp'. """ # deal with input parameters label_regexp = re.compile(label_regexp) label_column = int(label_column)
# first, get the browser obj from twill import get_browser, commands b = get_browser()
# grab the HTML from the current page html = b.get_html()
# parse the HTML. soup = BeautifulSoup() soup.feed(html)
# grab the table table = soup.first('table')
# grab the rows & iterate rows = table('tr')
names = [] for i, row in enumerate(rows): cols = row('td') # get the label column col = cols[label_column]
# if it's a match, run through & record all checkboxes if label_regexp.search(str(col)): for col in cols: for element in col('input'): if element.get('type') == 'checkbox': names.append(element['name'])
for name in names: name = str(name) commands.formvalue('1', name, '1')
