简体   繁体   中英

Capture screenshot of Steam page with Ruby

I need to capture screenshot from steam web page, that contains trade offer error, but for this action i have to be authorized and I don't know what header send to server. I am trying to do this with webshot gem , filling my credentials with capybara, but this not working and it captures login page

 ws.start_session do
  visit 'https://store.steampowered.com/login/'
  within(:css, 'form[name="logon"]') do
    fill_in 'username', {:id => 'input_username', :with => 'test'}
    fill_in 'password', {:id => 'input_password', :with => 'password'}
  end
  click_button('Sign in', exact: true)
end.capture 'https://store.steampowered.com/account', 'example.png', width: 500, height: 500, quality: 85

Your error is probably occurring because your code doesn't wait for the login to be successful before moving on to request the account page, so the request for the account page doesn't have the correct cookies set and gets redirected back to the login page. You need to do some sort of check to make sure the login has completed. Something like

ws.start_session do
  visit 'https://store.steampowered.com/login/'
  within(:css, 'form[name="logon"]') do
    fill_in 'input_username', with: 'test'
    fill_in 'input_password', with: 'password'
  end
  click_button('Sign in', exact: true)
  page.assert_text('You are now logged in!') # whatever text shows on the page after successfully logging in
end.capture 'https://store.steampowered.com/account', 'example.png', width: 500, height: 500, quality: 85

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