Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ test.describe('Test deployment', () => {

If your LTI tool requires the user to grant access, you must call `grantAccessIfNeeded` in your tests. This is no longer handled during authentication setup.

### Optional: Skip page navigation in `grantAccessIfNeeded`

If `toolUrl` is provided, `grantAccessIfNeeded` navigates to it. If your test has already navigated to the tool, omit `toolUrl` to skip the navigation step:

```javascript
// Already at the tool URL
await page.goto(TEST_URL)
// Check for grant access flow without re-navigating
await grantAccessIfNeeded(page, context)
```

### Optional: Register a cookie-dialog handler once per test

If your environment shows the OneTrust cookie dialog unpredictably, register a locator handler in test setup so it is auto-accepted whenever it appears:

```javascript
import { registerCookieDialogHandler } from '@oxctl/deployment-test-utils'

test.beforeEach(async ({ page }) => {
await registerCookieDialogHandler(page)
})
```

## Recommended npm scripts

```json
Expand Down
24 changes: 21 additions & 3 deletions src/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export const TEST_URL = buildTestUrl(
*
* @param {import('@playwright/test').Page} page - Playwright page instance
* @param {import('@playwright/test').BrowserContext} context - Playwright browser context
* @param {string} toolUrl - URL of the LTI tool to visit
* @param {string} [toolUrl] - Optional URL of the LTI tool to visit
* @returns {Promise<void>}
*/
export const grantAccessIfNeeded = async (page, context, toolUrl) => {
await page.goto(toolUrl)
if (toolUrl) {
await page.goto(toolUrl)
}
const ltiToolFrame = getLtiIFrame(page)

// wait for tool-support loading page
Expand Down Expand Up @@ -126,4 +128,20 @@ function normalizeUrlParts(host, path) {
function buildTestUrl(host, path) {
const { host: normalizedHost, path: normalizedPath } = normalizeUrlParts(host, path)
return `${normalizedHost}/${normalizedPath}`
}
}

/**
* Register a Playwright locator handler that accepts the OneTrust cookie dialog
* whenever it appears on the page.
*
* Call this once per test/page in consumer setup (for example in `beforeEach`).
*
* @param {import('@playwright/test').Page} page - Playwright page
* @returns {Promise<void>}
*/
Comment on lines +133 to +141

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would be better handled by https://playwright.dev/docs/api/class-page#page-add-locator-handler which allows us to just accept the dialog if it ever appears and not explicitly wait for it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the case for the beta banner as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so, not essential, I was just commenting because it was new code.

export const registerCookieDialogHandler = async (page) => {
const dialog = page.getByRole('dialog', { name: 'Cookie Settings' })
await page.addLocatorHandler(dialog, async () => {
await dialog.getByRole('button', { name: 'Accept' }).first().click()
})
}