Testing session protected resources with Selenium RC
Consider the following scenario: We book or buy some stuff through a web application and at the end of the process the application generates a receipt in form of a pdf for us. The pdf contains personal information so we make it only accessible to the current session.
We’d like to test the success scenario end-to-end, making sure that whatever we enter through the web application appears in the pdf. How to access the pdf from our Selenium RC test?
Grab the session cookie by calling:
session_cookie = @selenium_driver.get_eval('window.document.cookie')
Then grab the resource through a http request within the selenium rc test:
resource = Net::HTTP.new(host, port).start { |http| get = Net::HTTP::Get.new(path_to_resource) get['Cookie'] = session_cookie response = http.request(get) response.body }
It works fine for a Rails app and i guess this principle should be applicable for any other server with cookie based session handling.
Tags: Testing