how to wait for all redirects to finish using intern/web driver?

47 views Asked by At

I'm trying to test that the application redirects the user away from the authenticated route since they are not an admin.

But I need a way to wait for all redirects to finish before I call getCurrentUrl()

    it('should not allow regular user access', async (test) => {
  await test.remote
      .then(e2e.impersonate('[email protected]'))
      .get('/protected-route')
      //.waitForAllRedirects()
      .getCurrentUrl()
      .then(url => {
        console.log('url', url);
        expect(url.indexOf('/landing-page')).not.toBe(-1);
        return true;
      });
});
1

There are 1 answers

2
jason0x43 On

Probably the simplest thing to do is to look for content that should be on the non-protected page rather than the protected page. Once you've found the expected content, check the URL to verify you're where you should be.

it('should not allow regular user access', test => {
  return test.remote
    .then(e2e.impersonate('[email protected]'))
    .get('/protected-route')
    .findByCssSelector('.something.that.should.be.visible')
    .getCurrentUrl()
    .then(url => {
      console.log('url', url);
      expect(url.indexOf('/landing-page')).not.toBe(-1);
      return true;
    });
});