-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Playwright examples to the documentation (#164)
* added playwright examples * removed incorrect comment * corrections to RabbitAI's comment
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,33 @@ cy.forceLogin() | |
cy.forceLogin({redirect_to: '/profile'}) | ||
cy.forceLogin({email: '[email protected]'}) | ||
``` | ||
|
||
In `playwright/support/on-rails.js`: | ||
|
||
```js | ||
async function forceLogin(page, { email, redirect_to = '/' }) { | ||
// Validate inputs | ||
if (typeof email !== 'string' || typeof redirect_to !== 'string') { | ||
throw new Error('Invalid input: email and redirect_to must be non-empty strings'); | ||
} | ||
|
||
const response = await page.request.post('/__e2e__/force_login', { | ||
data: { email: email, redirect_to: redirect_to }, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
|
||
// Handle response based on status code | ||
if (response.ok()) { | ||
await page.goto(redirect_to); | ||
} else { | ||
// Throw an exception for specific error statuses | ||
throw new Error(`Login failed with status: ${response.status()}`); | ||
} | ||
} | ||
``` | ||
|
||
Examples of usage in Playwright specs: | ||
```js | ||
await forceLogin(page, { email: '[email protected]', redirect_to: '/profile' }); | ||
|
||
``` |
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