Dmytro Vasin
Dmytro Vasin

Reputation: 823

Capybara in separate ruby file

in some.rb file i put that code:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'

Capybara.run_server = false
Capybara.current_driver = :selenium

module MyTest
  class Test
    include Capybara::DSL
    def first
      visit('http://www.google.com')

      save_and_open_page

      # fill_in('?',:with => term)
      # page.should have_css('div#res li')
    end
  end
end

t = MyTest::Test.new
t.first

and try to run this file: ruby some.rb

and in saved page - i get google page, but in other coding...

how can i fix this ? ( i want put in google search some query - but in this coding i don't know what put in fill_in )

Upvotes: 0

Views: 119

Answers (1)

HemChe
HemChe

Reputation: 2337

Check the below link http://blog.dharanasoft.com/2012/03/19/a-search-spider-in-ruby-using-capybara-webkit/

The example is pretty helpful. Let me know in comments if you need a more detailed explanation.

fill_in "q", :with => ARGV[0] || "I love Ruby!" 

In the above statement, q is the google search box id(you can get it through firebug add on in firefox) and the last statement "I Love Ruby" is the query that will get pasted in the search box once the code is executed.

Upvotes: 2

Related Questions