Daniel Hollinrake
Daniel Hollinrake

Reputation: 1778

WATIR and Cucumber appears not to call the onclick event of the OBJECT tag

My colleague and I are new to Watir and Cucumber. He had written a few little ruby scripts using Watir and I'm now trying to 'translate' them into Cucumber.

In one of his tests, which works, he does the following:

b = Watir::Browser.new :ie
b.object(:id, 'TabContainer').click  

I've found that using object doesn't work for me using Cucumber so I've done the following:

@ie = Watir::IE.new
@ie.element(:id, 'TabContainer').click

The OBJECT in question is:

<object height="120" width="50" type="application/x-shockwave-flash" id="TabContainer"
   name="TabContainer" data="/en-gb/swf/helpbounce.swf" style="visibility: visible;">
   <param name="allowScriptAccess" value="always">
   <param name="wmode" value="transparent">
</object>

However, the click event doesn't work for me. Now, I know it isn't there as an attribute but it is present in helpbounce.swf and the WATIR only version works fine. Any advice or hints are gratefully welcomed.

Upvotes: 1

Views: 512

Answers (2)

Chuck van der Linden
Chuck van der Linden

Reputation: 6660

This isn't an answer (since I think Justin has nailed the issue here) but more of a really strong recommendation.

1) If you have not already done so, immediately buy and read 'The Cucumber Book' from pragmatic programmers. It will keep you on the right path with Cucumber (although myself I'd not use Capybara, which the authors like, but that's an individual choice)

2) as soon as possible, learn about Page Objects, it will make your code cleaner and far easier to maintain. We had a great 4 hour session at the Test Automation Bazaar on page objects, cucumber, and watir. You can find it here it would be worth every minute of your time that it takes to watch it and 'follow along' with all the exercises etc.

Upvotes: 2

Justin Ko
Justin Ko

Reputation: 46846

The use of Cucumber should not impact whether or not Watir does or does not work.

My guess is that your env.rb is using require 'watir' when it should be using require 'watir-webdriver'.

Reason for this guess is that based on one of your previous questions, it looks like you have Watir and Watir-Webdriver installed. At that time your env.rb was using Watir (not Watir-Webdriver).

However, given the code samples you've given, your colleague's tests are using Watir-Webdriver (as seen by the use of b = Watir::Browser.new :ie) where as you are trying to use Watir in your Cucumber tests (as seen by the use of @ie = Watir::IE.new).

So I think the solution to your problem is to switch your Cucumber tests to use Watir-Webdriver.

Upvotes: 1

Related Questions