Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find an <acronym> tag with watir-webdriver without taking a huge performance hit?

I am using watir-webdriver (0.5.3) in a Cucumber (1.1.9) test. I am attempting to verify the text value of an <acronym> tag. The code is legacy, and there are plans to change it to a <div> or <span> tag, but in the mean time I have to deal with it. I first attempted:

@browser.acronym(:id => /expense_code(.*)/).text

I received the following error:

NoMethodError: undefined method `acronym' for #<Watir::Browser:0x33e9940>

I poked around in the Watir code to see how tag objects were being created, and found that they seem to be dynamically created based on the HTML5 spec, but then I also found a comment in element.rb stating that they are no longer being created from the spec. At any rate, I couldn't see an easy way to inherit a <span> object and call it an <acronym> object. So, I looked into alternatives, and found the element object.

@browser.element(:id => /expense_code(.*)/).text

This code works, but it takes about a minute to traverse my page. I'm stuck with the regex for now, as the tag id is actually dynamically generated and I don't currently have a way to figure out those values. This is what the tag actually looks like:

<acronym class="editable select fillwith:exp_codes default:E100"
title="Expense Code: Expenses" id="expense_code114_582_10777">
E100    </acronym>

I would appreciate any thoughts on how I can improve the performance of my test.

like image 556
Doug Noel Avatar asked Dec 21 '22 23:12

Doug Noel


1 Answers

Is that class name predictable? could you construct that from a set part plus the text you are about to validate (it's the same in your example above) and go that way?

acronym = 'E100'
browser.element(:class, 'editable select fillwith:exp_codes default:#{acronym}'.text.should == acronym
like image 111
Chuck van der Linden Avatar answered May 01 '23 06:05

Chuck van der Linden