简体   繁体   English

Ruby Capybara Poltergeist,如何为具有所需登录名的页面拍摄屏幕截图

[英]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.

相关问题 如何在 Ruby 中使用 selenium-webdriver/capybara 截取完整浏览器页面及其元素的屏幕截图? - How to take a screenshot of a full browser page and its elements using selenium-webdriver/capybara in Ruby? 如果定义了Capybara Poltergeist驱动程序(对于Ruby),如何访问Selenium方法 - How to access Selenium methods if I defined Capybara Poltergeist driver (for Ruby) Capybara和Poltergeist的save_screenshot的未定义方法 - Undefined method for save_screenshot for Capybara and Poltergeist 如何正确调试Capybara / Poltergeist? - How to properly debug with Capybara/Poltergeist? Capybara button.click在控制台上有效,但不适用于脚本(Ruby; Capybara; Poltergeist) - Capybara button.click works on Console but not on a Script (Ruby; Capybara; Poltergeist) 最小的Capybara / Poltergeist测试返回空页 - Minimal Capybara / Poltergeist test returning empty page 如何使用Ruby,Rspec,Capybara和Selenium在无头(Poltergeist)模式下运行TC? - How to run TC in headless (Poltergeist) mode using Ruby, Rspec, Capybara and Selenium? 如何使用水豚和恶作剧检索innertext? - How to retrieve innertext using capybara and poltergeist? 如何测试/与AJAX自动完成功能和Capybara / Poltergeist交互 - how to test / interact with AJAX autocomplete and Capybara / Poltergeist 如何让jQuery与PhantomJS,Poltergeist和Capybara一起工作 - How to have jQuery work with PhantomJS, Poltergeist and Capybara
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM