{"id":15012833,"url":"https://github.com/yusukeiwaki/playwright-ruby-client","last_synced_at":"2025-05-14T15:07:25.160Z","repository":{"id":39623561,"uuid":"326015245","full_name":"YusukeIwaki/playwright-ruby-client","owner":"YusukeIwaki","description":"Playwright client for Ruby","archived":false,"fork":false,"pushed_at":"2025-05-09T22:51:46.000Z","size":8747,"stargazers_count":393,"open_issues_count":9,"forks_count":40,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-09T23:29:01.443Z","etag":null,"topics":["playwright","ruby"],"latest_commit_sha":null,"homepage":"https://playwright-ruby-client.vercel.app/","language":"Ruby","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/YusukeIwaki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-01-01T16:33:25.000Z","updated_at":"2025-05-09T17:50:25.000Z","dependencies_parsed_at":"2023-10-27T08:24:13.515Z","dependency_job_id":"d59c9551-5562-4dd6-9bc2-3b4758850e71","html_url":"https://github.com/YusukeIwaki/playwright-ruby-client","commit_stats":{"total_commits":762,"total_committers":20,"mean_commits":38.1,"dds":0.04330708661417326,"last_synced_commit":"26b2ae1ab30b92916d8c23552c03ada3d1a0c48e"},"previous_names":[],"tags_count":112,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-ruby-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-ruby-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-ruby-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-ruby-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YusukeIwaki","download_url":"https://codeload.github.com/YusukeIwaki/playwright-ruby-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169661,"owners_count":22026213,"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":["playwright","ruby"],"created_at":"2024-09-24T19:43:18.102Z","updated_at":"2025-05-14T15:07:25.116Z","avatar_url":"https://github.com/YusukeIwaki.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/playwright-ruby-client.svg)](https://badge.fury.io/rb/playwright-ruby-client)\n\n# 🎭 Playwright client for Ruby\n\n#### [Docs](https://playwright-ruby-client.vercel.app/docs/article/getting_started) | [API](https://playwright-ruby-client.vercel.app/docs/api/playwright)\n\n## Getting Started\n\n```\ngem 'playwright-ruby-client'\n```\n\nand then 'bundle install'.\n\nSince playwright-ruby-client doesn't include the playwright driver, **we have to install [playwright](https://github.com/microsoft/playwright) in advance**.\n\n```\nnpm install playwright\n./node_modules/.bin/playwright install\n```\n\nAnd set `playwright_cli_executable_path: './node_modules/.bin/playwright'`\n\n**Prefer playwrighting without Node.js?**\n\nInstead of npm, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/cb5409934629adaabc0cff1891080de2052fa778/setup.py#L73-L77)\n\n### Capture a site\n\n```ruby\nrequire 'playwright'\n\nPlaywright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|\n  playwright.chromium.launch(headless: false) do |browser|\n    page = browser.new_page\n    page.goto('https://github.com/YusukeIwaki')\n    page.screenshot(path: './YusukeIwaki.png')\n  end\nend\n```\n\n![image](https://user-images.githubusercontent.com/11763113/104339718-412f9180-553b-11eb-9116-908e1e4b5186.gif)\n\n### Simple scraping\n\n```ruby\nrequire 'playwright'\n\nPlaywright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|\n  playwright.chromium.launch(headless: false) do |browser|\n    page = browser.new_page\n    page.goto('https://github.com/')\n\n    page.get_by_placeholder(\"Search or jump to...\").click\n    page.locator('input[name=\"query-builder-test\"]').click\n\n    expect(page.keyboard).to be_a(::Playwright::Keyboard)\n\n    page.keyboard.type(\"playwright\")\n    page.expect_navigation {\n      page.keyboard.press(\"Enter\")\n    }\n\n    list = page.get_by_test_id('results-list').locator('.search-title')\n\n    # wait for item to appear\n    list.first.wait_for\n\n    # list them\n    list.locator('.search-title').all.each do |item|\n      title = item.text_content\n      puts(\"==\u003e #{title}\")\n    end\n  end\nend\n```\n\n```sh\n$ bundle exec ruby main.rb\n==\u003e microsoft/playwright\n==\u003e microsoft/playwright-python\n==\u003e microsoft/playwright-cli\n==\u003e checkly/headless-recorder\n==\u003e microsoft/playwright-sharp\n==\u003e playwright-community/jest-playwright\n==\u003e microsoft/playwright-test\n==\u003e mxschmitt/playwright-go\n==\u003e microsoft/playwright-java\n==\u003e MarketSquare/robotframework-browser\n```\n\n### Android browser automation\n\n```ruby\nrequire 'playwright'\n\nPlaywright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|\n  devices = playwright.android.devices\n  unless devices.empty?\n    device = devices.last\n    begin\n      puts \"Model: #{device.model}\"\n      puts \"Serial: #{device.serial}\"\n      puts device.shell('ls /system')\n\n      device.launch_browser do |context|\n        page = context.pages.first\n        page.goto('https://github.com/YusukeIwaki')\n        page.click('header button')\n        page.click('input[name=\"q\"]')\n        page.keyboard.type('puppeteer')\n        page.expect_navigation {\n          page.keyboard.press('Enter')\n        }\n        page.screenshot(path: 'YusukeIwaki.android.png')\n      end\n    ensure\n      device.close\n    end\n  end\nend\n```\n\n![android-browser](https://user-images.githubusercontent.com/11763113/106615177-8467a800-65af-11eb-94d9-c56e71487e78.gif)\n\n### Android native automation\n\nWe have to download android-driver for Playwright in advance.\n\n```\nwget https://github.com/microsoft/playwright/raw/master/bin/android-driver-target.apk -O /path/to/playwright-driver/package/bin/android-driver-target.apk\nwget https://github.com/microsoft/playwright/raw/master/bin/android-driver.apk -O /path/to/playwright-driver/package/bin/android-driver.apk\n```\n\n(If you downloaded Playwright via npm, replace `/path/to/playwright-driver/package/` with `./node_modules/playwright/` above.)\n\n```ruby\nrequire 'playwright'\n\nPlaywright.create(playwright_cli_executable_path: ENV['PLAYWRIGHT_CLI_EXECUTABLE_PATH']) do |playwright|\n  devices = playwright.android.devices\n  unless devices.empty?\n    device = devices.last\n    begin\n      device.shell('input keyevent POWER')\n      device.shell('input keyevent POWER')\n      device.shell('input keyevent 82')\n      sleep 1\n      device.shell('cmd statusbar expand-notifications')\n\n      # pp device.tree\n      # pp device.info(res: 'com.android.systemui:id/clock')\n      device.tap_on(res: 'com.android.systemui:id/clock')\n    ensure\n      device.close\n    end\n  end\nend\n\n```\n\n### Communicate with Playwright server\n\nIf your environment doesn't accept installing browser or creating browser process, consider separating Ruby client and Playwright server.\n\n![structure](https://user-images.githubusercontent.com/11763113/124934448-ad4d0700-e03f-11eb-942e-b9f3282bb703.png)\n\nFor launching Playwright server, just execute:\n\n```\nnpx playwright install \u0026\u0026 npx playwright run-server --port 8080 --path /ws\n```\n\nand we can connect to the server with the code like this:\n\n```ruby\nPlaywright.connect_to_playwright_server('ws://127.0.0.1:8080/ws?browser=chromium') do |playwright|\n  playwright.chromium.launch do |browser|\n    page = browser.new_page\n    page.goto('https://github.com/YusukeIwaki')\n    page.screenshot(path: './YusukeIwaki.png')\n  end\nend\n```\n\nWhen `Playwright.connect_to_playwright_server` is used, playwright_cli_executable_path is not required.\n\nFor more detailed instraction, refer this article: https://playwright-ruby-client.vercel.app/docs/article/guides/playwright_on_alpine_linux\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Playwright project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/playwright-ruby-client/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukeiwaki%2Fplaywright-ruby-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusukeiwaki%2Fplaywright-ruby-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukeiwaki%2Fplaywright-ruby-client/lists"}