Class: Selenium::WebPage
- Inherits:
-
Object
- Object
- Selenium::WebPage
- Defined in:
- lib/selenium/web_page.rb
Overview
Class that models a web page with a title
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#interval_millis ⇒ Object
Returns the value of attribute interval_millis.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #alert ⇒ Object
- #alert_message ⇒ Object
- #alert_present? ⇒ Boolean
- #button(how, what = nil) ⇒ Object
- #capture_page(file) ⇒ Object
- #capture_screen(file) ⇒ Object
- #click(locator) ⇒ Object
- #click_wait(locator) ⇒ Object
- #close ⇒ Object
- #context_menu(locator) ⇒ Object
- #double_click(locator) ⇒ Object
- #element(how, what = nil) ⇒ Object
- #element_locator(how, what = nil) ⇒ Object
- #element_present?(locator) ⇒ Boolean
- #ensure_present ⇒ Object
-
#enter(locator, text) ⇒ Object
enter the text to the element found by locator.
- #file_upload(how, what) ⇒ Object
- #fire_event(locator, event) ⇒ Object
- #focus(locator) ⇒ Object
- #html ⇒ Object
-
#initialize(browser, expected_title = nil) ⇒ WebPage
constructor
A new instance of WebPage.
- #key(key) ⇒ Object
- #key_down(key) ⇒ Object
- #key_press(locator, key) ⇒ Object
- #key_up(key) ⇒ Object
- #link(how, what = nil) ⇒ Object
- #open_page(url) ⇒ Object
- #present? ⇒ Boolean
- #speed ⇒ Object
- #speed=(value) ⇒ Object
- #text(locator) ⇒ Object
- #text_area(how, what = nil) ⇒ Object
- #text_field(how, what = nil) ⇒ Object
- #text_present?(text) ⇒ Boolean
- #title ⇒ Object
- #to_s ⇒ Object
- #upload(locator, file) ⇒ Object
- #value(locator) ⇒ Object
- #wait_for_load ⇒ Object
- #wait_until(message, &block) ⇒ Object
Constructor Details
#initialize(browser, expected_title = nil) ⇒ WebPage
Returns a new instance of WebPage.
18 19 20 21 22 23 |
# File 'lib/selenium/web_page.rb', line 18 def initialize(browser, expected_title = nil) @browser = browser @expected_title = expected_title @timeout = 60 @interval_millis = 100 end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
15 16 17 |
# File 'lib/selenium/web_page.rb', line 15 def browser @browser end |
#interval_millis ⇒ Object
Returns the value of attribute interval_millis.
16 17 18 |
# File 'lib/selenium/web_page.rb', line 16 def interval_millis @interval_millis end |
#timeout ⇒ Object
Returns the value of attribute timeout.
16 17 18 |
# File 'lib/selenium/web_page.rb', line 16 def timeout @timeout end |
Instance Method Details
#alert_message ⇒ Object
160 161 162 |
# File 'lib/selenium/web_page.rb', line 160 def @browser.get_alert end |
#alert_present? ⇒ Boolean
134 135 136 |
# File 'lib/selenium/web_page.rb', line 134 def alert_present? @browser.is_alert_present end |
#button(how, what = nil) ⇒ Object
122 123 124 |
# File 'lib/selenium/web_page.rb', line 122 def (how, what=nil) Button.new(self, element_locator(how, what)) end |
#capture_page(file) ⇒ Object
201 202 203 |
# File 'lib/selenium/web_page.rb', line 201 def capture_page(file) @browser.capture_entire_page_screenshot(file) end |
#capture_screen(file) ⇒ Object
205 206 207 |
# File 'lib/selenium/web_page.rb', line 205 def capture_screen(file) @browser.capture_screenshot(file) end |
#click(locator) ⇒ Object
114 115 116 |
# File 'lib/selenium/web_page.rb', line 114 def click(locator) @browser.click(locator) end |
#click_wait(locator) ⇒ Object
146 147 148 149 |
# File 'lib/selenium/web_page.rb', line 146 def click_wait(locator) click(locator) wait_for_load end |
#close ⇒ Object
110 111 112 |
# File 'lib/selenium/web_page.rb', line 110 def close @browser.stop end |
#context_menu(locator) ⇒ Object
164 165 166 |
# File 'lib/selenium/web_page.rb', line 164 def (locator) @browser.(locator) end |
#double_click(locator) ⇒ Object
142 143 144 |
# File 'lib/selenium/web_page.rb', line 142 def double_click(locator) @browser.double_click(locator) end |
#element(how, what = nil) ⇒ Object
85 86 87 |
# File 'lib/selenium/web_page.rb', line 85 def element(how, what=nil) HtmlElement.new(self, element_locator(how,what)) end |
#element_locator(how, what = nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/selenium/web_page.rb', line 89 def element_locator(how, what=nil) locator = how if (not what.nil?) if (how == :xpath or how == :name or how == :id) locator = "#{how}=#{what}" else raise "couldn't understand how to build locator using #{how} with #{what}" end end locator end |
#element_present?(locator) ⇒ Boolean
130 131 132 |
# File 'lib/selenium/web_page.rb', line 130 def element_present?(locator) @browser.is_element_present(locator) end |
#ensure_present ⇒ Object
34 35 36 |
# File 'lib/selenium/web_page.rb', line 34 def ensure_present title.should == @expected_title end |
#enter(locator, text) ⇒ Object
enter the text to the element found by locator
152 153 154 |
# File 'lib/selenium/web_page.rb', line 152 def enter(locator, text) @browser.type(locator, text) end |
#file_upload(how, what) ⇒ Object
101 102 103 |
# File 'lib/selenium/web_page.rb', line 101 def file_upload(how, what) FileUpload.new(self, element_locator(how, what)) end |
#fire_event(locator, event) ⇒ Object
168 169 170 |
# File 'lib/selenium/web_page.rb', line 168 def fire_event(locator, event) @browser.fire_event(locator, event) end |
#focus(locator) ⇒ Object
188 189 190 |
# File 'lib/selenium/web_page.rb', line 188 def focus(locator) @browser.focus(locator) end |
#html ⇒ Object
38 39 40 |
# File 'lib/selenium/web_page.rb', line 38 def html @browser.get_html_source end |
#key(key) ⇒ Object
126 127 128 |
# File 'lib/selenium/web_page.rb', line 126 def key(key) Key.new(self, key) end |
#key_down(key) ⇒ Object
172 173 174 175 176 |
# File 'lib/selenium/web_page.rb', line 172 def key_down(key) = "#{key}_key_down" raise NoKeyError.new(key.to_s) unless @browser.respond_to? @browser.send end |
#key_press(locator, key) ⇒ Object
184 185 186 |
# File 'lib/selenium/web_page.rb', line 184 def key_press(locator, key) @browser.key_press(locator, key) end |
#key_up(key) ⇒ Object
178 179 180 181 182 |
# File 'lib/selenium/web_page.rb', line 178 def key_up(key) = "#{key}_key_up" raise NoKeyError.new(key.to_s) unless @browser.respond_to? @browser.send end |
#link(how, what = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/selenium/web_page.rb', line 66 def link(how, what=nil) if (how == :text) locator = "link=#{what}" elsif (how == :href) locator = "xpath=//a[@href='#{what}']" else locator = element_locator(how, what) end Link.new(self, locator) end |
#open_page(url) ⇒ Object
105 106 107 108 |
# File 'lib/selenium/web_page.rb', line 105 def open_page(url) @browser.open(url) wait_for_load end |
#present? ⇒ Boolean
30 31 32 |
# File 'lib/selenium/web_page.rb', line 30 def present? title == @expected_title end |
#speed ⇒ Object
46 47 48 |
# File 'lib/selenium/web_page.rb', line 46 def speed @browser.get_speed.to_i end |
#speed=(value) ⇒ Object
42 43 44 |
# File 'lib/selenium/web_page.rb', line 42 def speed=(value) @browser.set_speed(value) end |
#text(locator) ⇒ Object
118 119 120 |
# File 'lib/selenium/web_page.rb', line 118 def text(locator) @browser.get_text(locator) end |
#text_area(how, what = nil) ⇒ Object
81 82 83 |
# File 'lib/selenium/web_page.rb', line 81 def text_area(how, what=nil) TextArea.new(self, element_locator(how, what)) end |
#text_field(how, what = nil) ⇒ Object
77 78 79 |
# File 'lib/selenium/web_page.rb', line 77 def text_field(how, what=nil) TextField.new(self, element_locator(how, what)) end |
#text_present?(text) ⇒ Boolean
138 139 140 |
# File 'lib/selenium/web_page.rb', line 138 def text_present?(text) @browser.is_text_present(text) end |
#title ⇒ Object
25 26 27 28 |
# File 'lib/selenium/web_page.rb', line 25 def title raise 'nil as browser' unless @browser @browser.get_title end |
#to_s ⇒ Object
209 210 211 |
# File 'lib/selenium/web_page.rb', line 209 def to_s "#{self.class}('#{@expected_title}') - #{browser.to_s}" end |
#upload(locator, file) ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/selenium/web_page.rb', line 192 def upload(locator, file) # @browser.attach_file(locator, file) @browser.click(locator) require 'auto_it' autoit = AutoIt.load window = AutoItWindow.wait_for(autoit, 'File Upload') puts window end |
#value(locator) ⇒ Object
156 157 158 |
# File 'lib/selenium/web_page.rb', line 156 def value(locator) @browser.get_value(locator) end |
#wait_for_load ⇒ Object
50 51 52 |
# File 'lib/selenium/web_page.rb', line 50 def wait_for_load @browser.wait_for_page_to_load end |
#wait_until(message, &block) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/selenium/web_page.rb', line 54 def wait_until(, &block) Timeout::timeout(timeout, "Timeout waiting for : #{}") do while(not yield ) sleep interval_millis / 1000.0 end end end |