Skip to content

Instantly share code, notes, and snippets.

@sevos
Created March 24, 2017 14:52
Show Gist options
  • Save sevos/9727dd876a14339e13fdbb328ebd6044 to your computer and use it in GitHub Desktop.
Save sevos/9727dd876a14339e13fdbb328ebd6044 to your computer and use it in GitHub Desktop.
This is a helper simulating mouse events related to hovering over an element: onmouseenter onmouseleave etc.
require 'rails_helper'
RSpec.feature 'Feature', js: true do
include InteractionHelper
scenario 'Scenario' do
visit '/'
hover_mouse(find('div#id')) do
click_on 'Button'
end
end
end
module InteractionHelper
def hover_mouse(element)
page.driver.browser.action.move_to(element.native, -1, -1).perform
page.driver.browser.action.move_to(element.native, 1, 1).perform
element.hover
within(element) do
yield
end
page.driver.browser.action.move_to(element.native, 1, 1).perform
page.driver.browser.action.move_to(element.native, -1, -1).perform
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment