Last active
August 29, 2015 14:20
-
-
Save horike37/2de7cc5f364335b9afa8 to your computer and use it in GitHub Desktop.
トップ、アーカイブ、シングルのPCとSPの表示確認とキャプチャを取得するSelenium Webdriverのコード
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
var webdriver = require('selenium-webdriver'); | |
var t = require('selenium-webdriver/testing'); | |
var driver; | |
var By = webdriver.By; | |
var until = require('selenium-webdriver').until; | |
var setting = require('./setting.json'); | |
var fs = require('fs'); | |
var expect = require('expect.js'); | |
var timestamp = Math.floor( new Date().getTime() / 1000 ); | |
webdriver.WebDriver.prototype.saveScreenshot = function(filename) { | |
filename = filename.replace('|' , '_'); | |
return driver.takeScreenshot(). | |
then(function(data) { | |
fs.writeFile ( | |
filename, | |
data.replace(/^data:image\/png;base64,/,''), | |
'base64', | |
function(error) { | |
if(error) throw error; | |
} | |
); | |
}); | |
}; | |
t.describe('PC', function() { | |
t.before(function() { | |
driver = new webdriver.Builder(). | |
usingServer('http://localhost:4444/wd/hub'). | |
withCapabilities(webdriver.Capabilities.firefox()). | |
build(); | |
}); | |
t.after(function() { | |
driver.quit(); | |
}); | |
t.it('トップ', function() { | |
driver.get(setting.pagelist.top+'?'+timestamp).then(function(){ | |
driver.sleep(1000); | |
driver.saveScreenshot( 'pc_top.png' ); | |
}); | |
}); | |
t.it('アーカイブ', function() { | |
driver.get(setting.pagelist.archive+'?'+timestamp).then(function(){ | |
driver.sleep(1000); | |
driver.saveScreenshot( 'pc_archive.png' ); | |
}); | |
}); | |
t.it('シングル', function() { | |
driver.get(setting.pagelist.single+'?'+timestamp).then(function(){ | |
driver.sleep(1000); | |
driver.saveScreenshot( 'pc_single.png' ); | |
}); | |
}); | |
}); | |
t.describe('SP', function() { | |
t.before(function() { | |
var firefox = require('selenium-webdriver/firefox'); | |
var profile = new firefox.Profile(); | |
profile.setPreference('general.useragent.override', 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X)'); | |
var options = new firefox.Options().setProfile(profile); | |
driver = new webdriver.Builder(). | |
forBrowser('firefox'). | |
usingServer('http://localhost:4444/wd/hub'). | |
setFirefoxOptions(options). | |
build(); | |
}); | |
t.after(function() { | |
driver.quit(); | |
}); | |
t.it('トップ', function() { | |
driver.get(setting.pagelist.top+'?'+timestamp).then(function(){ | |
driver.sleep(1000); | |
driver.saveScreenshot( 'sp_top.png' ); | |
}); | |
}); | |
t.it('アーカイブ', function() { | |
driver.get(setting.pagelist.archive+'?'+timestamp).then(function(){ | |
driver.sleep(1000); | |
driver.saveScreenshot( 'sp_archive.png' ); | |
}); | |
}); | |
t.it('シングル', function() { | |
driver.get(setting.pagelist.single+'?'+timestamp).then(function(){ | |
driver.sleep(1000); | |
driver.saveScreenshot( 'sp_single.png' ); | |
}); | |
}); | |
}); |
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
{ | |
"pagelist":{ | |
"top":"http://example.com/", | |
"archive":"http://example.com/archives/category/menlab", | |
"single":"http://example.com/archives/176208" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment