Class: Bucky::TestEquipment::PageObject::Pages

Inherits:
Object
  • Object
show all
Defined in:
lib/bucky/test_equipment/pageobject/pages.rb

Instance Method Summary collapse

Constructor Details

#initialize(service, device, driver) ⇒ Pages

Returns a new instance of Pages.



7
8
9
# File 'lib/bucky/test_equipment/pageobject/pages.rb', line 7

def initialize(service, device, driver)
  collect_pageobjects(service, device, driver)
end

Instance Method Details

#collect_pageobjects(service, device, driver) ⇒ Object

Load page class and define page method

Parameters:

  • service (String)
  • device (String)

    (pc, sp)

  • driver (Object)

    Webdriver object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bucky/test_equipment/pageobject/pages.rb', line 15

def collect_pageobjects(service, device, driver)
  # Create module name
  module_service_name = service.split('_').map(&:capitalize).join
  Dir.glob("#{$bucky_home_dir}/services/#{service}/#{device}/pageobject/*.rb").each do |file|
    require file

    page_name = file.split('/')[-1].sub('.rb', '')
    page_class_name = page_name.split('_').map(&:capitalize).join

    # Get instance of page class
    page_class = eval(format('Services::%<module_service_name>s::%<device>s::PageObject::%<page_class_name>s', module_service_name: module_service_name, device: device.capitalize, page_class_name: page_class_name))
    page_instance = page_class.new(service, device, page_name, driver)

    # Define method by page name
    self.class.class_eval do
      define_method(page_name) { page_instance }
    end
  end
end

#get_part(args) ⇒ Object

Get Web element by page, part, num

Parameters:



37
38
39
40
41
# File 'lib/bucky/test_equipment/pageobject/pages.rb', line 37

def get_part(args)
  return send(args[:page]).send(args[:part][:locate])[args[:part][:num]] if part_plural?(args)

  send(args[:page]).send(args[:part])
end

#part_exist?(args) ⇒ Bool

Parameters:

Returns:

  • (Bool)


52
53
54
55
56
57
# File 'lib/bucky/test_equipment/pageobject/pages.rb', line 52

def part_exist?(args)
  get_part(args)
  true
rescue Selenium::WebDriver::Error::NoSuchElementError
  false
end

#part_plural?(args) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/bucky/test_equipment/pageobject/pages.rb', line 45

def part_plural?(args)
  # If the part is hash and has 'num' key, it has plural elements.
  args[:part].class == Hash && args[:part].key?(:num)
end