Created
December 16, 2022 15:23
-
-
Save ahobson/91df90560dc4e1ca7ab156d3c7642f3e to your computer and use it in GitHub Desktop.
cypress to playwright helper script
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
#!/usr/bin/env ruby | |
# using ruby since it is already installed on macOS | |
if ARGV.length != 1 | |
STDERR.puts "Usage: #{$0} cypress_test_file.js" | |
exit(2) | |
end | |
File.readlines(ARGV[0]).each do |line| | |
print( | |
line. | |
gsub(/describe\((.*),.*/, | |
'test.describe(\1, () => {'). | |
gsub(/it\((.*),.*/, | |
'test(\1, async ({page}) => {'). | |
gsub('cy.get(', | |
'await page.locator('). | |
gsub(/cy.contains(.*);/, | |
'await expect(page.getByText\1).toBeVisible();'). | |
gsub(/await (page.locator.*).should\('be.disabled'\)/, | |
'await expect(\1).toBeDisabled()'). | |
gsub(/await (page.locator.*).should\('be.enabled'\)/, | |
'await expect(\1).toBeEnabled()'). | |
gsub(/\.clear\(\)\.type/, | |
'.type'). | |
gsub(/await (page.locator.*).type\((.*)\).blur\(\)/, | |
'await \1.type(\2); await \1.blur()'). | |
gsub(/await (page.locator.*).should('be.empty')/, | |
'await expect(\1).toBeEmpty()'). | |
gsub(/\.select\(([^)]*)\)/, | |
'.selectOption({ label: \1})'). | |
gsub(/await (page.locator.*).contains\((.*)\)/, | |
'await expect(\1).toContainText(\2)') | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment