From 50dcf21345fc257853cf7f002c1fb98b871b1ed0 Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Fri, 12 Apr 2024 18:09:19 -0700 Subject: [PATCH 1/6] things --- .grit/patterns/js/cypress_to_playwright.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.grit/patterns/js/cypress_to_playwright.md b/.grit/patterns/js/cypress_to_playwright.md index 765a41a9..c94c9a19 100644 --- a/.grit/patterns/js/cypress_to_playwright.md +++ b/.grit/patterns/js/cypress_to_playwright.md @@ -13,10 +13,17 @@ pattern convert_cypress_assertions() { or { `expect($arg).to.not.be.null` => `expect($arg).not.toBeNull()`, `expect($arg).to.not.be.undefined` => `expect($arg).not.toBeUndefined()`, + `expect($arg).to.include($item)` => `expect($arg).toContain($item)`, + `expect($arg).to.eql($item)` => `expect($arg).toEqual($item)`, `$locator.should($cond1, $cond2)` as $should where { $pw_cond = "", - $cond1 <: `'contain'` where { - $pw_cond += `toContainText($cond2)`, + $cond1 <: or { + `'contain'` where { + $pw_cond += `toContainText($cond2)`, + }, + `'have.attr'` where { + $pw_cond += `toHaveAttribute($cond2)`, + }, }, $should => `await expect($locator).$pw_cond`, }, @@ -35,9 +42,11 @@ pattern convert_cypress_queries() { `cy.visit($loc)` => `await page.goto($loc)`, `cy.get($locator)` => `page.locator($locator)`, `cy.contains($text, $options)` => `await expect(page.getByText($text)).toBeVisible($options)`, + `cy.get($locator).contains($text).$action()` => `await page.locator($locator, { hasText: $text }).click()`, `cy.contains($text)` => `await expect(page.getByText($text)).toBeVisible()`, `cy.log($log)` => `console.log($log)`, `cy.wait($timeout)` => `await page.waitForTimeout($timeout)`, + `$locator.eq($n)` => `$locator.nth($n)`, `Cypress.env('$var')` => `process.env.$var`, `cy.onlyOn($var === $cond)` => `if ($var !== $cond) { test.skip(); From 35371773e7d3d47892290925f6b885aed421641f Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Fri, 12 Apr 2024 18:13:45 -0700 Subject: [PATCH 2/6] more --- .grit/patterns/js/cypress_to_playwright.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.grit/patterns/js/cypress_to_playwright.md b/.grit/patterns/js/cypress_to_playwright.md index c94c9a19..acdee725 100644 --- a/.grit/patterns/js/cypress_to_playwright.md +++ b/.grit/patterns/js/cypress_to_playwright.md @@ -46,7 +46,9 @@ pattern convert_cypress_queries() { `cy.contains($text)` => `await expect(page.getByText($text)).toBeVisible()`, `cy.log($log)` => `console.log($log)`, `cy.wait($timeout)` => `await page.waitForTimeout($timeout)`, + `$locator.find($inner)` => `$locator.locator($inner)`, `$locator.eq($n)` => `$locator.nth($n)`, + `$locator.click()` => `await $locator.click()`, `Cypress.env('$var')` => `process.env.$var`, `cy.onlyOn($var === $cond)` => `if ($var !== $cond) { test.skip(); From e58ff84d7831ad5a261118db2bab0b8dead58c3f Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Fri, 12 Apr 2024 18:20:58 -0700 Subject: [PATCH 3/6] on --- .grit/patterns/js/cypress_to_playwright.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.grit/patterns/js/cypress_to_playwright.md b/.grit/patterns/js/cypress_to_playwright.md index acdee725..d276e716 100644 --- a/.grit/patterns/js/cypress_to_playwright.md +++ b/.grit/patterns/js/cypress_to_playwright.md @@ -42,7 +42,8 @@ pattern convert_cypress_queries() { `cy.visit($loc)` => `await page.goto($loc)`, `cy.get($locator)` => `page.locator($locator)`, `cy.contains($text, $options)` => `await expect(page.getByText($text)).toBeVisible($options)`, - `cy.get($locator).contains($text).$action()` => `await page.locator($locator, { hasText: $text }).click()`, + `cy.get($locator).contains($text).$action()` => `await page.locator($locator, { hasText: $text }).$action()`, + `cy.get($locator).contains($text)` => `page.locator($locator, { hasText: $text })`, `cy.contains($text)` => `await expect(page.getByText($text)).toBeVisible()`, `cy.log($log)` => `console.log($log)`, `cy.wait($timeout)` => `await page.waitForTimeout($timeout)`, @@ -53,6 +54,15 @@ pattern convert_cypress_queries() { `cy.onlyOn($var === $cond)` => `if ($var !== $cond) { test.skip(); }`, + `cy.$_($selector).each(($locator) => { + $body + })` as $loop where { + $var = `$[locator]s`, + $loop => `const $var = await page.locator($selector).all(); +for (const $locator of $var) { + $body +}` + }, `cy.request({ $opts })` as $req where { or { $opts <: contains pair(key=`method`, value=`"$method"`), From 2e4eb12070969558db93bc48f439c7bb04a9fdb6 Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Fri, 12 Apr 2024 18:35:26 -0700 Subject: [PATCH 4/6] just await --- .grit/patterns/js/cypress_to_playwright.md | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.grit/patterns/js/cypress_to_playwright.md b/.grit/patterns/js/cypress_to_playwright.md index d276e716..e2be4835 100644 --- a/.grit/patterns/js/cypress_to_playwright.md +++ b/.grit/patterns/js/cypress_to_playwright.md @@ -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(); @@ -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'); + } + }); +}); +``` From 62e3822cd143d92cb2623c54dbb3f7280d0632c9 Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Fri, 12 Apr 2024 18:35:52 -0700 Subject: [PATCH 5/6] ok --- .grit/patterns/js/cypress_to_playwright.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.grit/patterns/js/cypress_to_playwright.md b/.grit/patterns/js/cypress_to_playwright.md index e2be4835..5eaab91a 100644 --- a/.grit/patterns/js/cypress_to_playwright.md +++ b/.grit/patterns/js/cypress_to_playwright.md @@ -200,7 +200,7 @@ test.describe('Grouping', function () { }); ``` -## Converts complex queries +## Converts composite queries ```js describe('Grouping', function () { From 41a5c9499c3efde9bbb53921c529a66b793eb812 Mon Sep 17 00:00:00 2001 From: Seren Kwok Date: Fri, 12 Apr 2024 18:37:45 -0700 Subject: [PATCH 6/6] let it fly --- .grit/patterns/js/codecept_to_playwright.md | 3 ++- .grit/patterns/js/cypress_to_playwright.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.grit/patterns/js/codecept_to_playwright.md b/.grit/patterns/js/codecept_to_playwright.md index f79bb727..2f280507 100644 --- a/.grit/patterns/js/codecept_to_playwright.md +++ b/.grit/patterns/js/codecept_to_playwright.md @@ -1,5 +1,6 @@ --- title: Convert CodeceptJS to Playwright +tags: [migration] --- Migrate from CodeceptJS to Playwright. @@ -17,7 +18,7 @@ predicate convert_tags($scenario, $description) { $tags += `@$fragment`, }, }, - + $tags = join($tags, ` `), $description => trim(`$description $tags`, " "), } diff --git a/.grit/patterns/js/cypress_to_playwright.md b/.grit/patterns/js/cypress_to_playwright.md index 5eaab91a..ad725552 100644 --- a/.grit/patterns/js/cypress_to_playwright.md +++ b/.grit/patterns/js/cypress_to_playwright.md @@ -1,6 +1,6 @@ --- title: Convert Cypress to Playwright -tags: [hidden] +tags: [migration] --- Migrate from Cypress to Playwright.