简体   繁体   中英

Ruby Capybara Poltergeist, how to take screenshot for a page with required login

So i am using Cabybara to take screenshots like this

Capybara.register_driver(:poltergeist) { |app| Capybara::Poltergeist::Driver.new(app, js_errors: false) }
Capybara.default_driver = :poltergeist
session = Capybara.current_session
session.visit url
session.save_screenshot('image.png',full: true)

But now i encountered a page where i have to login, how can i login and take screen shot of this web page using Capybara ?

You need to fill out the login fields, click whatever button submits the login info, then wait until the login completes and then take your screenshot. Something like

session.visit url
session.fill_in 'Email', with: 'user@example.com'
session.fill_in 'Password', with: 'password'
session.click_button 'Sign in'
expect(session).to have_content 'You are now logged in!'
session.save_screenshot('image.png',full: true)

although the specific details are going to vary based on the page/fields you're trying to log into

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM