Set cookie before visiting a page

1,927 views
Skip to first unread message

Fabs

unread,
Mar 6, 2015, 9:23:01 AM3/6/15
to nightw...@googlegroups.com
Hi there

I am having problems with an authenticated page! 

Let's say I have a url X which loads a page that requires authentication. Login can be performed on page at url Y. 

Normal behaviour is the following:

- you go to X without authentication and you get redirected to Y.
- you go to Y when authenticated and you get redirected to X.

Now... what I am doing with nightwatch is the following:

      browser
        .setCookie(authenticatedCookieContentPreviouslyObtained)
        .url(X); 

Unfortunately I get redirected to page Y even though, theoretically, the cookie is set and page X should be accessible.

The content of the cookie is valid as I tested it by hand adding the cookie to a non authenticated browser which can then magically access the page once the cookie is added via firebug.

Any idea?

davidlinse

unread,
Mar 7, 2015, 7:19:00 AM3/7/15
to nightw...@googlegroups.com
Did you tried to switch the URL and setCookie commands?

~david

Alex Johnston

unread,
Oct 6, 2015, 9:50:42 AM10/6/15
to NightwatchJs
I know this is an old thread but in case anyone is looking for a solution - I had difficulty with this and found the best way was to navigate to the URL, set the cookie then reload the page as setting after .url only seemed to take effect after the page loaded.

eg.

            .url(link)
            .setCookie(xxxxxx)
            .url(link)


May not be ideal but works for now. If anyone has any better ideas please let me know.
Reply all
Reply to author
Forward
0 new messages