I want to test interactive authentication using watir. I need to open the browser once on the selenium server, enter without user interaction with its username / password (stored on the server, the user does not enter them, he just needs to enter the verification code), a new text box appears with the label βenter verification codeβ, then the system sends a confirmation code to the user and closes the browser (here I need to somehow save the session). The user receives a confirmation code and sends it to the server, the server opens a new browser (restores somehow saved session) and enters the confirmation code received from the user.
I could leave the browser open and simply enter the verification code in the text box that appears, but if the user does not send me the verification code that he received, the browser will remain open, and not a good solution.
So, I tried something like this:
params = { login: 'userexample.com', password: '123456' } adapter = Adapters::Test.new(params) adapter.sign_in #opens browser, fills credentials fields, clicks 'get verification code', 'enter verification code' field appears cookies = adapter.browser.cookies.to_a #save browser state url = adapter.browser.url adapter.browser.close adapter = Adapters::Test.new(params) adapter.browser.goto url adapter.browser.cookies.clear cookies.each do |saved_cookie| adapter.browser.cookies.add(saved_cookie[:name], saved_cookie[:value]) end adapter.browser.refresh #I should be on the same page with appeared 'enter verification code' field, but nothing happens after refresh, I am still on the main page with only login/password fields.
How to save the state of the browser, close it, and then open it again with the same session?
source share