运行 RSpec/Watir 脚本异常终止

发布于 2024-09-26 10:29:26 字数 1135 浏览 0 评论 0原文

我正在使用 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自找没趣 2024-10-03 10:29:26

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

规范 myBrowserTest.rb

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

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

戴夫

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

_畞蕅 2024-10-03 10:29:26

我发现的一个问题是您打开了两个浏览器。我会将其替换

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

为:

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

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')
献世佛 2024-10-03 10:29:26

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

require "rubygems"
require "watir"

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

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.

嘿哥们儿 2024-10-03 10:29:26

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文