Difference between these two gems "site_prism" and "page_object" - ruby

I have come across two projects one is with WATIR cucumber feature files and step definitions and another one is Rspec, capybara`` withoutstep definitionsandfeature files`.
In WATIR project page_object was used and in capybara site_prism gem was used.
What is the difference between two?
Can't we use page_object in capybara would that be incorrect approach? Why?

The main difference between the two is supported underlying drivers, which is the part that actually interacts with the browser.
SitePrism supports Capybara.
Page-Object supports Watir-Webdriver and Selenium-Webdriver.
As each gem makes assumptions about the API of the driver, you cannot use unsupported drivers - ie you cannot use the Page-Object gem with Capybara.
Aside from that, it is mainly API preferences. Both gems are for creating page object models. However, the syntax for defining the page object and the methods the page object has will differ based on the preferences of each gem's author.

Related

Ruby Selenium PageObjects Template

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

How to unload 'require' in ruby/rspec?

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.

Salesforce Gem for Rails 3.1

I have this rails Application which uses salesforce App. I want to know if there are any gem and tutorials to build Salesforce App in rails easily. I found this rforcedotcom gem but it lacks tutorial for Rails 3.
The current standard gem is the databasedotcom gem, which is updated fairly actively and officially endorsed by Salesforce.
There is also the asf-rest-adapter gem (which has a dependency on asf-soap-adapter) by Ray Gao which I have running in a number of apps, and works quite well.
There's yet another gem out now called Restforce.
The author bills it as "lighter weight" with "greater flexibility and more advanced functionality" than the databasedotcom gem (and he should know -- he worked on the that gem too).
Another alternative is to use Active Force that uses RestForce as a backend and provides an ActiveRecord like interface. It also have some generators to get up and running faster.

How can I help TextMate recognize which bundle to load?

I have a problem with four bundles I'm using, specifically Ruby, Ruby on Rails, RSpec and Sinatra.
Most of the time TextMate manages to get the bundle type right, but for these, I find myself constantly switching form Sinatra to Ruby on Rails, as some model files get recognized as Sinatra.
It also happens a lot with RSpec, where the Sinatra bundle sometimes takes precedence.
Is there any way to manage the way in which bundles are recognized? It would be great if I could somehow hint TextMate what bundles to completely ignore in a specific project, or based on a directory structure.
I think you can modify your Sinatra bundle to trigger as soon as it detects require 'sinatra'

What's the best practices in code reuse between different Ruby projects?

guys!
I'm a software developer with Java background and I'm starting some projects using a Ruby web framework (Padrino/Sinatra).
In my java projects, I usually had some "common" projects whose classes where used in several projects. For instance, I had a central authentication service, and a shared database that stored the user profiles. All my projects that used this service shared some models mapped to the user profile database.
So, despite the framework, orm lib etc., what's the best way of sharing code across several Ruby projects?
Besides this, ruby's gems is one of the best way of reusing common parts of code. Gems have names, version numbers, and descriptions and therefore you can easily maintain up-to-date versions of these libraries, install and uninstall, manage your computer’s local installations of gems using the gem command, available from the command line. Gems became standard with Ruby 1.9, but before you have to use require 'rubygems' line in the scripts. There are several tools that help create them, for example, bundler. Bundler not only tool for gem creation, but an awesome application's dependencies manager.
Put your code into a something.rb file and require it at the top of your other script(s).
You can also use load instead of require, but require has the nice property that it will not include a file more than once. Also, using load requires the .rb extension, whereas require does not, i.e.,
#some_script.rb
puts('hello world')
#another script
require 'some_script'
>> hello world
load 'some_script'
LoadError: no such file to load -- some_script
from (irb):2:in 'load'
from (irb):2
You will almost always use require, but load is an option as well if you want to use it for... whatever reason.

Resources