2
のAVAを使用してpage.js)
const phantom = require('phantom');
/**
* Loads a page using a Promise and jsdom
* @param {string} url The page to be loaded
*/
export default function loadPage(url, callback, thenCallback) {
return new Promise(async (resolve, reject) => {
const instance = await phantom.create();
const page = await instance.createPage();
const status = await page.open('https://webslides.tv/');
if(status != 'success') reject('Error loading '+url);
await page
.evaluate(callback)
.then(await thenCallback);
await instance.exit();
resolve(true);
});
}
もう一つはテストです:
import test from 'ava';
import loadPage from '../helpers/load-page';
test('prueba', async t => {
const check = count => {
t.is(count.childNodes.length, 9);
}
await loadPage('http://webslides.tv',() => {
const ws = document.querySelector('#webslides');
return ws;
}, async (count) => {
await check(count);
});
});
は、ページがロードされた後にテストを実行することが可能ですか?同じページで複数のテストを実行したいが、毎回そのページをロードしたくない。
ありがとうございました