Class: Applitools::Selenium::DomSnapshotScript::RecursiveSnapshotter
- Inherits:
-
Object
- Object
- Applitools::Selenium::DomSnapshotScript::RecursiveSnapshotter
- Defined in:
- lib/applitools/selenium/visual_grid/dom_snapshot_script.rb
Constant Summary collapse
- POLL_INTERVAL_MS =
0.5
Instance Attribute Summary collapse
-
#cross_origin_rendering ⇒ Object
Returns the value of attribute cross_origin_rendering.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#script ⇒ Object
Returns the value of attribute script.
-
#should_skip_failed_frames ⇒ Object
Returns the value of attribute should_skip_failed_frames.
-
#use_cookies ⇒ Object
Returns the value of attribute use_cookies.
Instance Method Summary collapse
- #create_cross_frames_dom_snapshots ⇒ Object
- #create_dom_snapshot_threaded ⇒ Object
-
#initialize(driver, script, cross_origin_rendering, use_cookies) ⇒ RecursiveSnapshotter
constructor
A new instance of RecursiveSnapshotter.
- #process_dom_snapshot_frames(dom) ⇒ Object
- #snapshot_and_process_cors_frames(dom) ⇒ Object
Constructor Details
#initialize(driver, script, cross_origin_rendering, use_cookies) ⇒ RecursiveSnapshotter
Returns a new instance of RecursiveSnapshotter.
102 103 104 105 106 107 108 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 102 def initialize(driver, script, cross_origin_rendering, ) self.should_skip_failed_frames = true self.driver = driver self.script = script self.cross_origin_rendering = cross_origin_rendering self. = end |
Instance Attribute Details
#cross_origin_rendering ⇒ Object
Returns the value of attribute cross_origin_rendering.
100 101 102 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 100 def cross_origin_rendering @cross_origin_rendering end |
#driver ⇒ Object
Returns the value of attribute driver.
100 101 102 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 100 def driver @driver end |
#script ⇒ Object
Returns the value of attribute script.
100 101 102 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 100 def script @script end |
#should_skip_failed_frames ⇒ Object
Returns the value of attribute should_skip_failed_frames.
98 99 100 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 98 def should_skip_failed_frames @should_skip_failed_frames end |
#use_cookies ⇒ Object
Returns the value of attribute use_cookies.
100 101 102 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 100 def @use_cookies end |
Instance Method Details
#create_cross_frames_dom_snapshots ⇒ Object
110 111 112 113 114 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 110 def create_cross_frames_dom_snapshots dom = create_dom_snapshot_threaded process_dom_snapshot_frames dom dom end |
#create_dom_snapshot_threaded ⇒ Object
116 117 118 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 116 def create_dom_snapshot_threaded script.run end |
#process_dom_snapshot_frames(dom) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 120 def process_dom_snapshot_frames dom dom["cookies"] = driver.manage. if dom["frames"].each do |frame| selector = frame['selector'] unless selector Applitools::EyesLogger.warn "inner frame with null selector" next end begin original_frame_chain = driver.frame_chain frame_element = driver.find_element(:css, selector) frame_src = frame_element.attribute('src') Applitools::EyesLogger.info "process_dom_snapshot_frames src = #{frame_src}" driver.switch_to.frame(frame_element) process_dom_snapshot_frames frame driver.switch_to.default_content unless original_frame_chain.empty? driver.switch_to.frames frame_chain: original_frame_chain end rescue StandardError => e Applitools::EyesLogger.error e.class.to_s Applitools::EyesLogger.error e. if should_skip_failed_frames Applitools::EyesLogger.warn "failed switching to frame #{selector}" else raise ::Applitools::EyesError.new 'failed switching to frame' end end end self.snapshot_and_process_cors_frames(dom) if self.cross_origin_rendering end |
#snapshot_and_process_cors_frames(dom) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/applitools/selenium/visual_grid/dom_snapshot_script.rb', line 156 def snapshot_and_process_cors_frames(dom) dom["crossFrames"].each do |frame| selector = frame['selector'] unless selector Applitools::EyesLogger.warn "cross frame with null selector" next end frame_index = frame['index'] begin original_frame_chain = driver.frame_chain frame_element = driver.find_element(:css, selector) # frame_src = frame_element.attribute('src') Applitools::EyesLogger.info "snapshot_and_process_cors_frames src = #{frame_src}" driver.switch_to.frame(frame_element) frame_dom = create_cross_frames_dom_snapshots dom['frames'] ||= [] dom['frames'].push frame_dom frame_url = frame_dom['url'] dom['cdt'][frame_index]['attributes'].push({ 'name' => 'data-applitools-src', 'value' => frame_url }) Applitools::EyesLogger.info "Created cross origin frame snapshot #{frame_url}" process_dom_snapshot_frames frame_dom driver.switch_to.default_content unless original_frame_chain.empty? driver.switch_to.frames(frame_chain: original_frame_chain) end rescue StandardError => e Applitools::EyesLogger.error e.class.to_s Applitools::EyesLogger.error e. if should_skip_failed_frames Applitools::EyesLogger.warn "failed extracting and processing cross frame #{selector}" else raise ::Applitools::EyesError.new 'failed switching to frame' end end end end |