Created
June 11, 2013 02:08
-
-
Save daipresents/5754060 to your computer and use it in GitHub Desktop.
GithubのIssuesをバックアップするために、rspec + webdriver でIssueページのキャプチャをとりまくるスクリプトを作ってみた。webdriverの動かし方とかは http://buff.ly/14tt6KI などを参照のこと。
This file contains 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
# coding:utf-8 | |
require 'selenium-webdriver' | |
require 'rspec' | |
include RSpec::Expectations | |
describe "GithubのIssue保存" do | |
before(:each) do | |
@verification_errors = [] | |
@driver = Selenium::WebDriver.for :chrome | |
@driver.manage.timeouts.implicit_wait = 5 | |
end | |
after(:all) do | |
@driver.quit | |
@verification_errors.should == [] | |
end | |
it "Issue保存" do | |
# このへんの設定は各環境に合わせて | |
username = "username" | |
password = "password" | |
issue_page = "https://github.com/daipresents/sample/issues" | |
image_folder = "/Download/images" | |
# ログイン | |
@driver.get("https://github.com/login") | |
@driver.find_element(:xpath, '//*[@id="login_field"]').send_keys username | |
@driver.find_element(:xpath, '//*[@id="password"]').send_keys password | |
@driver.find_element(:xpath, '//*[@id="login"]/form/div[3]/input[3]').click | |
# Issue番号.jpg という名前でキャプチャを取得 | |
# Issueがなくなったら例外で落ちるはず | |
# Issueのタイトルとステータースをログでとっておく | |
no = 1 | |
File.open(image_folder + "/issues.log", 'w'){ | title_file | | |
while true | |
@driver.get(issue_page + "/" + no.to_s) | |
status = @driver.find_element(:xpath, '//*[@id="discussion_bucket"]/div[1]/div[1]/span[1]').text | |
title = @driver.find_element(:xpath, '/html/body/div/div[2]/div/div[2]/div/div[2]/div[2]/div[2]/div/div/div/div/div/div/h2').text | |
title_file.write sprintf("%d,%s,%s\n", no, status, title) | |
@driver.save_screenshot(sprintf("%s/%04d.png", image_folder, no)) | |
exit | |
no += 1 | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment