add: Add more methods to browser util

This commit is contained in:
Atinux 2017-11-02 17:47:50 +01:00
parent a2cc3afe60
commit 297b1a1434

View File

@ -22,6 +22,8 @@ export async function page(url) {
page.html = () => page.evaluate(() => window.document.documentElement.outerHTML)
page.$text = (selector) => page.$eval(selector, (el) => el.textContent)
page.$$text = (selector) => page.$$eval(selector, (els) => els.map((el) => el.textContent))
page.$attr = (selector, attr) => page.$eval(selector, (el, attr) => el.getAttribute(attr), attr)
page.$$attr = (selector, attr) => page.$$eval(selector, (els, attr) => els.map((el) => el.getAttribute(attr)), attr)
page.$nuxt = await page.evaluateHandle('window.$nuxt')
page.nuxt = {
@ -42,6 +44,9 @@ export async function page(url) {
loadingData() {
return page.evaluate(($nuxt) => $nuxt.$loading.$data, page.$nuxt)
},
errorData() {
return page.evaluate(($nuxt) => $nuxt.nuxt.err, page.$nuxt)
},
waitForNavigation() {
return page.waitForFunction('window.$nuxt.$loading.$data.show === false')
}