Class: Gridium::ElementVerification
- Inherits:
-
Object
- Object
- Gridium::ElementVerification
- Defined in:
- lib/element_verification.rb
Instance Method Summary collapse
-
#attribute(attribute, value) ⇒ Object
TODO:.
-
#css(attribute, value) ⇒ Object
TODO:.
-
#initialize(element, timeout, fail_test: false, element_should_exist: true) ⇒ ElementVerification
constructor
A new instance of ElementVerification.
- #not ⇒ Object
- #present ⇒ Object
-
#selected ⇒ Object
TODO:.
- #text(text) ⇒ Object
-
#value(value) ⇒ Object
TODO:.
- #visible ⇒ Object
Constructor Details
#initialize(element, timeout, fail_test: false, element_should_exist: true) ⇒ ElementVerification
Returns a new instance of ElementVerification.
9 10 11 12 13 14 |
# File 'lib/element_verification.rb', line 9 def initialize(element, timeout, fail_test: false, element_should_exist: true) @element = element # Selement @timeout = timeout @should_exist = element_should_exist @fail_test = fail_test end |
Instance Method Details
#attribute(attribute, value) ⇒ Object
TODO:
137 138 139 |
# File 'lib/element_verification.rb', line 137 def attribute(attribute, value) raise NotImplementedError end |
#css(attribute, value) ⇒ Object
TODO:
142 143 144 |
# File 'lib/element_verification.rb', line 142 def css(attribute, value) raise NotImplementedError end |
#not ⇒ Object
16 17 18 |
# File 'lib/element_verification.rb', line 16 def not ElementVerification.new(@element, @timeout, fail_test: @fail_test, element_should_exist: false) end |
#present ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/element_verification.rb', line 93 def present = nil = nil should_be_present = @should_exist if should_be_present = "Element should be present. timed out after #{@timeout} seconds" = "is present." else = "Element should NOT be present. timed out after #{@timeout} seconds" = "is not present." end wait = Selenium::WebDriver::Wait.new :timeout => @timeout, :interval => 1 begin wait.until do element_is_present = @element.element(timeout: @timeout).present? if element_is_present && should_be_present ElementExtensions.highlight(@element) if Gridium.config.highlight_verifications log_success() return @element elsif !element_is_present && !should_be_present Log.debug("[GRIDIUM::ElementVerification] Confirming element is NOT present...") log_success() else # TODO: @rizzza: This `.not` case is wrong. It bails too early and does not evaluate with the wait block log_issue() end end @element end end |
#selected ⇒ Object
TODO:
132 133 134 |
# File 'lib/element_verification.rb', line 132 def selected raise NotImplementedError end |
#text(text) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/element_verification.rb', line 20 def text(text) = nil = nil should_have_text = @should_exist element_text = @element.text if @element.present? $verification_passes += 1 else Log.error("[GRIDIUM::ElementVerification] Cannot determine element text. Element is not present.") end if should_have_text = "Element should contain text (#{text}), but does not. timed out after #{@timeout} seconds" = "contains text (#{text})." else = "Element should not contain text (#{text}), but does. timed out after #{@timeout} seconds" = "does not contain text (#{text}). Actual text is: (#{element_text})." end wait = Selenium::WebDriver::Wait.new :timeout => @timeout, :interval => 1 begin wait.until do element_contains_text = element_text.eql?(text) if should_have_text && element_contains_text Log.debug("[GRIDIUM::ElementVerification] Confirming text (#{text}) is within element...") ElementExtensions.highlight(@element) if Gridium.config.highlight_verifications log_success() elsif !should_have_text && !element_contains_text Log.debug("[GRIDIUM::ElementVerification] Confirming text (#{text}) is NOT within element...") ElementExtensions.highlight(@element) if Gridium.config.highlight_verifications log_success() else # TODO: @rizzza: This `.not` case is wrong. It bails too early and does not evaluate with the wait block log_issue("#{} Element's text is: (#{element_text}).") end end @element end end |
#value(value) ⇒ Object
TODO:
127 128 129 |
# File 'lib/element_verification.rb', line 127 def value(value) raise NotImplementedError end |
#visible ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/element_verification.rb', line 60 def visible = nil = nil should_be_visible = @should_exist if should_be_visible = "Element should be visible. timed out after #{@timeout} seconds" = "Element is visible." else = "Element should not be visible. timed out after #{@timeout} seconds" = "Element is not visible." end wait = Selenium::WebDriver::Wait.new :timeout => @timeout, :interval => 1 begin wait.until do element_is_displayed = @element.element(timeout: @timeout).displayed? if element_is_displayed && should_be_visible ElementExtensions.highlight(@element) if Gridium.config.highlight_verifications log_success() return @element elsif !element_is_displayed && !should_be_visible Log.debug("[GRIDIUM::ElementVerification] Confirming element is NOT visible...") log_success() else # TODO: @rizzza: This `.not` case is wrong. It bails too early and does not evaluate with the wait block log_issue() end end @element end end |