lib/percy/capybara/loaders/base_loader.rb in percy-capybara-2.2.1 vs lib/percy/capybara/loaders/base_loader.rb in percy-capybara-2.3.0.pre.beta

- old
+ new

@@ -68,9 +68,39 @@ # "about:srcdoc" iframe srcdoc pages. current_url = "/#{current_url}" if current_url[0] != '/' current_url end + + # NOTES: + # - Doesn't handle multiple iframes with the same URL (`src` attribute) + # @private + def iframes_resources + resources = [] + + page.all(:css, 'iframe').each do |iframe_element| + iframe_url = iframe_element[:src] + root_page_host = page.current_host + + page.within_frame(iframe_element) do + next unless page.current_host == root_page_host + path = URI.parse(iframe_url).path + content = page.body + sha = Digest::SHA256.hexdigest(content) + resources << + Percy::Client::Resource.new( + path, + content: content, + sha: sha, + mimetype: 'text/html' + ) + end + end + + resources + rescue ::Capybara::NotSupportedByDriverError + [] + end end end end end