下面的 gem 文件:
group :development, :test do
gem 'rspec-rails'
gem 'capybara-selenium'
gem "chromedriver-helper"
end
我正在使用反应视图测试轨道应用程序。测试正在进行中,但是当单击按钮时,它会单击其他地方。
rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'capybara/rspec'
require 'selenium/webdriver'
require 'chromedriver/helper'
Capybara.default_max_wait_time = 5
Capybara.javascript_driver = :selenium_chrome
RSpec.configure do |config|
config.raise_errors_for_deprecations!
end
test_spec.rb
require 'rails_helper'
feature "Select a Work Station" do
scenario "User should select a embedding work station" , js: true do
# 1- Go to login screen and authenticate
visit "http://localhost:3001"
fill_in('Email', :with => 'xxx')
fill_in('Password', :with => 'xxxx')
click_button("Submit")
# save_and_open_screenshot
# 2- Select an account
find('tr[accountname="Clinical Pathology Laboratories"]').click
# save_and_open_screenshot
# 3- Use default location
click_button("Save")
# save_and_open_screenshot
# 4- Click on the Embedding button
find('img[alt="Embedding"]').click
# 5- Start Session
find('#work_station_id').find('option', text: "Embedding #1").select_option
# ------------ clicking action ------
# page.driver.browser.action.move_to(find('button', text: "Start Session")).move_by(0, 5)
# expect(page).to have_select('#work_station_id')
# select 'Embedding #1', :from => '#work_station_id'
# page.driver.browser.mouse.move_to(find('button', text: "Start Session"), 0, 5)
# find('button[class="btn btn-success"]').click
# page.click_link_or_button('Start Session')
# click_button("Start Session")
end
end
问题开始#------------单击操作------和下方,我尝试单击按钮,但我希望它将我移动到下一页。我尝试以多种不同的方式单击"开始会话"按钮。相反,我得到那个按钮在点上不可点击......
Failure/Error: page.click_link_or_button('Start Session')
Selenium::WebDriver::Error::UnknownError:
unknown error: Element <button type="submit" class="btn btn-success" data-target="#undefined">...</button> is not clickable at point (628, 358). Other element would receive the click: <div class="wrapper wrapper-content animated fadeInRight">...</div>
(Session info: chrome=60.0.3112.101)
(Driver info: chromedriver=2.31.488774 (7e15618d1bf16df8bf0ecf2914ed1964a387ba0b),platform=Mac OS X 10.12.6 x86_64)
您遇到的问题是您有另一个元素(
...
( 在您尝试单击的按钮上。 您需要弄清楚它存在的原因,然后执行任何必要的操作以使按钮可用。 这可能包括滚动页面,使屏幕尺寸更大,以便内容不会重叠,关闭有问题的元素(如果它是模态等(。
此外,您正在使用硒操作方法,但将水豚元素传递给它们,而不是实际执行操作。
如果要调用这些方法,则需要在 Capybara 元素上调用native
以获取硒原生元素引用,并在操作链的末端调用 execute 以实际使其执行某些操作。
page.driver.browser.action.move_to(find('button', text: "Start Session").native).move_by(0, 5).perform