ãpuppeteer-rubyã¯ãCapybaraã¨å ±åãã¦åä½ç²¾åº¦ãåä¸ã§ããã®ã§ã¯ï¼ï¼ãã£ã¦ãããã¨ã«å é±ãããã«ãµã¨æ°ã¥ããã®ã§ãã«ãã¨ãªã£ã¦å®è£ ãã¦ã¿ãã
Capybaraã¨Puppeteerã®å ±å
ãããããªãã§å ±åãããå¿ è¦ãããã®ãï¼
- Seleniumã ã¨ãââã®è¦ç´ ãç¾ããã¾ã§å¾ ã¤ããâ³â³ã®è¦ç´ ãæ¶ããã¾ã§å¾ ã¤ãã¿ãããªã¨ããã§ãæã DOMã®å¤åéç¥ãæ¾ããããã¦ã失æãã¦ãã¾ããã¨ãããã
- Puppeteerã¯DOMã®å¤åéç¥ã«ã¯å¼·ãããã ãå ¨é¨ãPuppeteerã§æ¸ãç´ãæ°åã¯ç¡ã...ã
ã¿ãããªæãã§ãSeleniumãCapybaraã®æ¢åã³ã¼ãããªãã¹ãæ¸ãæããªãããã§Puppeteerã®ãåããããéè¦ã¯ãå²ã¨ããæ°ãããã
ã§ãéè¦ã¯ãããããªã®ã«ãä¸ã®ä¸ã«ããã®ã¯
ã®ããã«ãCapybara/Chromeãã©ã¤ããå®å ¨ã«ç½®ãæããä»çµã¿ã°ã£ããã ãªãã¨ã
ãããã¯ã¹ã¤ã«Seleniumãå¦å®ããããããããªããã ãSeleniumã®ä¸æºãã¤ã³ããã©ãã«ãPuppeteerã§è£å¼·ãããã ããªãã ãã¨ãããã¨ã§ãpuppeteer-rubyããã£ã¡ã®æ¹åã§ä½¿ããããã« Puppeteer.connect
ãå®è£
ããã
å®éã«åä½ãããä¾
RSpec.describe 'hotel.testplanisphere.dev', type: :feature do before { visit 'https://hotel.testplanisphere.dev/' @browser = Puppeteer.connect( browser_url: 'http://localhost:9222', default_viewport: Puppeteer::Viewport.new(width: 1280, height: 800)) } after { @browser.disconnect } it 'can be handled with puppeteer and assert with Capybara' do # automation with puppeteer >> puppeteer_page = @browser.pages.first puppeteer_page.wait_for_selector('li.nav-item') reservation_link = puppeteer_page.SS('li.nav-item')[1] await_all( puppeteer_page.async_wait_for_navigation, reservation_link.async_click, ) # << automation with puppeteer # expectation with Capybara DSL expect(page.title).to include('宿æ³ãã©ã³ä¸è¦§') expect(page).to have_text('宿æ³ãã©ã³ä¸è¦§') end it 'can be handled with Capybara and assert with puppeteer' do # automation with Capybara >> page.all('li.nav-item')[1].click # << automation with Capybara # expectation with puppeteer puppeteer_page = @browser.pages.first expect(puppeteer_page.title).to include('宿æ³ãã©ã³ä¸è¦§') body_text = puppeteer_page.Seval('body', '(el) => el.textContent') expect(body_text).to include('宿æ³ãã©ã³ä¸è¦§') end end
詳ããããããã¯ãã®è¾ºã«æ¸ãã¦ããâ puppeteer-ruby-example/_with_capybara-rspec at master · YusukeIwaki/puppeteer-ruby-example · GitHub
Seleniumãï¼DevTools Protocolã®ãã¼ãéæ¾ç¶æ ã§ï¼èµ·åããChromeãã©ã¦ã¶ã«å¯¾ãã¦ãPuppeteer.connectãã¦ããã¨ã¯Selenium WebDriverçµç±ã§ãPuppeteerçµç±ã§ãæä½ã§ããç¶æ ã«ãããã¨ããã ãã®è©±ã
使ã£ã¦ã¿ã¦ãã
2020/06/29ç¾å¨ã®ææ°ã®0.0.15ã§ã¯PDFåºåã«ã対å¿ãã¾ããã
ã¾ã ã¾ã 足ããªãæ©è½ã¯ããããããã¾ããããSelenium使ã£ã¦ã¿ããã©ããªããæã ãã¹ããè½ã¡ã¦å°ã£ã¦ãã»ã»ã»ãã£ã¦ãã人ã«ã¯ãããã¨ä¾¿å©ãªããããªãããªãã
å¹æã«ã¤ãã¦ã¯ä¼ç¤¾ã®ã»ãã§ãããããã£ã¦è©¦ãã¦ãããããå°ãä¸å¯§ã«æ«é²ãããã¨ãããã
(2020.08.30追è¨) ã¦ããã¼#2ã£ã¦ããã¤ãã³ãã§æ«é²ãã
åä½ãã¹ããæ¸ãå§ãã¦ãããã精度ãä¸ãã£ã¦ããã®ã§ãてすらぼみーとあっぷ #2 - connpass ã§å°ã£ã¦ã人ãããªãããªã¼ï¼ã¨æ¢ãã«ç»å£çºè¡¨ãã¦ã¿ã¾ããã