-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move puppeteer inject helper out of createTest
- Loading branch information
Showing
4 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
import { injectRumWithPuppeteer } from '../../lib/framework' | ||
import { RUM_BUNDLE } from '../../lib/framework/sdkBuilds' | ||
import { APPLICATION_ID, CLIENT_TOKEN } from '../../lib/helpers/configuration' | ||
import * as fs from 'fs' | ||
|
||
describe('Inject RUM with Puppeteer', () => { | ||
// S8s tests inject RUM with puppeteer evaluateOnNewDocument | ||
it('should not throw error in chrome', async () => { | ||
const isInjected = await injectRumWithPuppeteer() | ||
expect(isInjected).toBe(true) | ||
}) | ||
}) | ||
|
||
async function injectRumWithPuppeteer() { | ||
const ddRUM = fs.readFileSync(RUM_BUNDLE, 'utf8') | ||
const puppeteerBrowser = await browser.getPuppeteer() | ||
let injected = true | ||
|
||
await browser.call(async () => { | ||
const page = await puppeteerBrowser.newPage() | ||
await page.evaluateOnNewDocument( | ||
` | ||
if (location.href !== 'about:blank') { | ||
${ddRUM} | ||
window.DD_RUM._setDebug(true) | ||
window.DD_RUM.init({ | ||
applicationId: ${APPLICATION_ID}, | ||
clientToken: ${CLIENT_TOKEN}, | ||
}) | ||
window.DD_RUM.startView() | ||
} | ||
` | ||
) | ||
page.on('console', (msg) => { | ||
if (msg.type() === 'error') { | ||
injected = false | ||
} | ||
}) | ||
await page.goto('https://webdriver.io') | ||
}) | ||
return injected | ||
} |