tags:

views:

43

answers:

4

I am using Ruby 1.8.6, Watir 1.6.6, and RSpec 1.3.0. When I run the following script, it "terminates" (term given in EclipsePDT IDE) but no error is listed. Same when I run it from the c-prompt on windows, except no "terminate". The browser never opens. Anybody got a clue? It runs OK if I take off the describe, it, and end lines.

describe 'FaceBook' do
  before :all do
    @b = Watir::Browser.new
    @b = Watir::IE.start('http://www.facebook.com')
  end

  it 'Default Page links' do
    @b.link(:class, 'fbxWelcomeBoxName').text.should == 'Dave McNulla'
    @b.link(:href, 'http://www.facebook.com/?ref=home').text.should == 'Home'
    @b.link(:href, 'http://www.facebook.com/dave.mcnulla').text.should == 'Profile'
  end
  it 'Home Page links' do
    @b.link(:href, 'http://www.facebook.com/?ref=home').click
    @b.link(:href, 'http://www.facebook.com/?ref=home').text.should == 'Home'
    @b.link(:href, 'http://www.facebook.com/dave.mcnulla').text.should == 'Profile'
  end
  it 'Profile Page links' do
    @b.link(:text, 'Profile').click
    @b.link(:href, 'http://www.facebook.com/?ref=home').text.should == 'Home'
    @b.link(:href, 'http://www.facebook.com/dave.mcnulla').text.should == 'Profile'
  end

  after :all do
    @b.close
  end
end
A: 

One problem I see is that you open two browsers. I would replace this:

@b = Watir::Browser.new
@b = Watir::IE.start('http://www.facebook.com')

with:

@b = Watir::Browser.start('http://www.facebook.com')
Željko Filipin
Thanks. If only I could open one browser! ;(
Dave McNulla
A: 

Does it help if you add this to before :all block:

require "rubygems"
require "watir"

Your code opens the browser at my machine when I require rubygems and watir.

Željko Filipin
A: 

I added some puts statements to see which parts were running and which parts were never arrived at:

require 'spec'

puts "before strting"
describe 'FaceBook' do
  require 'watir'
  require 'rubygems'

  puts "before all"
  before :all do
    puts "all"
    @b = Watir::Browser.start('http://www.facebook.com')
  end

  puts "before Default"
  it 'Default Page links' do
    puts "Default"
    @b.link(:class, 'fbxWelcomeBoxName').text.should == 'Dave McNulla'
    @b.link(:href, 'http://www.facebook.com/?ref=home').text.should == 'Home'
    @b.link(:href, 'http://www.facebook.com/dave.mcnulla').text.should == 'Profile'
  end
  puts "before Home"    
  it 'Home Page links' do
    puts "Home"
    @b.link(:href, 'http://www.facebook.com/?ref=home').click
    @b.link(:href, 'http://www.facebook.com/?ref=home').text.should == 'Home'
    @b.link(:href, 'http://www.facebook.com/dave.mcnulla').text.should == 'Profile'
  end
  puts "before Profile"
  it 'Profile Page links' do
    puts "Profile"
    @b.link(:text, 'Profile').click
    @b.link(:href, 'http://www.facebook.com/?ref=home').text.should == 'Home'
    @b.link(:href, 'http://www.facebook.com/dave.mcnulla').text.should == 'Profile'
  end
  puts "before after"    
  after :all do
    puts "All"
    @b.close
  end
end

Output:

before strting
before all
before Default
before Home
before Profile
before after

Apparently, the blocks for the test cases is not running.

Dave McNulla
+1  A: 

I finally found out that RSpec test scripts run from calling 'spec' on the command line as in:

spec myBrowserTest.rb

I had assumed that I ran them by calling Ruby, as I had done on TestUnit files.

Now I need to figure out how to call 'spec' from within Eclipse PDT. Thanks to everybody that brought in ideas. I appreciate it even more because I did a poor job of presenting my problem in the first place.

Dave

Dave McNulla
I forgot to say you have to call the script with `spec` instead of `ruby`. :)
Željko Filipin