[rspec-users] Trouble with Capybara and RSpec on a new model spec

venkat damarasing lists at ruby-forum.com
Tue Jun 18 11:55:49 UTC 2013


Hi All,
Iam new to ruby application having little knowledge,and currently am
working for a testing application which is designed on
Ruby,capybara,rspec and am having an issue i.e when am click on a
button a javascript popup is displaying and sometime modalpopup also
displaying but am unable to click the alert and even i have tried
different ways with the help of google but none of them worked, for
example the script which i have used for clicking the alert is below

1.alert=page.driver.browser.switch_to.alert
alert.send(‘Stay on Page’)

2. page.evaluate_script(‘window.confirm = function() { return true; }’)
page.click(“Stay on Page”)

Coming to my frame work we have four files
1. Testcase.rb file---here the logic which test case required which
looks like following for details find in the attachment
require 'spec_helper'
feature 'Brochure Sample' do
  #Config changes
  app = Application.new
  #Specify Object Maps
  scenario 'Apply To All Levels Sample Messages' do
   begin
    app.utilities.setup_directory('Apply To All Levels Sample Messages')
    #Specify Test data
    #Launch the web site, and open Application
rescue Exception => e
      app.utilities.capture_screen_shot('script failed','fail')
      raise e
   end
  end
end

2.class file
The methods required for the test case
3. Spec Helpers
This contains some configuration i.e about drivers it looks like the 
below for details find the attachment

require ‘capybara’
require ‘capybara/rspec’
require ‘capybara/dsl’
require ‘selenium-webdriver’
require ‘yaml’
#require ‘capybara-screenshot/rspec’

Capybara.default_driver = :selenium
Capybara.run_server = false
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.include Capybara::DSL
config.include Capybara::RSpecMatchers
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
 #Capybara configuration changes from the default that are needed.
Capybara.configure do |config|
config.match = :prefer_exact
config.exact_options = true
config.ignore_hidden_elements = true
config.visible_text_only = true
end

end

require_relative ‘configuration’
require_relative ‘helpers/common/application’

#this recursively pulls all files under the ‘helpers’ folder.
#puts ‘Current Directory:-’ + File.dirname(__FILE__)
#puts [File.join(File.dirname(__FILE__), 'helpers', '*.rb')]
current_path = File.expand_path File.dirname(__FILE__)
#puts “CURRENT” + current_path
helpers_path = File.join current_path, “helpers”
#puts “HELPERS” + helpers_path
Dir["#{helpers_path}/**/*.rb"].each { |file|
require file
#puts file
}

4.common
This is about utility i.e. the common methods used in the project
5.configuration
This contains the required urls,credentials etc

so can anyone please help me for clicking the alerts,modalpopups what 
are the changes that i need to do for my framework please guide for 
solving this issue

Attachments:
http://www.ruby-forum.com/attachment/8517/spechelperbfile.JPG
http://www.ruby-forum.com/attachment/8518/Testcasefile_.rbfile_.JPG
http://www.ruby-forum.com/attachment/8519/commonfiles.JPG
http://www.ruby-forum.com/attachment/8521/class_file.JPG


-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list