Skip to content

Commit

Permalink
just await
Browse files Browse the repository at this point in the history
  • Loading branch information
seren5240 committed Apr 13, 2024
1 parent e58ff84 commit 2e4eb12
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion .grit/patterns/js/cypress_to_playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ pattern convert_cypress_queries() {
`cy.wait($timeout)` => `await page.waitForTimeout($timeout)`,
`$locator.find($inner)` => `$locator.locator($inner)`,
`$locator.eq($n)` => `$locator.nth($n)`,
`$locator.click()` => `await $locator.click()`,
`$locator.click($opts)` => `await $locator.click($opts)`,
`$locator.text()` => `await $locator.textContent()`,
`Cypress.env('$var')` => `process.env.$var`,
`cy.onlyOn($var === $cond)` => `if ($var !== $cond) {
test.skip();
Expand Down Expand Up @@ -198,3 +199,34 @@ test.describe('Grouping', function () {
});
});
```

## Converts complex queries

```js
describe('Grouping', function () {
it('my test', async () => {
cy.get('.header').find('.button').eq(1).click({ force: true });
cy.get('.sidebar').contains('Files').click();
cy.get('.header').find('.button').eq(1).should('have.attr', 'disabled');
cy.get('.button').each((button) => {
expect(button.text()).to.eql('Submit');
});
});
});
```

```ts
import { expect, test } from '@playwright/test';

test.describe('Grouping', function () {
test('my test', async ({ page, request }) => {
await page.locator('.header').locator('.button').nth(1).click({ force: true });
await page.locator('.sidebar', { hasText: 'Files' }).click();
await expect(page.locator('.header').locator('.button').nth(1)).toHaveAttribute('disabled');
const buttons = await page.locator('.button').all();
for (const button of buttons) {
expect(await button.textContent()).toEqual('Submit');
}
});
});
```

0 comments on commit 2e4eb12

Please sign in to comment.