Created
September 19, 2011 04:41
-
-
Save gordonbanderson/1225970 to your computer and use it in GitHub Desktop.
Pass in a host and a file containing URLs for that host. Screenshtos will then be created
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'capybara' | |
require 'capybara/dsl' | |
require 'yaml' | |
host = ARGV[0] | |
urlsFile = ARGV[1] | |
Capybara.run_server = false | |
Capybara.current_driver = :selenium | |
Capybara.app_host = 'http://www.google.com' | |
module MyCapybaraTest | |
class Test | |
include Capybara::DSL | |
def test_google | |
session = Capybara::Session.new(:selenium, 'google') | |
#Uncomment this to see in Chrome | |
session.driver.browser.save_screenshot('home.png') | |
end | |
def show_urls(host, urlsFile) | |
file = File.new(urlsFile, "r"); | |
session = Capybara::Session.new(:selenium, 'google') | |
diver = session.driver | |
while (line = file.gets) | |
next if line.strip == '' | |
url = host+line | |
puts "URL:"+url | |
parts = line.split('/') | |
filename = parts.pop | |
filename.strip! | |
if filename == '' | |
puts "\tPopping again" | |
filename = parts.pop | |
end | |
if filename == nil | |
filename = 'home' | |
end | |
filename = filename + ".png" | |
puts "F:*"+filename+'*' | |
puts parts.to_yaml | |
session.visit(url) | |
dirPath = './screenshots/'+parts.join('/') | |
puts "Making dirpath "+dirPath | |
cmd = 'mkdir -p '+dirPath | |
puts "CMD:"+cmd | |
`#{cmd}` | |
savepath = dirPath+'/'+filename | |
savepath.gsub!('//','/') | |
puts "SAVING TO :"+savepath | |
session.driver.browser.save_screenshot(savepath) | |
end | |
end | |
end | |
end | |
t = MyCapybaraTest::Test.new | |
t.show_urls(host, urlsFile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment