【问题标题】:Abnormal termination running an RSpec/Watir script运行 RSpec/Watir 脚本的异常终止
【发布时间】:2010-10-10 13:22:26
【问题描述】:

我正在使用 Ruby 1.8.6、Watir 1.6.6 和 RSpec 1.3.0。当我运行以下脚本时,它“终止”(EclipsePDT IDE 中给出的术语)但没有列出任何错误。当我从 Windows 上的 c 提示符运行它时相同,除了没有“终止”。浏览器永远不会打开。有人有线索吗?如果我去掉 describe、it 和 end 行,它运行正常。

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

【问题讨论】:

  • 请格式化代码,这样不可读:)
  • 我不确定是什么问题。浏览器永远不会打开?我不明白terminate 的问题。
  • 是的,浏览器永远不会打开。 :( 我添加了一些“放置”以查看哪些运行了哪些没有运行。
  • 'it' 命令外的 puts 运行了,it 命令内的 puts 没有运行。
  • Zetetic - 感谢您帮助格式化。

标签: ruby rspec watir


【解决方案1】:

我终于发现 RSpec 测试脚本是通过在命令行上调用“spec”来运行的,如下所示:

规范 myBrowserTest.rb

我假设我通过调用 Ruby 来运行它们,就像我对 TestUnit 文件所做的那样。

现在我需要弄清楚如何从 Eclipse PDT 中调用“规范”。感谢所有提出想法的人。我更感激它,因为我一开始就没有很好地提出我的问题。

戴夫

【讨论】:

  • 我忘了说你必须用spec而不是ruby调用脚本。 :)
【解决方案2】:

我看到的一个问题是您打开了两个浏览器。我会替换这个:

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

与:

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

【讨论】:

  • 谢谢。要是我能打开一个浏览器就好了! ;(
【解决方案3】:

如果将其添加到before :all 块中是否有帮助:

require "rubygems"
require "watir"

当我需要 ruby​​gems 和 watir 时,您的代码会在我的机器上打开浏览器。

【讨论】:

    【解决方案4】:

    我添加了一些 puts 语句来查看哪些部分正在运行,哪些部分从未到达:

    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
    

    输出:

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

    显然,测试用例的块没有运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      • 1970-01-01
      • 2013-03-30
      • 2016-10-01
      • 2016-11-08
      • 2011-11-29
      • 1970-01-01
      相关资源
      最近更新 更多