Created
September 20, 2018 02:53
-
-
Save deguchi/6b98f73a42cb4fadb32728dbc71b4ca7 to your computer and use it in GitHub Desktop.
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
const devices = require('puppeteer/DeviceDescriptors'); | |
let fetch = require('node-fetch'); | |
let FormData = require('form-data'); | |
let fs = require('fs'); | |
let opener = require('opener'); | |
it('スマートフォン版のスクリーンショットを撮影', async function () { | |
this.timeout(20000); | |
await page.emulate(devices['iPhone 6']); | |
await page.screenshot({ | |
path: 'iphone6.png', | |
fullPage: true | |
}); | |
// yabumiにアップロード | |
const formData = new FormData(); | |
formData.append('imagedata', fs.createReadStream('iphone6.png')); | |
await fetch('https://yabumi.cc/api/images.json', { | |
method: 'POST', | |
body: formData | |
}) | |
.then(function (res) { | |
return res.json(); | |
}).then(async function (json) { | |
console.log(json); | |
if (json.url) { | |
await opener(json.url); | |
} | |
fs.unlinkSync('iphone6.png'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment