javascript
1コード 2```const should = require('should'); 3const webdriverio = require('webdriverio'); 4const fs = require('fs'); 5 6const config = {}; 7config.url = 'http://hoge:hogepass@xxx.xxx.xxx/xxx/'; 8config.outdir = 'ss';//pass? 9 10let client; 11//スクリーンショット関数? 12function joinOutputPath(str) { 13 return `${config.outdir}/${str}.png`; 14} 15 16// Creates output dir for screenshot if NOT exists 17if (!fs.existsSync(config.outdir)) { 18 fs.mkdirSync(config.outdir); 19} 20 21module.exports = function () { 22 describe('Sample001', () => { 23 before(function (done) { 24 this.timeout(30000); 25 client = webdriverio 26 .remote({ desiredCapabilities: { browserName: 'safari' } }) 27 .init().url(config.url).call(done); 28 //スクリーンショットエラー 29 process.on('uncaughtException', (err) => { 30 const date = new Date().toLocaleString().replace(/\s|//g, '-').replace(/:/g, ''); 31 console.log(` ScrrenShot: error${date}.png`); 32 client.saveScreenshot(joinOutputPath(`error${date}`)); 33 }); 34 }); 35 after(function (done) { 36 this.timeout(50000); 37 client.end().call(done); 38 }); 39 describe('[Sample-001] Google Top Page', () => { 40 it('is OK', function (done) { 41 this.timeout(30000); 42 client 43 .saveScreenshot(joinOutputPath('sampleSS1')) 44 .call(done); 45 }); 46 }); 47 describe('[Sample-002] Input Search Word', () => { 48 it('is OK', function (done) { 49 this.timeout(30000); 50 client 51 .setValue('input#lst-ib', 'Selenium') 52 .saveScreenshot(joinOutputPath('sampleSS2')) 53 .call(done); 54 }); 55 }); 56 describe('[Sample-003] Search Result', () => { 57 it('is OK', function (done) { 58 this.timeout(30000); 59 client 60 .keys('\uE007') 61 .pause(1000) 62 .saveScreenshot(joinOutputPath('sampleSS3')) 63 .call(done); 64 }); 65 }); 66 }); 67};
あなたの回答
tips
プレビュー