Authentication in AngularJS/Testacular e2e scenarios

1,024 views
Skip to first unread message

Christian Smith

unread,
Nov 16, 2012, 1:21:07 PM11/16/12
to ang...@googlegroups.com
I have an AngularJS application that requires authentication. It's part of a larger project served from Express and lives at its own base path: `<base href="/path/to/app/">`, not `/`. The existing application already has a round trip login. Users need to be logged in before they can access the Angular app. This works fine, except for e2e testing with testacular.

With authentication on the server disabled, e2e tests run without problems. For example:

    describe 'protected app', ->

      it 'should display the index', ->
        browser().navigateTo '/path/to/app'
        expect(browser().location().url()).toBe '/'

      it 'etc...'


Obviously, with server side authentication, this will fail. We need to be logged in first. We get the following error:

    Sandbox Error: Application document not accessible.

The problem comes when we try to log in within our scenarios.

    describe 'protected app', ->

      it 'should authenticate', ->
        browser().navigateTo '../login'
        #input('#email').enter('ad...@example.com')
        #input('#password').enter('secret')
        #element('button').click()    

      it 'should display the index', ->
        browser().navigateTo '/path/to/app'
        expect(browser().location().url()).toBe '/'

      it 'etc...'

Running this (with or without filling out the form and clicking) results in the login page loading and freezing up. Testacular never completes its run, it just hangs on the login page.

Is there a flaw in my understanding of Angular/Testacular/e2e testing or perhaps a bug?


Any ideas? Thanks!

Vojta Jína

unread,
Nov 16, 2012, 6:43:45 PM11/16/12
to ang...@googlegroups.com
Hey Christian,

short answer: this is a limitation of the scenario runner, it can't handle full page reload.

I think the easier solution would be to fake the auth, basically create a session on the server before performing tests, depending on what kind of authentication you are using.

V.

Christian Smith

unread,
Nov 16, 2012, 7:02:49 PM11/16/12
to ang...@googlegroups.com
Vojta responded on Github:

"This is not a Testacular issue. Testacular should have a time-out per test and per test suite, so that it does not hang forever (that's already on my todo list).

"The problem is angular scenario runner does not support full page reload."


k...@pivotallabs.com

unread,
Dec 18, 2012, 10:13:38 PM12/18/12
to ang...@googlegroups.com
How does one fake the auth? If I could provide basic auth headers, that would "work" for me, but how do I tweak the runner to insert the extra headers before contacting the back end?

Ken

John Gordon

unread,
Feb 11, 2013, 12:54:20 PM2/11/13
to ang...@googlegroups.com, k...@pivotallabs.com
A simple approach would be to add a button in the UI that tests could click on.  You could do whatever action you wanted in the button's click handler.  We're doing this to login a user.

Hampus Ahlgren

unread,
Apr 24, 2013, 9:40:52 AM4/24/13
to ang...@googlegroups.com
How did you end up going about the log-in problem?

bstyle killa

unread,
Sep 9, 2013, 2:52:11 PM9/9/13
to ang...@googlegroups.com
What does this is not a Testacular issue its a angular scenario runner issue solution look like? How can I log in to securityapp:8081 then be redirected to my app:8080? This is pretty standard for authenticating users so it should have a work around right?
Reply all
Reply to author
Forward
0 new messages