MCPcopy
hub / github.com/codeceptjs/CodeceptJS / amOnPage

Method amOnPage

lib/helper/Puppeteer.js:743–784  ·  view source on GitHub ↗

* {{> amOnPage }}

(url)

Source from the content-addressed store, hash-verified

741 * {{> amOnPage }}
742 */
743 async amOnPage(url) {
744 if (!/^\w+\:\/\//.test(url)) {
745 url = this.options.url + url
746 }
747
748 if (this.options.basicAuth && this.isAuthenticated !== true) {
749 if (url.includes(this.options.url)) {
750 await this.page.authenticate(this.options.basicAuth)
751 this.isAuthenticated = true
752 }
753 }
754
755 if (this.options.trace) {
756 const fileName = `${`${store.outputDir}${path.sep}trace${path.sep}${uuidv4()}_${clearString(this.currentRunningTest.title)}`.slice(0, 245)}.json`
757 const dir = path.dirname(fileName)
758 if (!fileExists(dir)) fs.mkdirSync(dir)
759 await this.page.tracing.start({ screenshots: true, path: fileName })
760 this.currentRunningTest.artifacts.trace = fileName
761 }
762
763 try {
764 await this.page.goto(url, { waitUntil: this.options.waitForNavigation })
765 } catch (err) {
766 // Handle terminal navigation errors that shouldn't be retried
767 if (
768 err.message &&
769 (err.message.includes('ERR_ABORTED') || err.message.includes('frame was detached') || err.message.includes('Target page, context or browser has been closed') || err.message.includes('Navigation timeout'))
770 ) {
771 // Mark this as a terminal error to prevent retries
772 const terminalError = new Error(err.message)
773 terminalError.isTerminal = true
774 throw terminalError
775 }
776 throw err
777 }
778
779 const performanceTiming = JSON.parse(await this.page.evaluate(() => JSON.stringify(window.performance.timing)))
780
781 perfTiming = this._extractDataFromPerformanceTiming(performanceTiming, 'responseEnd', 'domInteractive', 'domContentLoadedEventEnd', 'loadEventEnd')
782
783 return this._waitForAction()
784 }
785
786 /**
787 *

Callers 15

auth.jsFile · 0.45
interactive.jsFile · 0.45
AppiumWeb_test.jsFile · 0.45
Playwright_test.jsFile · 0.45
WebDriver_test.jsFile · 0.45
Puppeteer_test.jsFile · 0.45
testsFunction · 0.45
openFunction · 0.45
openSiblingPageFunction · 0.45
config_test.jsFile · 0.45
retryTo_test.jsFile · 0.45

Calls 7

_waitForActionMethod · 0.95
clearStringFunction · 0.90
fileExistsFunction · 0.90
includesMethod · 0.80
evaluateMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected