{"id":13651135,"url":"https://github.com/naqvis/playwright-cr","last_synced_at":"2025-10-24T08:31:10.664Z","repository":{"id":53563506,"uuid":"327092570","full_name":"naqvis/playwright-cr","owner":"naqvis","description":"Crystal version of the Playwright testing and automation library.","archived":false,"fork":false,"pushed_at":"2021-03-24T05:45:54.000Z","size":1729,"stargazers_count":20,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-29T22:56:33.350Z","etag":null,"topics":["crystal","crystal-lang","crystal-shard","playwright"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naqvis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-05T19:01:44.000Z","updated_at":"2024-08-08T04:00:09.000Z","dependencies_parsed_at":"2022-09-10T18:10:12.088Z","dependency_job_id":null,"html_url":"https://github.com/naqvis/playwright-cr","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fplaywright-cr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fplaywright-cr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fplaywright-cr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fplaywright-cr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naqvis","download_url":"https://codeload.github.com/naqvis/playwright-cr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237937786,"owners_count":19390543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crystal","crystal-lang","crystal-shard","playwright"],"created_at":"2024-08-02T02:00:45.593Z","updated_at":"2025-10-24T08:31:09.985Z","avatar_url":"https://github.com/naqvis.png","language":"Crystal","funding_links":[],"categories":["Language Support"],"sub_categories":[],"readme":"# 🎭 [Playwright](https://playwright.dev) for Crystal ![CI](https://github.com/naqvis/playwright-cr/workflows/CI/badge.svg) [![GitHub release](https://img.shields.io/github/release/naqvis/playwright-cr.svg)](https://github.com/naqvis/playwright-cr/releases)\n\n\n#### [Website](https://playwright.dev/) |  [API Reference](https://naqvis.github.io/playwright-cr/)\n\n**Playwright-cr** is a Crystal library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable** and **fast**. [See how Playwright is better](https://playwright.dev/#path=docs%2Fwhy-playwright.md\u0026q=).\n\n\n|          | Linux | macOS | Windows |\n|   :---   | :---: | :---: | :---:   |\n| Chromium \u003c!-- GEN:chromium-version --\u003e89.0.4344.0\u003c!-- GEN:stop --\u003e | ✅ | ✅ | ✅ |\n| WebKit 14.1 | ✅ | ✅ | ✅ |\n| Firefox \u003c!-- GEN:firefox-version --\u003e85.0b1\u003c!-- GEN:stop --\u003e | ✅ | ✅ | ✅ |\n\nHeadless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/#?path=docs/intro.md\u0026q=system-requirements) for details.\n\n# Playwright Dependencies\nPlaywright Crystal relies on two external components: The Playwright driver and the browsers.\n\n## Playwright Driver\n\nPlaywright drivers will be downloaded to the `bin/driver` folder, and browsers will be installed at shard installation time.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     playwright:\n       github: naqvis/playwright-cr\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n### Page Screenshot\n\nThis code snippet navigates to whatsmyuseragent.org in Chromium, Firefox and WebKit, and saves 3 screenshots.\n```crystal\nrequire \"playwright\"\n\nplaywright = Playwright.create\nbrowser_types = [playwright.chromium,\n                 playwright.webkit,\n                 playwright.firefox]\n\nbrowser_types.each do |browser_type|\n  browser = browser_type.launch\n  context = browser.new_context(Playwright::Browser::NewContextOptions.new(\n    viewport: Playwright::Page::ViewPort.new(800, 600)))\n  page = context.new_page\n  page.goto(\"http://whatsmyuseragent.org/\")\n  page.screenshot(Playwright::Page::ScreenshotOptions.new(path: Path[\"screenshot-#{browser_type.name}.png\"]))\n  browser.close\nend\nplaywright.close\n```\n\n### Mobile and geolocation\n\nThis snippet emulates Mobile Chromium on a device at a given geolocation, navigates to openstreetmap.org, performs action and takes a screenshot.\n```crystal\nrequire \"playwright\"\n\nplaywright = Playwright.create\nbrowser = playwright.chromium.launch(Playwright::BrowserType::LaunchOptions.new(headless: false))\npixel2 = playwright.devices[\"Pixel 2\"]\ncontext = browser.new_context(Playwright::Browser::NewContextOptions.new(\n  viewport: Playwright::Page::ViewPort.new(pixel2.viewport.width, pixel2.viewport.height),\n  user_agent: pixel2.user_agent,\n  device_scale_factor: pixel2.device_scale_factor.to_i,\n  is_mobile: pixel2.is_mobile,\n  has_touch: pixel2.has_touch,\n  locale: \"en-US\",\n  geolocation: Playwright::Geolocation.new(41.889938, 12.492507),\n  permissions: [\"geolocation\"]))\npage = context.new_page\npage.goto(\"https://www.openstreetmap.org/\")\npage.click(\"a[data-original-title=\\\"Show My Location\\\"]\")\npage.screenshot(Playwright::Page::ScreenshotOptions.new(path: Path[\"colosseum-pixel2.png\"]))\nbrowser.close\nplaywright.close\n\n```\n\n### Evaluate in browser context\n\nThis code snippet navigates to example.com in Firefox, and executes a script in the page context.\n```crystal\nrequire \"playwright\"\n\nplaywright = Playwright.create\nbrowser = playwright.firefox.launch(Playwright::BrowserType::LaunchOptions.new(headless: false))\ncontext = browser.new_context\npage = context.new_page\npage.goto(\"https://www.example.com/\")\ndimensions = page.evaluate(%(\n  () =\u003e {\n    return {\n      width: document.documentElement.clientWidth,\n      height: document.documentElement.clientHeight,\n      deviceScaleFactor: window.devicePixelRatio\n    }\n  }\n))\nputs dimensions # =\u003e {\"width\" =\u003e 1280, \"height\" =\u003e 720, \"deviceScaleFactor\" =\u003e 1}\nbrowser.close\nplaywright.close\n```\n\n### Intercept network requests\n\nThis code snippet sets up request routing for a WebKit page to log all network requests.\n```crystal\nrequire \"playwright\"\n\nplaywright = Playwright.create\nbrowser = playwright.webkit.launch\ncontext = browser.new_context\npage = context.new_page\npage.route(\"**\", Playwright::Consumer(Playwright::Route).new { |route|\n  puts route.request.url\n  route.continue\n})\npage.goto(\"http://todomvc.com\")\nbrowser.close\nplaywright.close\n```\n\nRefer to `spec` for more samples and usages. This shard comes with **350+** test cases :)\n## Development\n\nTo run all tests:\n\n```\ncrystal spec\n```\nBy Default browser is `chromium`, but you can change the browser via setting environment variable of `BROWSER=firefox` or `BROWSER=webkit` for specs to run using different browser.\nBy default tests are run in **headless** mode. But if you would like the tests to run in headful way, set the environment variable `HEADFUL=true`.\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/naqvis/playwright-cr/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Ali Naqvi](https://github.com/naqvis) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaqvis%2Fplaywright-cr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaqvis%2Fplaywright-cr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaqvis%2Fplaywright-cr/lists"}