Class: SeleniumHelperTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/generators/templates/helpers/selenium_helper_template.rb

Instance Method Summary collapse

Methods inherited from Template

#initialize, #parsed_body

Constructor Details

This class inherits a constructor from Template

Instance Method Details

#bodyObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/templates/helpers/selenium_helper_template.rb', line 4

def body
  <<~EOF
    require 'selenium-webdriver'
    require_relative 'driver_helper'

    module Raider
      module SeleniumHelper
        def click_when_present
          # This is an example of an implicit wait in selenium
          wait = Selenium::WebDriver::Wait.new(timeout: 15)
          wait.until { present? }
          click
        end

        def select_by(key, value)
          # Creates new Select object to use the select by method
          dropdown = Selenium::WebDriver::Support::Select.new self
          dropdown.select_by(key, value)
        end

        def hover
          # Using actions to move the mouse over an element
          DriverHelper.driver.action.move_to(self).perform
        end

        # How to perform right click through the context click method
        def right_click
          DriverHelper.driver.action.context_click(self).perform
        end
      end

      # Here we are opening the selenium class and adding our custom method
      class Selenium::WebDriver::Element
        include SeleniumHelper
      end
    end
  EOF
end