twalpole / apparition

Capybara driver for Chrome using CDP
MIT License
363 stars 46 forks source link

Missing switch_to API #27

Closed christiannelson closed 5 years ago

christiannelson commented 5 years ago

Thanks for creating and maintaining apparition! We also tried to create a new driver that bypasses selenium and chromedriver (we called it https://github.com/carbonfive/shimmer), but didn't get very far... we're excited to see something else maturing. :)

It looks like an API that is supported by selenium-webdriver might be missing in apparition. Perhaps we were using a non-standard API?

Failure/Error: page.driver.browser.switch_to.alert.accept

     NoMethodError:
       undefined method `switch_to' for #<Capybara::Apparition::Browser:0x000000010d770bb0>
       Did you mean?  https://github.com/carbonfive/shimmer

Do you have any suggestions? Thanks!

twalpole commented 5 years ago

You're welcome - hopefully it works for you.

For system modals you should be using the Capybara modals API - https://www.rubydoc.info/github/teamcapybara/capybara/Capybara/Session#accept_alert-instance_method - which in your case would be

page.accept_alert do
  # perform action that triggers the alert to appear
end
christiannelson commented 5 years ago

@twalpole That worked perfect, and I learned about the official API for handling confirmations and alerts. Thank you!

Note sure if this is the best place to ask, but when we created shimmer, our hypothesis was that we could get closer to poltergeist performance by reducing the middle layers (selenium + chromedriver). We found poltergeist to be roughly 2x faster than headless chrome. Our very early tests suggested we could, but then with more real world example that was no longer the case.

Do you have any anecdotal evidence that suggests there's some truth to that (faster without the middeman)?

twalpole commented 5 years ago

@christiannelson It should be slightly faster than selenium/chromedriver but it's not going to be near 2X. The main reason Poltergeist was faster was because it wasn't doing nearly as much as a real browser (a 6-7 year old browser let alone modern). The real benefit of Apparition over Selenium/chromedriver is simpler requirements (just the browser) and more functionality available via CDP. Technically you can now use CDP commands via Selenium too but there's no way to match up/pass elements found via webdriver and CDP.

christiannelson commented 5 years ago

@twalpole That totally makes sense... thanks for the explanation.