Class: Test::Page
- Inherits:
-
Object
- Object
- Test::Page
- Extended by:
- Forwardable
- Defined in:
- lib/test/page.rb,
lib/test/page/version.rb
Constant Summary collapse
- VERSION =
"1.0.3"
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary collapse
-
.element(&block)
Set element for the Page via block.
Instance Method Summary collapse
-
#element ⇒ Object
Get the element instance.
-
#initialize(element = nil) ⇒ Page
constructor
A new instance of Page.
-
#method_missing(name, *args)
Proxies every method call not found on Page to element instance.
-
#redirect_to(page, element = nil)
Create new Page object conveniently on page actions.
Constructor Details
#initialize(element = nil) ⇒ Page
Returns a new instance of Page.
74 75 76 |
# File 'lib/test/page.rb', line 74 def initialize(element=nil) @element = element end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args)
Proxies every method call not found on Test::Page to element instance. Subsequent executions of the same method will be invoked on the Test::Page object directly.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/test/page.rb', line 88 def method_missing(name, *args) begin element rescue SystemStackError raise_invalid_element_definition end if element.respond_to?(name) self.class.send :define_method, name do |*args| element.send(name, *args) {yield} end self.send(name, *args) {yield} else super end end |
Class Attribute Details
.browser
Set and get the browser object for Test::Page.
This makes it possible to reuse one global browser object between different Test::Page objects. It will be also shared between sub-classes of Test::Page class.
19 20 21 |
# File 'lib/test/page.rb', line 19 def browser @browser end |
Instance Attribute Details
#browser
Set and get the browser object for specific Test::Page instance.
This is useful if some specific Test::Page instance needs a different browser than is set via browser method. Popup browser windows might be one example.
If browser is not set via #browser then browser set via browser will be used.
50 51 52 |
# File 'lib/test/page.rb', line 50 def browser @browser || parent_page_browser end |
Class Method Details
.element(&block)
Set element for the Test::Page via block. It will be evaluated lazily after Test::Page has been instantiated.
Element is like the container of the Test::Page - everything outside of that element is not considered as part of the Test::Page. Use as specific element as possible.
35 36 37 |
# File 'lib/test/page.rb', line 35 def element(&block) @element_block = block end |
Instance Method Details
#element ⇒ Object
Get the element instance.
When #setup is defined, it will be executed once per Test::Page instance.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/test/page.rb', line 61 def element @setup_done ||= begin setup if respond_to?(:setup) true end @element ||= begin raise_no_browser_set_exception unless browser element_proc = self.class.element_block element_proc && instance_eval(&element_proc) end end |
#redirect_to(page, element = nil)
Create new Test::Page object conveniently on page actions.
82 83 84 |
# File 'lib/test/page.rb', line 82 def redirect_to(page, element=nil) page.new element end |