Hi Edith, Try putting the "myFrame" under the describe in a "before :each" or "before :all" block.
Chandu On Jan 28, 4:34 pm, Edith <[email protected]> wrote: > Hi Everyone, > > I'm trying to understand the scoping of the browser variable that is > created in itest2 generated code. When I copy this code into an "it" > block or into a "def" block in a watircraft generated method then I > get no errors. > > When I try to reference the browser object in the "descrbe" block in > the test spec, I get a NameError. For example, the code: > > $LOAD_PATH.unshift File.dirname(__FILE__) unless > $LOAD_PATH.include? File.dirname(__FILE__) > require 'spec_helper' > > describe "some text here" do > it "should do something" do > myFrame=browser.frame(:name, "someFrame") > myFrame.text.include?("Name").should == true > end > > it "should do something else" do > myFrame=browser.frame(:name, "someFrame") > myFrame.text.include?("Name2").should == true > end > end > > works just fine but the following: > > $LOAD_PATH.unshift File.dirname(__FILE__) unless > $LOAD_PATH.include? File.dirname(__FILE__) > require 'spec_helper' > > describe "some text here" do > myFrame=browser.frame(:name, "someFrame") > > it "should do something" do > myFrame.text.include?("Name").should == true > end > > it "should do something else" do > myFrame.text.include?("Name2").should == true > end > end > > throws the following error: > > C:/watir/ae_user_preferences/test/specs/ > verify_up_general_content_spec.rb:6: undefined local variable or > method `browser' for Spec::Example::ExampleGroup::Subclass_1:Class > (NameError) > from C:/ruby186/lib/ruby/gems/1.8/gems/rspec-1.2.9/lib/spec/example/ > example_group_methods.rb:183:in `module_eval' > from C:/ruby186/lib/ruby/gems/1.8/gems/rspec-1.2.9/lib/spec/example/ > example_group_methods.rb:183:in `subclass' > from C:/ruby186/lib/ruby/gems/1.8/gems/rspec-1.2.9/lib/spec/example/ > example_group_methods.rb:55:in `describe' > from C:/ruby186/lib/ruby/gems/1.8/gems/rspec-1.2.9/lib/spec/example/ > example_group_factory.rb:31:in `create_example_group' > from C:/ruby186/lib/ruby/gems/1.8/gems/rspec-1.2.9/lib/spec/dsl/ > main.rb:28:in `describe' > from C:/watir/ae_user_preferences/test/specs/ > verify_up_general_content_spec.rb:5 > > I don't understand why the browser variable isn't "known" at the > "describe" level but is in the "it" block of my test spec and in the > "def' blocks in the module methods associated with my watircraft test > suite. > > Thanks in advance, > Edith -- You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to [email protected] Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/watir-general
