JQuery Events/live + ScrewUnit = :-(. ScrewUnit swaps the DOM “out from under” the elements that Events/live is watching, which messes with ScrewUnit. Call
dieon the DOM elements that live events are watching.ScrewUnit + CI + IE = :’-( Also, When ScrewUnit suites become large, they trigger IE’s “slow script” warning, which can freeze your continuous integration build. Check out the Registry Hack to set your own timeout.
We have a fan of Thor in the house: “Map options to a class. Simply create a class with the appropriate annotations, and have options automatically map to functions and parameters.” Which, as is (not) obvious, indicates that Thor is a replacement for rake.
Standup 06/23/2009: Multi-table Inheritance?
Ask for Help
“Has anyone implemented mutli-table (class table) inheritance in Rails, as apposed to single table inheritance (STI)?”
- There are some plugins that nobody has tried, such as inherits_from
- What about a view to represent the super set of tables and rows?
“We’re looking for a dead-simple, drop-in JS rating or ‘starting’ plugin.”
Check out the start-rating jQuery plugin. Any other suggestions?
Standup 3/27/2009: Gem repo forked?
Interesting Things
- IE doesn’t allow you to change the type of an input. If you create an input with createElement, IE will not allow you to change that element to a button. This was discovered when a project’s javascript dom builder code was modified to generate inputs of type=button rather than type=submit. The cross-browser solution was to create some other temporary dom element such as a div and then set the innerHtml of that element to a type=button input, then extract that child element and return it in the builder call. Yeah!
Ask for Help
“What’s the best way to get gems for forked repos?”
There was quite a discussion on this. The specific issue is that the team is trying to use Compass (Chris Eppstein gave a talk on Compass at Pivotal on 3/18-look for the future video on our Talks Page.) For the moment, since compass depends on the edge version of sass you must first manually install sass before installing the compass gem.
- One suggestion was to submit a fix for the gem. This is not a good solution in this case since the new version of sass/haml is expected to be released soon, fixing compass and simplifying its installation.
- Pivotal will likely host its own internal gem server at some point to deal with issues like this.
- The Has My Gem Built Yet? service might be useful in some situations, but not for this specific problem.
Standup 3/25/2009: Branches + JSUnit + CI + IE = :-(
Interesting Things
- Branches + JsUnit + CI + IE = :-( : Apparently it is difficult to manage IE’s cache in CI. One project apparently has a bat file on CI that clears the cache every 30 minutes. Another team solved this by making the cache directory read only. Often browser/OS combinations have some technique for disabling caching.
- Test Swarm Alpha: this is a crowd sourced javascript testing solution (think seti@home for javascript testing) being developed by John Resig.
Ask for Help
“AR attribute appears to be skipped by text field helper?!” Apparently the model method is bypassed by the text field helper if a column of the same name is present in the underlying table. This was experienced in Rails 2.2.
Others have apparently experienced this in the past but a clear answer did not surface.
Standup 3/24/2009: Browser History with Javascript and Page Based Json
Interesting Things
- Browser History with Javascript and Page Based Json: One of our projects solved the vexing problem of browser history for a page that has initial page provided json with subsequent ajax updates. A simple page back operation will display the originally downloaded data, not the updated data. The solution is to add a unique id for each page, and store these ids in a cookie. When an ajax request updates the page it removes its page id from the cookie. When you use the back button, each page checks to see if its unique id is in the cookie, and if it is not, it forces a reload.
Really Simple History was mentioned as another way to manage javascript/ajax history. - Rubymine Build 784 has the Weirdest. Bug. Ever.: This may only be a problem if you work on a mac and you need to enter capital letters in rubymine dialogs like find and replace ;-). Many of us are fans of intellij/rubymine, but we wish they had a better test process. To be fair, rubymine is in public preview, so expect the occasional bug or two.
Run JavaScript in Selenium tests. Easily.
Here’s the gist of this post: gist.github.com/58876
Ever since I’ve started using Webrat, a lot of the pain of Selenium has gone away
for me. There’s still a little bit of pain though. Part of it is caused by the fact
that it’s harder than it should be to just execute arbitrary bits of JavaScript in
in your current window under test. Well no more. Here’s a helper:
module SeleniumHelpers
# Execute JavaScript in the context of your Selenium window
def run_javascript(javascript)
driver.get_eval <<-JS
(function() {
with(this) {
#{javascript}
}
}).call(selenium.browserbot.getCurrentWindow());
JS
end
private
# If running in regular Selenium context, get_eval is defined on self.
def driver
respond_to?(:selenium) ? send(:selenium) : self
end
end
To use it with Cucumber, do like so:
World do |world|
world.extend(SeleniumHelpers)
world
end
To use it with POS, do like so:
class JavaScriptHelperTest < SeleniumTestCase
include SeleniumHelpers
# your tests go here...
end
Now what?
Now to run JavaScript in your Selenium window, just call run_javascript. Note
that it’s always going to return a String, so you may have to massage the output
a tad:
checked_boxes_count = run_javascript <<-JS
jQuery('input[type=checkbox]:checked').size();
JS
checked_boxes_count # => "3"
checked_boxes_count.to_i # => 3
Cooler stuff
While Webrat’s DSL for traversing web apps is awesome, I’ve always found the
alternatives (Polonium for example) to not jive well with how I think. They’re
way better than talking directly to Selenium, you’re still locked in to a certain
style. The run_javascript helper makes it easier to write your own helpers that
fit your own style.
module ElementHelpers
class Element
def initialize(context, selector)
@context, @selector = context, selector
end
def hide!
call(:hide)
end
def show!
call(:show)
end
def visible?
call(:is, ':visible') == 'true'
end
private
def call(fn, *args)
@context.run_javascript <<-JS
return jQuery(#{@selector.inspect})[#{fn.to_s.inspect}](#{args.map(&:inspect).join(', ')});
JS
end
end
def locate(selector)
Element.new(self, selector)
end
end
Now you can write your tests like so:
class JavaScriptHelperTest < ActiveSupport::TestCase
include SeleniumHelpers
include ElementHelpers
def setup
@element = locate('#all')
end
def test_visible_by_default
assert @element.visible?
end
def test_hide_element
@element.hide!
assert ! @element.visible?
end
def test_show_element
@element.hide! # setup
@element.show!
assert @element.visible?
end
end
Credit should go to Brian Takita, since he did most of the hard work and I just wrote a method. Let me
know if you have any issues or ideas with the helper, and may all your tests be green.
Standup 11/12/2008: JSON2.js borked?
Interesting Things
JSON version 2 has problems with its JavaScript implementation json2.js, specifically when calling
JSON.stringify()on arrays:// JSON version 1 [1] => "[1]" // JSON version 2 [1] => ""[1]""We’re not sure if this is a bug or a feature. We’re sticking with JSON version 1 until further notice.
Pivot Adam has a very interesting blog post about functors called Give up the func. Check it out!
Ask for Help
“We were having problems when mocking an ActiveRecord association under Mocha when we called
expectson a method that calls a method.”
The solution was basically to not mock associations.
“Mod_rewrite + SSL was causing problems when redirecting to a subdomain behind SSL.”
A wild-card SSL certificate solves the problem.
Effective Markdown Editing with the WMD editor and the Save Text Area Firefox plugin
Anytime I need to edit Markdown, I reach for the WMD editor. Their splitscreen demo is the most effective way to edit Markdown that I have seen.
The left screen is the editor and the right screen is the “real-time” preview of the Markdown. It is nice because I don’t have to press a preview button to see rendered Markdown. The Markdown is also rendered as I type so I get instantaneous feedback of my changes.
There is also a Save Text Area Firefox addon, which enables me to save/load the contents of a text area to/from a file on the filesystem. Also the Ctrl+s shortcut saves the file.
So when editing Markdown, I:
- Open Firefox and go to http://wmd-editor.com/examples/splitscreen?blank=1
- Load or Save a markdown file by right-clicking the editor screen
- Going to the Text submenu
- Clicking Load or Save As
- Edit the file and see the generated output
Of course, its not a text editor replacement, since the possible text manipulation in Firefox is limited, but the feedback that is provided by WMD is very effective to rapid Markdown editing. I hope this sort of UI becomes more common.
Now if only there were a similar Textile editor…
Standup 08/04/2008
Ask for Help
“Does anyone know why a Selenium click event might not trigger the same activity as directly triggering the DOM id through javascript? We have a form submit button that works fine when directly activated but doesn’t work in Selenium.”
It was suggested that perhaps this is a timing issue. Maybe some required JS for the form hasn’t loaded before Selenium is trying the event.
One workaround would be to test only the form submission called by on-click instead of the click itself.