2

How to automate remember me feature using selenium webdriver and cucumber

Reading Time: 2 minutes

TL;DR

 

In this post I will explain problems I encountered and how I resolved them while I was designing automated test for remember me feature.

 

Context of this post is automation of end to end feature that are visible to user via the browser. You will see remember me checkbox on your login page, but that is the point where visibility of this feature ends.

 

How remember me feature actually works?

If you do not check remember me, then when you close browser after you have finished using web application, next time you come back to the application, you will need to login in again.

 

If you check remember me, then when you close browser and come back again to your application, you will be automatically logged in.

Magic behind this feature are cookies. Cookie contains session for your application and information how long that session in cookie is valid. Server side creates the cookie, but browser must act based on the information in that cookie.

 

So when you test remember me feature, you actually test browser and web application features.

 

First issue in test design

 

In order to have faster execution of browser automation tests, I do not close browser between scenarios (Watirmelon first page object anti pattern). But in order to test remember me feature, you need to close the browser. Here is the code that should be put in cucumber env.rb file that resolves this issue:

 

Second issue is scenario run order dependency

 

But that solution introduces another anti pattern, now scenario run from remember me feature file must be always run in same order:

 

 

That means you can not use following cucumber run option:

 

cucumber –order random :5738 remember_me.feature

Here is step that loads cookies:

 

Third issue selenium webdriver cookie domains

In my first implementation, in env.rb file, I just saved all browser cookies to file. But when I loaded those cookies, i got following exception:

 

 

Note: By observing that exception I learned that Firefox webdriver is actually Firefox extension written in javascript. That extension is automatically installed in Firefox before test run.

And here is the line of code that produces exception:

 

 

Observe comment in line 8 🙂 For me it implies that developer did not know how to properly implement cookie domain check. But as it is open source project, we will forgive him.

 

The issue here was that Google Analytics cookies had subdomain:

.app.domain.com

as cookie domain value. As application domain was:

app.domain.com

Google Analytics cookie domain was rejected in firefox webdriver. So before saving cookie values in file, I deleted Google Analytics cookies.

 

Conclusion

 

I am moving this blog from Blogger. While I was publishing this post, I discovered that WordPress needs plugin in order to embed gists to posts. Blogger had that feature out of the post.

 

Finding proper WordPress heuristic: install one that has more stars.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Karlo Smid

2 Comments

  1. Hi I am getting the same error. can you please guide me what should i do. I do not have a source code version.

    • Hi Zalak!

      In env.rb, do something like this:
      After do |scenario|
      if scenario.name.include? “remember me”
      @browser.cookies.delete(‘_gat’)
      @browser.cookies.delete(‘_ga’)
      @browser.cookies.save(‘remember_me.cookies’)
      @browser.close
      end
      end

      So you need to delete cookies which domains are from application under test domain.

      Regards, Karlo.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.