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.
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
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.)
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.
Related
We are working right now with Ruby, Cucumber and Selenium to perform our integration tests.
Right now we want to improve the quality of our tests and therefore we want to use Capybara.
Now since all our methods need to be rewritten for that, we thought maybe someone has already done that and wrote a wrapper for the selenium webdriver, where Capybara does the job.
For example:
The wrapper should replace the following:
driver.navigate_to "/home"
to something like
visit "/home"
The point is, we donĀ“t want to rewrite all our code, since the functionality out of my view is quite of the same and it should not be that difficult to write a wrapper for driver, which does this automatically. Means: the navigate_to method just calls a visit method, and I am happy.
Do I have to write this on my own, or was this already done?
Thanks alot!
No, there is no existing wrapper for that.
You seem to be missing the fact that Capybara is itself a wrapper around selenium-webdriver, so you are asking for a selenium compatible wrapper around a wrapper around selenium. This coupled with the fact that if all you do is emulate your existing selenium commands with Capybara commands you won't be gaining anything from Capybara, so it's pointless. It sounds like your team would be better off leaving the existing tests as they are, writing all new tests using Capybara, and as existing tests need change/maintenance rewriting them to use Capybara with it's built-in waiting/retrying and friendlier API.
Does an (experimental) class browser exist for Ruby?
I am talking about a class browser/editor combination similar to that of most Smalltalk implementations (i.e. focused on [runtime] classes/objects instead of .rb files)
P.S.: it looks like pry is already able to do a lot of the things that would be needed by a smalltalk style class browser? https://speakerdeck.com/u/rahult/p/pry-an-irb-alternative-on-steroids
P.S.2: Looks like the Seaside Smalltalk framework has a web browser based class browser
P.S.3: MagLev/Webtools is the closest I have found yet:
P.S.4: Apparently http://tibleiz.net/code-browser/index.html has Ruby support and is able to present a Smalltalk like class browser:
Check out the maglev/webtools project on github, as well as the rubymirrors gem. It already provides a class browser and workspace for multiple Ruby implementations, and a graphical debugger works on MagLev as well (not so much on MRI).
If you want to build one, the easiest would be to use MOOSE and build the browser with Glamour, on top of a Ruby parser written in PetitParser. Then you could use Pharo as your Ruby IDE.
You can have a look at the Maglev Database Explorer [1, 2] as well.
[1] Video: http://www.youtube.com/watch?v=27mS1BNP7wQ
[2] Gem: https://github.com/matthias-springer/maglev-database-explorer-gem
There is. It is called Reflexive. https://github.com/dolzenko/reflexive
(I've never taken the time to try it though, so I am curious about other experiences with it.)
I have no experience with it (and it is old), but may be rbbr still works.
I would like to ask if anybody knows an easy way to test Telerik controls with Watin.
We are about to start using it but before we do I wanted to see if there is anything I would need to know.
The problem that I can see we will be having is that if even smallest thing changes then all our tests will also break.
Any suggestion is greatly appreciated.
The problem that I can see we will be having is that if even smallest thing changes then all our tests will also break.
This could/will be true of all portions of your pages, including Telerik controls, depending on your test structure. Ideally, your elements will have IDs assigned and you'll use Page classes and custom control objects to remove all HTML references from your actual test code. Then if something changes on the webpage (or in a control), you verify the change is expected, then you change the WatiN page code (or control code) and re-run your tests.
The WatiN page class primer is here: http://watinandmore.blogspot.com/2009/06/introducing-page-class.html
Basically, you want to have your test code look like myPage.PickDate("3/29/2012") and not like ie.Tables[3].TableRows[2].TableCells[4].Textbox(Find.ByClass("datePicker")).TypeText("3/29/2012")
Changes can, do and should result in failing tests, however, I can attest that with a good page (or control) class setup that abstract away the HTML DOM and other specifics leaving non-HTML-filled test code, means that when changes do happen they are most often easy to get working again.
Note: Selenium also has a Page class concept, but I have not used it very much as of right now. Bottom line: If you write a lot of tests that reference the HTML DOM directly in test code, you're setting yourself up for a maintenance headache regardless of if you go with WatiN or Selenium or whatever.
Added: As to your original question: Can you work with Telerik controls in WatiN? Yes you can most likely, but depending on the control you may need to get a bit creative, possibly even calling javascript methods from within your test (page object ;) ). I've been stumped by a couple controls (non-Telerik) but most I've eventually figured out.
I realize you asked about WatiN, and I know I'll probably get downvoted into oblivion, but I might recommend Selenium instead. It seems to be more widely used and when we were evaluating the two we found Selenium easier to work with because of the Firefox plugin to record/generate the tests. This meant that our non-technical folks could set up the tests.
Since then we've successfully used Selenium to test ASP.NET sites that utilize Telerik controls. I only ran into one issue, with the RadNumericTextBoxes, which I've documented a fix for here: http://www.msigman.com/2012/02/entering-radnumerictextbox-selenium-webdriver-1-6-0/.
I'm currently in the process of writing a how-to guide for doing it: http://www.msigman.com/2012/03/automated-testing-asp-net-web-application/ (shameless plug).
You should also consider evaluating Telerik's Test Studio, our functional automation test tool. (Disclosure: I'm their evangelist for Test Studio.)
Test Studio really shines when you're working with Telerik controls. You'll get some great additional functionality around being able to dive deeper in to verifications and actions around the controls.
Even more importantly, Test Studio handles centralizing locators and pages by default, so you don't need any additional effort to best manage your UI changes.
If possible does anyone have a template for setting up selenium tests using a pageObject design pattern.
What i would like to do is create a parent class which opens the browser. I can then pass that browser variable to another subclasses for pages such as LoginPage etc etc.
If anyone could be further information on this that would be great.
My main problem is getting the subclasses to inherit the browser variable.
I would really appreciate some help with this, any answer welcome to help point me in the right direction.
Cheers,
Jon
There is a page objects Gem. it works with both watir-webdriver and selenium-webdriver.
We had a 4 hour class on using that gem, watir-webdriver and cucumber at the recent test automation bazaar conference. you can find it here
Give it a shot, you can use it with either.. (and you may find you prefer the watir api to what selenium uses (I know I do) and if you like selenium, well that's an option too since the gem supports both
I am primarily a fluent .NET developer (as can be seen from the amount of posts and threads I make about .NET), but I thought it would be good to learn RoR.
In doing so, I have a few questions about the architecture of the language (Ruby) and the framework (RoR):
1) In .NET, every object is derived from System but inherits System.Object. So when I type System., I get a list of namespaces and then in those namespaces, classes and more namespaces.
Does Ruby not have this sort of hierarchy?
2) In some cases, I don't get the intellisense. For example, I wrote the class as outlined here (http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer) but in the line recipients user.email, nothing comes up when I type "user.".
Any idea why?
Thank
Dave Thomas (Pragmatic Programmers) has an excellent screencast series on the Ruby object model/metaprogramming. We watched this in a local Ruby user's group. The series isn't free, but it's not expensive either. You might want to check out the free preview to see if you think it is worth your time.
And to give you an answer. Yes, everything in Ruby derives from Object. You can find the docs on this at http://corelib.rubyonrails.org/. Look for the Object class.
I'm not sure why you aren't getting intellisense, partly because you haven't specified your IDE. It's possible that you can't because you've added the method dynamically and no intellisense is available.
If we compare .NET to Rails then yes, there is this kind of hierarchy there. And in general, you can achieve this kind of hierarchy in any Ruby application via using modules.
I guess it's because of Ruby's dynamic nature.
Ruby is a pure OO language meaning that everything from classes to objects derive from the Object class.
Download NetBeans. There is full intellisense support for Ruby and Ruby on Rails.
http://www.netbeans.org/features/ruby/index.html
Intellisense support probably won't get you what you think it will get you. Because Ruby is a dynamic language, Intellisense, or code completion, is difficult. What you will find is that either the drop down is so flooded with possible completions as to be useless. Or in your case nothing at all.
It's not 100% useless, but I have never found it terribly valuable.