Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:35:00+00:00 2026-06-10T03:35:00+00:00

I’m really confused about this. I’m using the Ruby class below in an automated

  • 0

I’m really confused about this. I’m using the Ruby class below in an automated test suite:

class FlightSearchPage

  attr_accessor :page_title

  def initialize(browser, page)
    @browser      = browser
    @start_url    = page
  end

  def method_missing(sym, *args, &block)
    @browser.send sym, *args, &block
  end

  @page_title   = @browser.title

  #def page_title
  #  @browser.title
  #end

end

I’m subclassing it with:

class BrandFlightsPage < FlightSearchPage


    def initialize(browser, page, brand)
      super(browser, page)
      [...snip...]
    end
end

When I instantiate the subclass, passing in @browser, a watir-webdriver object, @browser.title throws:

undefined method `title’ for nil:NilClass (NoMethodError)

But if I uncomment the page_title method in FlightSearchPage, it works as expected. I’ve also tried it with the variable assignment inside the constructor.

I’ve gone around in circles trying to track this down, but I just can’t see it.

Here’s the stacktrace:

undefined method `title' for nil:NilClass (NoMethodError)
/Users/Dazzla/Dropbox/src/Projects/over_the_watir/pages/flight_search_page.rb:13:in `<class:FlightSearchPage>'
/Users/Dazzla/Dropbox/src/Projects/over_the_watir/pages/flight_search_page.rb:1:in `<top (required)>'
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/Dazzla/Dropbox/src/Projects/over_the_watir/pages/brand_flight_search_page.rb:1:in `<top (required)>'
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/Dazzla/Dropbox/src/Projects/over_the_watir/features/step_definitions/steps.rb:1:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:40:in `run!'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
/usr/local/rvm/gems/ruby-1.9.3-p0/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p0/bin/cucumber:19:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p0/bin/cucumber:19:in `<main>'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:35:01+00:00Added an answer on June 10, 2026 at 3:35 am

    This is because

     attr_accessor :page_title
    

    already creates a getter and a setter.

    i would put this

    @page_title   = @browser.title
    

    inside your initialize method..

    class FlightSearchPage
    
      attr_accessor :page_title
    
      def initialize(browser, page)
        @browser      = browser
        @page_title   = @browser.title
        @start_url    = page
      end
    
      def method_missing(sym, *args, &block)
        @browser.send sym, *args, &block
      end
    
    end
    

    or (better) remove the attr_accessor and just add a method

       class FlightSearchPage
    
          def initialize(browser, page)
            @browser      = browser
            @start_url    = page
          end
    
          def method_missing(sym, *args, &block)
            @browser.send sym, *args, &block
          end
    
          def page_title
            return @browser.title unless @browser
            "browser not set, no title"
          end
    
        end
    

    Instantiating the browser:

    This is placed in a file called env.rb which is run before each test:

    Before do
      @browser = Watir::Browser.new
    end
    

    It’s run in the context of the current instance of cucumber’s World

    What I don’t understand is that all other browser methods are working as expected when implemented with accessors except this one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.