{"id":4453,"date":"2022-02-07T07:00:58","date_gmt":"2022-02-07T07:00:58","guid":{"rendered":"https:\/\/www.diogonunes.com\/blog\/?p=4453"},"modified":"2023-07-16T12:25:41","modified_gmt":"2023-07-16T11:25:41","slug":"playwright-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/","title":{"rendered":"Playwright cheat sheet"},"content":{"rendered":"<figure id=\"attachment_4456\" aria-describedby=\"caption-attachment-4456\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?resize=580%2C387&#038;ssl=1\" alt=\"\" width=\"580\" height=\"387\" class=\"size-large wp-image-4456\" srcset=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?resize=1024%2C683&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?resize=400%2C267&amp;ssl=1 400w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?resize=768%2C512&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?resize=1536%2C1024&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?resize=1200%2C800&amp;ssl=1 1200w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?w=1740&amp;ssl=1 1740w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><figcaption id=\"caption-attachment-4456\" class=\"wp-caption-text\">Photo by <a href=\"https:\/\/unsplash.com\/@impatrickt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Patrick Tomasso<\/a> on <a href=\"https:\/\/unsplash.com\/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Unsplash<\/a><br \/><\/figcaption><\/figure>\n<blockquote>\n<p>\u2b50\ufe0f This post was featured in <a href=\"https:\/\/softwaretestingweekly.com\/issues\/110\">Software Testing Weekly #110<\/a> and <a href=\"https:\/\/www.lambdatest.com\/newsletter\/editions\/issue76\">Coding JAG #76<\/a><\/p>\n<\/blockquote>\n<p>My first experience with Playwright was terrible. However the testing community seems to be loving it, thus I gave it another shot. I started by doing a <a href=\"https:\/\/testautomationu.applitools.com\/js-playwright-tutorial\/\">free course<\/a>, but I don&#8217;t recommend it, it&#8217;s very outdated by now.<\/p>\n<p>I know you loved my <a href=\"https:\/\/www.diogonunes.com\/blog\/cypress-tips-tricks\/\">Cypress recipes post<\/a>, so here&#8217;s a new one for Playwright with up-to-date code snippets on how to implement common automation scenarios.<\/p>\n<p><!--more--><\/p>\n<ul>\n<li><strong>Setup<\/strong>\n<ul>\n<li>Test skeleton (Test version)<\/li>\n<li>Test skeleton (Library version)<\/li>\n<\/ul>\n<\/li>\n<li><strong>Actions<\/strong>\n<ul>\n<li>Visit URL<\/li>\n<li>Select page element<\/li>\n<li>Count selected elements<\/li>\n<li>Type text<\/li>\n<li>Click element<\/li>\n<li>Dropdowns<\/li>\n<li>Checkboxes and Radios<\/li>\n<li>iFrames<\/li>\n<li>Alerts \/ Dialog popups<\/li>\n<li>Check status of element<\/li>\n<\/ul>\n<\/li>\n<li><strong>Assertions<\/strong>\n<ul>\n<li>Check the page title<\/li>\n<li>Check something exists in the page<\/li>\n<\/ul>\n<\/li>\n<li><strong>Miscellaneous<\/strong>\n<ul>\n<li>Take a screenshot<\/li>\n<li>Record a video<\/li>\n<li>Emulate a mobile device<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>\u2699\ufe0f Setup<\/h2>\n<h3>Test skeleton (Test version)<\/h3>\n<pre><code class=\"js\">const { expect, test } = require(\"@playwright\/test\");\n\ntest.describe(\"Google search\", () =&gt; {\n  test(\"is online\", async ({ page }) =&gt; {\n    await page.goto(\"https:\/\/google.com\/\");\n    await expect(page).not.toBeNull();\n  });\n});\n<\/code><\/pre>\n<h3>Test skeleton (Library version)<\/h3>\n<pre><code class=\"js\">const { chromium } = require(\"playwright\");\n\n(async () =&gt; {\n    const browser = await chromium.launch({ headless: false, slowMo: 100 }); \/\/ options\n    const page = await browser.newPage();\n    \/\/ do stuff\n    await browser.close();\n})();\n<\/code><\/pre>\n<h2>\u26a1\ufe0f Actions<\/h2>\n<h3>Visit URL<\/h3>\n<pre><code class=\"js\">await page.goto(\"https:\/\/google.com\");\n<\/code><\/pre>\n<h3>Select page element<\/h3>\n<pre><code class=\"js\">\/\/ locate based on user visible text\nconst emailInput = await page.locator(\"text=Action was successful\");\n\/\/ locate based on CSS selector\nconst emailInput = await page.locator(\"#cssSelector &gt; goes here\");\n<\/code><\/pre>\n<h3>Count selected elements<\/h3>\n<pre><code class=\"js\">const matches = await page.locator(\"#cssSelector &gt; goes here\");\nconst total = matches.count();\nconst firstMatch = matches.first();\nconst thirdMatch = matches.nth(2);  \/\/ index is 0-based\nconst lastMatch = matches.last();\n<\/code><\/pre>\n<h3>Type text<\/h3>\n<pre><code class=\"js\">const emailInput = ...;\nawait emailInput.fill(\"Text to type goes here\");\n\/\/ or inline\nawait page.locator(\"#cssSelector\").fill(\"Fake user will type this\");\n\n\/\/ send keys to the page, regardless what is currently focused\nawait page.keyboard.type(\"pressing some KEYS!\");\n\/\/ send key combinations (e.g. shortcuts)\nawait page.keyboard.press('Ctrl+C');\n\/\/ press and hold a key (e.g. select something)\nawait page.keyboard.down('Shift');\nfor (let i = 0; i &lt; 'KEYS!'.length; i++)\n  await page.keyboard.press('ArrowLeft');\nawait page.keyboard.up('Shift');\n<\/code><\/pre>\n<h3>Click element<\/h3>\n<pre><code class=\"js\">await page.locator(\"#cssSelector\").click();\n<\/code><\/pre>\n<h3>Dropdowns<\/h3>\n<pre><code class=\"js\">await page.selectOption(\"#css\", \"blue\" );                   \/\/ by internal value\nawait page.selectOption(\"#css\", { label: \"Blue ink\" });     \/\/ by visible label\nawait page.selectOption(\"#css\", { index: 1 });              \/\/ by 0-based index\nawait page.selectOption(\"#css\", [\"red\", \"blue\"]);           \/\/ multi select\n<\/code><\/pre>\n<h3>Checkboxes and Radios<\/h3>\n<pre><code class=\"js\">await page.check('#css');\nawait page.uncheck('#css');\nawait page.check('text=XL'); \/\/ check radio\n\nexpect(await page.isChecked('#css')).toBeTruthy(); \/\/ assert state\n<\/code><\/pre>\n<h3>iFrames<\/h3>\n<pre><code class=\"js\">const iframeCheckoutSanddox = \"#checkout-demo\";\nconst sectionPaymentSummary = \"#ProductSummary-totalAmount\";\nconst inputEmail = \"#email\";\n\nawait page.goto(\"https:\/\/checkout.stripe.dev\/preview\");\n\n\/\/ select the iframe\nconst stripeFrame = page.frameLocator(iframeCheckoutSanddox);\nawait expect(stripeFrame).not.toBeNull();\n\n\/\/ assert elements withing the iframe\nawait expect(stripeFrame.locator(sectionPaymentSummary)).toBeVisible();\n\n\/\/ interact with elements withing the iframe\nawait frame.locator(inputEmail).fill(\"someone@gmail.com\");\n<\/code><\/pre>\n<h3>Alerts \/ Dialog popups<\/h3>\n<pre><code class=\"js\">\/* TODO: Update this code, I think it's outdated by now\n  \/\/ code to listen for a dialog popup\n  page.once(\"dialog\", async (dialog) =&gt; {\n      console.log(dialog.message()); \/\/ confirm msg seen by user\n      await dialog.accept(); \/\/ close dialog\n  });\n  \/\/ actually trigger the dialog\n  await page.click(\"#confirmButton\");\n\n  \/\/ using \".once\" instead of \".on\" allows multiple listeners in the same test\n  page.once(\"dialog\", async (dialog) =&gt; {\n      await dialog.accept(\"Hello input!\"); \/\/ to input something in a dialog\n  });\n  await page.click(\"#promptButton\");\n*\/\n<\/code><\/pre>\n<h3>Check status of element<\/h3>\n<pre><code class=\"js\">await page.locator(\"#cssSelector\").isVisible();\n<\/code><\/pre>\n<p>P.S: <a href=\"https:\/\/playwright.dev\/docs\/actionability#assertions\">list with all the assertions available<\/a><\/p>\n<h2>\u2705 Assertions<\/h2>\n<h3>Check the page title<\/h3>\n<pre><code class=\"js\">await expect(page).toHaveTitle(\"The Geeky Gecko - The most amazing blog\");\n<\/code><\/pre>\n<h3>Check something exists in the page<\/h3>\n<pre><code class=\"js\">await expect(page.locator(\"#cssSelector\")).toBeVisible();\n<\/code><\/pre>\n<h2>Miscellaneous<\/h2>\n<h3>Take a screenshot<\/h3>\n<pre><code class=\"js\">await page.screenshot({path: \"path\/to\/generated_file.png\"});          \/\/ page above the fold\nawait page.screenshot({path: \"path\/to\/file.png\", fullPage: true});    \/\/ entire page\nawait page.locator(\"#css\").screenshot({path: \"path\/to\/file.png\"});    \/\/ just an element\n<\/code><\/pre>\n<h3>Record a video<\/h3>\n<p><a href=\"https:\/\/playwright.dev\/docs\/api\/class-video#video-save-as\">Check the official docs<\/a><\/p>\n<h3>Emulate a mobile device<\/h3>\n<ul>\n<li><a href=\"https:\/\/playwright.dev\/docs\/cli#emulate-devices\">Check the official docs<\/a><\/li>\n<li>P.S: <a href=\"https:\/\/github.com\/microsoft\/playwright\/blob\/master\/packages\/playwright-core\/src\/server\/deviceDescriptorsSource.json\">list of supported devices<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u2b50\ufe0f This post was featured in Software Testing Weekly #110 and Coding JAG #76 My first experience with Playwright was terrible. However the testing community seems to be loving it, thus I gave it another shot. I started by doing a free course, but I don&#8217;t recommend it, it&#8217;s very outdated by now. I know [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4456,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[85,55,33],"class_list":["post-4453","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech","tag-playwright","tag-testing","tag-utilities"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Playwright cheat sheet - The Geeky Gecko<\/title>\n<meta name=\"description\" content=\"A list of code snippets and examples to implement common automation scenarios in Playwright\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Playwright cheat sheet - The Geeky Gecko\" \/>\n<meta property=\"og:description\" content=\"A list of code snippets and examples to implement common automation scenarios in Playwright\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\" \/>\n<meta property=\"og:site_name\" content=\"The Geeky Gecko\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-07T07:00:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-16T11:25:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Diogo Nunes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dialexnunes\" \/>\n<meta name=\"twitter:site\" content=\"@dialexnunes\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Diogo Nunes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\"},\"author\":{\"name\":\"Diogo Nunes\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\"},\"headline\":\"Playwright cheat sheet\",\"datePublished\":\"2022-02-07T07:00:58+00:00\",\"dateModified\":\"2023-07-16T11:25:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\"},\"wordCount\":229,\"publisher\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\"},\"image\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1\",\"keywords\":[\"playwright\",\"testing\",\"utilities\"],\"articleSection\":[\"Technology\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\",\"url\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\",\"name\":\"Playwright cheat sheet - The Geeky Gecko\",\"isPartOf\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1\",\"datePublished\":\"2022-02-07T07:00:58+00:00\",\"dateModified\":\"2023-07-16T11:25:41+00:00\",\"description\":\"A list of code snippets and examples to implement common automation scenarios in Playwright\",\"breadcrumb\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1\",\"width\":1920,\"height\":1280},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.diogonunes.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Playwright cheat sheet\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#website\",\"url\":\"https:\/\/www.diogonunes.com\/blog\/\",\"name\":\"The Geeky Gecko\",\"description\":\"The Geeky Gecko\",\"publisher\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.diogonunes.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\",\"name\":\"Diogo Nunes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1\",\"width\":799,\"height\":799,\"caption\":\"Diogo Nunes\"},\"logo\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.diogonunes.com\",\"https:\/\/x.com\/dialexnunes\"],\"url\":\"https:\/\/www.diogonunes.com\/blog\/author\/diogo-nunes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Playwright cheat sheet - The Geeky Gecko","description":"A list of code snippets and examples to implement common automation scenarios in Playwright","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/","og_locale":"en_US","og_type":"article","og_title":"Playwright cheat sheet - The Geeky Gecko","og_description":"A list of code snippets and examples to implement common automation scenarios in Playwright","og_url":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/","og_site_name":"The Geeky Gecko","article_published_time":"2022-02-07T07:00:58+00:00","article_modified_time":"2023-07-16T11:25:41+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg","type":"image\/jpeg"}],"author":"Diogo Nunes","twitter_card":"summary_large_image","twitter_creator":"@dialexnunes","twitter_site":"@dialexnunes","twitter_misc":{"Written by":"Diogo Nunes","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#article","isPartOf":{"@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/"},"author":{"name":"Diogo Nunes","@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c"},"headline":"Playwright cheat sheet","datePublished":"2022-02-07T07:00:58+00:00","dateModified":"2023-07-16T11:25:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/"},"wordCount":229,"publisher":{"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c"},"image":{"@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1","keywords":["playwright","testing","utilities"],"articleSection":["Technology"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/","url":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/","name":"Playwright cheat sheet - The Geeky Gecko","isPartOf":{"@id":"https:\/\/www.diogonunes.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage"},"image":{"@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1","datePublished":"2022-02-07T07:00:58+00:00","dateModified":"2023-07-16T11:25:41+00:00","description":"A list of code snippets and examples to implement common automation scenarios in Playwright","breadcrumb":{"@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#primaryimage","url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1","width":1920,"height":1280},{"@type":"BreadcrumbList","@id":"https:\/\/www.diogonunes.com\/blog\/playwright-cheat-sheet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.diogonunes.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Playwright cheat sheet"}]},{"@type":"WebSite","@id":"https:\/\/www.diogonunes.com\/blog\/#website","url":"https:\/\/www.diogonunes.com\/blog\/","name":"The Geeky Gecko","description":"The Geeky Gecko","publisher":{"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.diogonunes.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c","name":"Diogo Nunes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1","width":799,"height":799,"caption":"Diogo Nunes"},"logo":{"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.diogonunes.com","https:\/\/x.com\/dialexnunes"],"url":"https:\/\/www.diogonunes.com\/blog\/author\/diogo-nunes\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/11\/patrick-tomasso-Oaqk7qqNh_c-unsplash.jpg?fit=1920%2C1280&ssl=1","jetpack-related-posts":[{"id":4204,"url":"https:\/\/www.diogonunes.com\/blog\/framework-review-playwright\/","url_meta":{"origin":4453,"position":0},"title":"Framework review: Playwright","author":"Diogo Nunes","date":"29 March, 2021","format":false,"excerpt":"Playwright enables end-to-end testing. Test modern single page apps, across all modern browsers, using in your preferred language (JS, TS, Java, C#, Python). \u2014 Official website Code Example of automation at GitHub. Use cases \ud83e\udd48 Automate end-to-end (E2E) tests using the UI. It also supports mocks. Learning curve \ud83e\udd48 Most\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":2566,"url":"https:\/\/www.diogonunes.com\/blog\/cross-browser-testing-tuttu-testing-through-ui\/","url_meta":{"origin":4453,"position":1},"title":"Before doing cross-browser testing ask yourself: are you TuTTu?","author":"Diogo Nunes","date":"18 July, 2016","format":false,"excerpt":"Recently I had the requirement to test the behavior of a web application on Chrome, Firefox... and the dreaded Internet Explorer. The team already had automated end-to-end test written in Java using Selenium web driver. We decided to explore the world of automated cross-browser testing and we were recommended BrowserStack\u2026","rel":"","context":"In &quot;Work&quot;","block_context":{"text":"Work","link":"https:\/\/www.diogonunes.com\/blog\/category\/work\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2016\/07\/cross-browser-header.png?fit=1200%2C646&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2016\/07\/cross-browser-header.png?fit=1200%2C646&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2016\/07\/cross-browser-header.png?fit=1200%2C646&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2016\/07\/cross-browser-header.png?fit=1200%2C646&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2016\/07\/cross-browser-header.png?fit=1200%2C646&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4351,"url":"https:\/\/www.diogonunes.com\/blog\/testing-concepts-2\/","url_meta":{"origin":4453,"position":2},"title":"Testing is\u2026 (Concepts #2)","author":"Diogo Nunes","date":"18 October, 2021","format":false,"excerpt":"This is part of my free testing course, focused on teaching you the fundamentals of testing \ud83d\ude09 \ud83d\udd0e Investigation Testing uncovers information that enables better decisions. Noticing what everyone looks but no one sees. Looking for what is inconsistent or counter intuitive. Finding problems before they happen or become critical.\u2026","rel":"","context":"In &quot;Work&quot;","block_context":{"text":"Work","link":"https:\/\/www.diogonunes.com\/blog\/category\/work\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/holly-mandarich-UVyOfX3v0Ls-unsplash.jpg?fit=1200%2C798&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/holly-mandarich-UVyOfX3v0Ls-unsplash.jpg?fit=1200%2C798&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/holly-mandarich-UVyOfX3v0Ls-unsplash.jpg?fit=1200%2C798&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/holly-mandarich-UVyOfX3v0Ls-unsplash.jpg?fit=1200%2C798&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/holly-mandarich-UVyOfX3v0Ls-unsplash.jpg?fit=1200%2C798&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4352,"url":"https:\/\/www.diogonunes.com\/blog\/testing-concepts-3\/","url_meta":{"origin":4453,"position":3},"title":"Testing is not just\u2026 (Concepts #3)","author":"Diogo Nunes","date":"25 October, 2021","format":false,"excerpt":"\ud83c\udfc6 This post was featured in Software Testing Weekly #95 and Coding JAG #60 This is part of my free testing course, focused on teaching you the fundamentals of testing \ud83d\ude09 \ud83e\udd16 Automation Much of what we find as testers comes off-script and high-value unknowns are found by letting humans\u2026","rel":"","context":"In &quot;Work&quot;","block_context":{"text":"Work","link":"https:\/\/www.diogonunes.com\/blog\/category\/work\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/lenny-kuhne-jHZ70nRk7Ns-unsplash.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/lenny-kuhne-jHZ70nRk7Ns-unsplash.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/lenny-kuhne-jHZ70nRk7Ns-unsplash.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/lenny-kuhne-jHZ70nRk7Ns-unsplash.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/lenny-kuhne-jHZ70nRk7Ns-unsplash.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4328,"url":"https:\/\/www.diogonunes.com\/blog\/testing-concepts-1\/","url_meta":{"origin":4453,"position":4},"title":"Testing&#8217;s purpose (Concepts #1)","author":"Diogo Nunes","date":"11 October, 2021","format":false,"excerpt":"tl;dr Testing\u2019s purpose is to measure and maximise quality delivered, while minimising risk to an acceptable level. This post is part of my free testing course, focused on teaching you the fundamentals of testing. Until the end of the year, expect a new blog post every Monday. :) Theory Are\u2026","rel":"","context":"In &quot;Work&quot;","block_context":{"text":"Work","link":"https:\/\/www.diogonunes.com\/blog\/category\/work\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/fallon-michael-VUWDlBXGogg-unsplash.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/fallon-michael-VUWDlBXGogg-unsplash.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/fallon-michael-VUWDlBXGogg-unsplash.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/fallon-michael-VUWDlBXGogg-unsplash.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/10\/fallon-michael-VUWDlBXGogg-unsplash.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":2536,"url":"https:\/\/www.diogonunes.com\/blog\/four-testing-quadrants\/","url_meta":{"origin":4453,"position":5},"title":"Testing for agile teams: The four testing quadrants (#3)","author":"Diogo Nunes","date":"16 January, 2017","format":false,"excerpt":"This post is part of the \"Testing for Agile Teams\" series. We do different types of testing to accomplish different goals. Your team has its own unique context. It's a tool, not a rule. Tests that support the team Supports the team as it develops the product: Drives development to\u2026","rel":"","context":"In &quot;Work&quot;","block_context":{"text":"Work","link":"https:\/\/www.diogonunes.com\/blog\/category\/work\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2016\/03\/Agile-Testing-Book-Part-4.jpg?fit=489%2C340&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts\/4453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/comments?post=4453"}],"version-history":[{"count":3,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts\/4453\/revisions"}],"predecessor-version":[{"id":4467,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts\/4453\/revisions\/4467"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/media\/4456"}],"wp:attachment":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/media?parent=4453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/categories?post=4453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/tags?post=4453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}