Class: Page

Inherits:
Object
  • Object
show all
Includes:
GemsOverriding, PageObject
Defined in:
lib/page.rb

Constant Summary collapse

STAND =
common_config['stand'].freeze
CONFIG =
common_config.merge!(YAML.load_file("lib/configs/#{STAND}.yml")).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(visit = false) ⇒ Page

Returns a new instance of Page.



20
21
22
# File 'lib/page.rb', line 20

def initialize(visit = false)
  super(Page.driver, visit)
end

Class Method Details

.driverObject



16
17
18
# File 'lib/page.rb', line 16

def self.driver
  Driver.instance.browser
end

Instance Method Details

#close_other_windowsObject

close all windows except current



45
46
47
48
49
50
51
52
53
54
# File 'lib/page.rb', line 45

def close_other_windows
  cur_window = browser.window_handle
  browser.window_handles.each do |window|
    next if window.eql?(cur_window)

    browser.switch_to.window(window)
    browser.close
  end
  browser.switch_to.window(cur_window)
end

#code_mirror(id) ⇒ Object



35
36
37
# File 'lib/page.rb', line 35

def code_mirror(id)
  execute_script("return $('##{id}').val();")
end

#switch_next_windowObject

switch to next window and close current



57
58
59
60
61
62
63
64
65
66
# File 'lib/page.rb', line 57

def switch_next_window
  cur_window = browser.window_handle
  browser.close
  browser.window_handles.each do |window|
    next if window.eql?(cur_window)

    browser.switch_to.window(window)
    break
  end
end

#type_ck_editor(id, text) ⇒ Object

deal with ck editor text areas



40
41
42
# File 'lib/page.rb', line 40

def type_ck_editor(id, text)
  execute_script("CKEDITOR.instances['#{id}'].insertText('#{text}');")
end

#type_code_mirror(id, text) ⇒ Object

deal with code mirror text areas



30
31
32
33
# File 'lib/page.rb', line 30

def type_code_mirror(id, text)
  execute_script("$('##{id}').val('#{text}');")
  execute_script("$('##{id}').keyup();")
end

#upload_file(element, file_path) ⇒ Object

direct upload files via window upload dialog



25
26
27
# File 'lib/page.rb', line 25

def upload_file(element, file_path)
  element.send_keys(file_path.tr('/', '\\'))
end