Class: SeleniumPage::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium_page/page.rb,
lib/selenium_page/page/errors.rb

Overview

Page

Defined Under Namespace

Classes: Errors

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ Page

rubocop:enable Metrics/MethodLength



56
57
58
59
60
# File 'lib/selenium_page/page.rb', line 56

def initialize(driver)
  raise Errors::WrongDriver unless driver.is_a? Selenium::WebDriver::Driver

  @driver = driver
end

Class Method Details

.configure_url(url) ⇒ Object



8
9
10
11
12
# File 'lib/selenium_page/page.rb', line 8

def self.configure_url(url)
  raise Errors::UnexpectedUrl unless url.is_a? String

  @url = url
end

.element(element_name, element_selector, &block) ⇒ Object

rubocop:disable Metrics/MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/selenium_page/page.rb', line 19

def self.element(element_name, element_selector, &block)
  raise Errors::UnexpectedElementName unless element_name.is_a? Symbol
  unless element_selector.is_a? String
    raise Errors::UnexpectedElementSelector
  end
  if instance_methods.include?(element_name)
    raise Errors::AlreadyDefinedElementName, element_name
  end

  define_method(element_name) do
    if block_given?
      find_element(element_selector, &block)
    else
      find_element(element_selector)
    end
  end
end

.elements(collection_name, collection_selector, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/selenium_page/page.rb', line 37

def self.elements(collection_name, collection_selector, &block)
  raise Errors::UnexpectedElementName unless collection_name.is_a? Symbol
  unless collection_selector.is_a? String
    raise Errors::UnexpectedElementSelector
  end
  if instance_methods.include?(collection_name)
    raise Errors::AlreadyDefinedElementName, collection_name
  end

  define_method(collection_name) do
    if block_given?
      find_elements(collection_selector, &block)
    else
      find_elements(collection_selector)
    end
  end
end

.urlObject



14
15
16
# File 'lib/selenium_page/page.rb', line 14

def self.url
  @url
end

Instance Method Details

#getObject

Raises:



66
67
68
69
70
71
72
73
# File 'lib/selenium_page/page.rb', line 66

def get
  raise Errors::UrlNotSet unless self.class.url

  scheme_and_authority = SeleniumPage.scheme_and_authority
  raise Errors::SchemeAndAuthorityNotSet unless scheme_and_authority

  @driver.get scheme_and_authority + self.class.url
end

#urlObject



62
63
64
# File 'lib/selenium_page/page.rb', line 62

def url
  self.class.url
end