4

We are currently running rspec tests that check for specific libraries/models to be loaded. Specifically, we want to test that when creating an object, we get the correct Watir object back: Watir::Browser for FF and Chrome, and Watir::Safari for Safari.

We already tried doing this: Unload a ruby class but it just deletes the constant, which isn't what we want.

Normally, this wouldn't be a problem but due to compatibility problems with safariwatir and watir-webdriver, this is not the case. It errors out with:

superclass mismatch for class UnknownObjectException

And to 'fix' this, we basically have to choose which webdriver to load(hence the original logic - which we plan to test)

Is there a way to solve this? Our tests pass, not just when ran as a whole. So we basically have to skip a step just to circumvent the require problem.

Community
  • 1
  • 1
corroded
  • 21,406
  • 19
  • 83
  • 132

3 Answers3

2

New Anser: NEWS FLASH webdriver now supports Safari! ditch safariwatir and do it all with webdriver. I just found this out today at the Test Automation Bazaar, so don't have much in the way of details.. I'd expect to see some blog postings about this from the Watir community in the next week or so once people recover from the conference.

UPDATE: Details now up on the watir-webdriver blog regarding how to make things work with Safari

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
  • wow that's great news! all we have to do is wait for the update? We're running on watir-webdriver 0.5.3 right now. – corroded Mar 25 '12 at 05:19
  • potentially you could try updating the webdriver gem and see if that lets you start up a browser of type :safari. (you are making me wish I'd spent more time at the TAB event talking with JariB about this to get a handle on how it works.) – Chuck van der Linden Mar 27 '12 at 16:23
  • actually i tried that but no luck. are you talking about watir or selenium webdriver? – corroded Mar 28 '12 at 14:13
  • well you for sure would need to update the webdriver stuff to get the new safari support. not sure if watir-webdriver would also need to be updated, but it would be a pretty good idea to update both I'd think. The watir level stuff just provides you with a nice API, all the driving of the browsers is up to webdriver. Effectively webdriver is now the lower level 'engine' that drives both selenium2 and Watir-webdriver (the old Watir, (soon to be renamed watir-classic I think) only drives IE, and does that via Win32ole stuff.) – Chuck van der Linden Mar 28 '12 at 20:32
  • yeah i think im running both updated versions: 2.20.0 for selenium-webdriver and 0.5.4 for watir, i tried doing Watir::Browser.new :safari and it just throws an error – corroded Mar 29 '12 at 03:52
  • Safari support is not in the watir-webdriver gem yet. I hope I will have some time to document how to get it installed next week. – Željko Filipin Mar 29 '12 at 04:38
  • @corroded, See http://watirwebdriver.com/safari/ for details of how to get Safari working with webdriver and watir-webdriver – Chuck van der Linden Apr 18 '12 at 19:10
0

Classes in Ruby are objects, but the idea of classes as a 'one per execution/objectspace" only exists because Ruby class objects are assigned as constants.

Since your classes are namespaced with theater module, you can check the type of an object dynamically. If that isn't enough, you can duck-type. Since you mentioned compatibility issues, there are methods that exist for one that do not for another (which you can test for) or there are methods that return different values for each (which you can test for.)

Chris
  • 11,819
  • 19
  • 91
  • 145
0

I've handled something similar to this by using conditional logic when I require the 'watir' gem, so that only one version ends up being required based on what the environment is configured for. I can provide more details later, perhaps after the watir test automation bazaar is over and I have a little time to think and dig out some code samples for you.

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
  • thanks! this is still bugging us. We DO have conditional requires going on but we are trying to TEST those conditions. IN which case, when rspec goes through the test cases, say first it checks if watir-webdriver was loaded, then by the time it tries to test if safariwatir was required, watir-webdriver is still loaded so it throws the error – corroded Mar 23 '12 at 05:52
  • I'm a bit confused, are you testing your test code with rspec? This might be one aspect you would need to omit from those tests, perhaps confirm it's working via some kind of logging or some debugging puts statements "I'm loading Safari" etc. – Chuck van der Linden Mar 27 '12 at 16:27