Skip to content

Commit

Permalink
Fix example code for browsing GitHub.com
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Sep 10, 2024
1 parent 2cb9cb6 commit 89f44c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ require 'puppeteer-ruby'
Puppeteer.launch(headless: false, slow_mo: 50, args: ['--window-size=1280,800']) do |browser|
page = browser.new_page
page.viewport = Puppeteer::Viewport.new(width: 1280, height: 800)
page.goto("https://github.com/", wait_until: 'domcontentloaded')
with_network_retry { page.goto("https://github.com/", wait_until: 'domcontentloaded') }

form = page.query_selector("form.js-site-search-form")
search_input = form.query_selector("input.header-search-input")
page.wait_for_selector('[placeholder="Search or jump to..."]').click
search_input = page.wait_for_selector('input[name="query-builder-test"]')
search_input.click
page.keyboard.type_text("puppeteer")

page.wait_for_navigation do
search_input.press('Enter')
search_input.press("Enter")
end

list = page.query_selector("ul.repo-list")
items = list.query_selector_all("div.f4")
list = page.wait_for_selector('[data-testid="results-list"]')
items = list.query_selector_all(".search-title")
items.each do |item|
title = item.eval_on_selector("a", "a => a.innerText")
puts("==> #{title}")
Expand Down Expand Up @@ -95,16 +95,16 @@ More usage examples can be found [here](https://github.com/YusukeIwaki/puppeteer

Following packages are required.

* Google Chrome or Chromium
* In Debian-based images, `google-chrome-stable`
* In Alpine-based images, `chromium`
- Google Chrome or Chromium
- In Debian-based images, `google-chrome-stable`
- In Alpine-based images, `chromium`

Also, CJK font will be required for Chinese, Japanese, Korean sites.

### References

* Puppeteer official README: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
* puppeteer-ruby example: https://github.com/YusukeIwaki/puppeteer-ruby-example/tree/master/docker_chromium
- Puppeteer official README: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
- puppeteer-ruby example: https://github.com/YusukeIwaki/puppeteer-ruby-example/tree/master/docker_chromium

## :bulb: Collaboration with Selenium or Capybara

Expand Down Expand Up @@ -224,12 +224,10 @@ RSpec.describe 'Sample integration tests', driver: :null do
end
```


## API

https://yusukeiwaki.github.io/puppeteer-ruby-docs/


## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/YusukeIwaki/puppeteer-ruby.
2 changes: 2 additions & 0 deletions lib/puppeteer/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ class ResponseDebugPrinter
NON_DEBUG_PRINT_METHODS = [
'Network.dataReceived',
'Network.loadingFinished',
'Network.requestServedFromCache',
'Network.requestWillBeSent',
'Network.requestWillBeSentExtraInfo',
'Network.resourceChangedPriority',
'Network.responseReceived',
'Network.responseReceivedExtraInfo',
'Page.lifecycleEvent',
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ def with_network_retry(max_retry: 2, timeout: 4, &block)
page.viewport = Puppeteer::Viewport.new(width: 1280, height: 800)
with_network_retry { page.goto("https://github.com/", wait_until: 'domcontentloaded') }

form = page.query_selector("form.js-site-search-form")
search_input = form.query_selector("input.header-search-input")
page.wait_for_selector('[placeholder="Search or jump to..."]').click
search_input = page.wait_for_selector('input[name="query-builder-test"]')
search_input.click
page.keyboard.type_text("puppeteer")

page.wait_for_navigation do
search_input.press("Enter")
end

list = page.query_selector("ul.repo-list")
items = list.query_selector_all("div.f4")
list = page.wait_for_selector('[data-testid="results-list"]')
items = list.query_selector_all(".search-title")
items.each do |item|
title = item.eval_on_selector("a", "a => a.innerText")
puts("==> #{title}")
Expand Down

0 comments on commit 89f44c6

Please sign in to comment.