 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Hugh McGowan
RE: Using Rasta with parent classes [ reply ] 2008-11-27 00:50
|
The ||= will only set the left side if it's nil, which means in our case it will only call Watir::IE.new once. So the parent class stores the session and then each of the child classes can access the value in the instance variable @browser. If the child class changes @browser it won't affect other classes since they get a copy of @@session in @browser each time the child class loads.
For example
a = nil
a ||= 1 # a=1 because a is nil
a ||= 2 # still, a=1 because a is not nil
|
By: Hugh McGowan
RE: Using Rasta with parent classes [ reply ] 2008-11-26 21:03
|
Sorry it took a while to get back to you. So for each tab in the spreadsheet, Rasta will create an instance of that object. Because you had the watir launched in the before_all, it was getting launched each tab you executed.
I think what you want to do would be something more along these lines. A base Page class can handle storing the session information and upon initialization of the child classes it will set @browser to the current session.
require 'watir'
class Page
def initialize
@@session ||= Watir::IE.new
@browser = @@session
end
end
class Page1 < Page
def test
@browser.goto 'http://www.google.com'
end
end
class Page2 < Page
def test
@browser.goto 'http://www.yahoo.com'
end
end
Page1.new.test
Page2.new.test
|
By: Robert Stagner
Using Rasta with parent classes [ reply ] 2008-11-05 21:48
|
I've noticed that when I attempt to run Rasta using a class I've constructed that inherits from another class, the framework instantiates two instances of Internet Explorer. I'm pretty sure that this is due to the fact that my code contains the parent class within the class definition. My code is as follows:
class ContactsPage < PnpPage
include Rasta::Fixture::RastaFixture
attr_accessor :search_term
def before_all
@page = Watir::IE.new
end
def before_each
@page.goto('www.google.com')
end
def google_hits
@page.text_field(:name, 'q').value = @search_term
@page.button(:name, 'btnG').click
google_results = /Results \d+ - \d+ (of|of about) ([\d,]+) for #{@search_term}/
@page.contains_text(google_results)[2].to_i
end
end
I notice that when I remove " < PnpPage" from the code, then I only get one instance of IE. Could the fact that I'm inheriting from another class cause Rasta to launch 2 instances of IE? And if so, is there a workaround to this ... one that allows me to keep the " < PnpPage" syntax?
|
|
 |