[英]Ruby Capybara Poltergeist, how to take screenshot for a page with required login
So i am using Cabybara to take screenshots like this 所以我正在使用Cabybara来拍摄这样的屏幕截图
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 ? 但是现在我遇到了必须登录的页面,如何使用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 尽管具体细节将根据您尝试登录的页面/字段而有所不同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.