我是一般的Ruby的新手。我想用硒来学习水豚做我们公司网站的测试。水豚rspec脚本不执行在描述块
在将代码放入描述块之前,我的代码正在工作。但是我需要在登录后等待页面加载。我做了一些研究,发现期望方法是要走的路,但他们只能在我认为的块中工作。现在,当我运行ruby testscript.rb时,浏览器甚至不打开。以下是代码:
require 'timeout'
require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
require 'capybara/rspec/matchers'
require 'capybara/session/matchers'
require 'capybara/node/matchers'
Capybara.default_driver = :selenium
session = Capybara::Session.new(:selenium)
describe 'login process', :type => :feature do
it 'signs me in' do
visit 'https://testwebsite.com'
find_by_id('login_form')
fill_in('username', with: 'testuser')
fill_in('password', with: 'testpw')
find_by_id('Login').click
expect(page).to have_content('phSearchInput')
end
end
describe 'search install product', :type => :feature do
it 'searches product' do
fill_in('phSearchInput', with: '6109302')
find_by_id('phSearchButton').click
within "SVMXC__Installed_Product__c_body" do
click_on "6109302"
end
end
end
任何帮助表示赞赏。随意提供替代方案来解决等待页面加载问题。我不想睡觉。谢谢!
非常感谢!它现在正在运行。但是我得到了'期望'的NoMethodError。我想我补充了所有要求。有任何想法吗?这是行:expect(page).to have_field('phSearchInput') – shen
@shen假设你正在运行一个现代版本的RSpec,听起来你需要在'水豚/水鸟'之前需要'rspec'或'rspec/expectations' rspec',也许也可以配置RSpec。 –
我昨天刚刚安装了所有东西,所以我相信一切都应该是现代的。我没有'rspec'或'rspec/expectation'。我有'水豚/ rspec/matchers',它在'capybara/rspec'之前,但它仍然不起作用。你有什么想法?谢谢! – shen