Class: UlePage::Page

Inherits:
SitePrism::Page
  • Object
show all
Extended by:
SitePrismExtender
Includes:
Capybara::DSL, RSpec::Matchers, Helper
Defined in:
lib/ule_page/page.rb

Direct Known Subclasses

Create, Detail, Index

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SitePrismExtender

class_name, define_elements, define_elements_js, define_sub_elements, element_collection

Methods included from Helper

#confirm_alert, #finished_all_ajax_requests?, #need_run_javascript, #pause_here, #pg, #signout, #visit_admin_pages, #wait_for_ajax

Class Method Details

.inherited(subclass) ⇒ Object

e.g. is_order_detail?



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

def self.inherited(subclass)
  method_name = "is_#{subclass.parent.name.demodulize.singularize.underscore}_#{subclass.name.demodulize.singularize.underscore}?"
  subclass.send(:define_method, method_name) do
    true
  end
end

.set_urls(*urls) ⇒ Object



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

def self.set_urls(*urls)
  @urls = urls
  add_to_page_map @urls
  set_first_url
end

.urlsObject



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

def self.urls
  @urls
end

Instance Method Details

#check_element_have_content(selector, content) ⇒ Object

usage: check_element_have_content ‘.nav li a’, ‘my brand’



110
111
112
# File 'lib/ule_page/page.rb', line 110

def check_element_have_content(selector, content)
  should have_selector(selector, text: content)
end

#check_element_have_no_content(selector, content) ⇒ Object



114
115
116
# File 'lib/ule_page/page.rb', line 114

def check_element_have_no_content(selector, content)
  should have_no_selector(selector, text: content)
end

#check_form(hashtable, fields = [], map = {}) ⇒ Object

usage: check_form hashtabe, [:id, :name], => “id2” check_form hashtable, [], => “id2” check_form hashtable if the fields is empty, it will use all the keys of the hashtable

precondition: there are the elements mapped to the hashtable keys.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ule_page/page.rb', line 67

def check_form(hashtable, fields = [], map = {})
  fields = hashtable.keys.map { |k| k.to_sym } if fields.empty?

  fields.each do |f|
    key = f
    key = map[f] if map.has_key?(f)

    if self.respond_to? f.to_sym
      el_content = send(f).send(:value)

      expect(el_content).to eq hashtable[key.to_s]
    end

  end
end

#check_have_content(content) ⇒ Object



83
84
85
# File 'lib/ule_page/page.rb', line 83

def check_have_content(content)
  page.should have_content content
end

#check_have_hashtable_content(hashtable, keys = []) ⇒ Object

usage: check_have_hashtable_content hashtable usage: check_have_hashtable_content hashtable, [:id, :name]



93
94
95
96
97
98
99
# File 'lib/ule_page/page.rb', line 93

def check_have_hashtable_content(hashtable, keys = [])
  keys = hashtable.keys if keys.empty?

  keys.each do |k|
    check_have_content hashtable[k.to_s]
  end
end

#check_have_no_hashtable_content(hashtable, keys = []) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/ule_page/page.rb', line 101

def check_have_no_hashtable_content(hashtable, keys = [])
  keys = hashtable.keys if keys.empty?

  keys.each do |k|
    check_have_not_content hashtable[k.to_s]
  end
end

#check_have_not_content(content) ⇒ Object



87
88
89
# File 'lib/ule_page/page.rb', line 87

def check_have_not_content(content)
  expect(page).to have_no_content(content)
end

#fill_form(hashtable, fields = [], map = {}) ⇒ Object

usage: fill_form hashtable, [:id, :name], => “id2” fill_form hashtable, [], => “id2” fill_form hashtable if the fields is empty, it will use all the keys of the hashtable



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ule_page/page.rb', line 46

def fill_form(hashtable, fields = [], map = {})
  fields = hashtable.keys.map { |k| k.to_sym } if fields.empty?

  fields.each do |f|
    key = f
    key = map[f] if map.has_key?(f)

    # p "setting #{f} with #{hashtable[key.to_s]}"

    send(f).send(:set, hashtable[key]) or send(f).send(:select, hashtable[key]) if self.respond_to? f.to_sym
  end
end

#find_row(content, rows = nil) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/ule_page/page.rb', line 118

def find_row(content, rows = nil)
  rows = page.all('tr') if rows.nil?

  rows.each do |r|
    return r if r.has_content?(content)
  end
end

#go_backObject



126
127
128
# File 'lib/ule_page/page.rb', line 126

def go_back
  click_link_or_button '返回'
end

#open(expansion = {}) ⇒ Object



36
37
38
39
# File 'lib/ule_page/page.rb', line 36

def open(expansion = {})
  self.load expansion
  self
end