2
我試圖運行使用AVA和PhantomJS(實際上phantomjs節點)使用AVA與PhantomJS
我必須在文件的網頁一些測試,第一個是加載使用幻影網頁模塊(負載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);
});
});
是否有可能一旦頁面已經被加載運行測試?我想用同一頁面運行多個測試,但我不想每次都加載頁面。
謝謝