gemini icon indicating copy to clipboard operation
gemini copied to clipboard

Suites for authenticated pages

Open zouxuoz opened this issue 8 years ago • 1 comments

Hey, guys. I'm starting writing regression tests for my application and gemini is awesome, but I have some problems with protected pages.

I want to authenticate user before the start gemini suite, but it's not working because functions executed in browser context.

gemini.suite('As authenticated user, I can see dasboard', (suite) => {
  suite.setUrl('/dasboard')
    .before(function(actions) {
      actions.executeJS(function(window) {
        helpers.asUser({ authenticated: true }).then(function({ token }) {
          setCookie(window.document, TOKEN_COOKIE_NAME, token, {
            expires: 7,
            domain: TOKEN_COOKIE_DOMAIN,
          });

          window.authenticated = true;
        });
      });

      actions.waitForJSCondition(function(window) {
        return window.authenticated;
      }, 120000);
    })
    .setCaptureElements('body')
    .capture('1440x1024', function(actions) {
      actions.setWindowSize(1440, 1024);
    })
  ;
});

How I can pass some variables and functions to browser context with gemini or may be exist another way to resolve my case?

zouxuoz avatar Jul 15 '17 12:07 zouxuoz

.before will be applied after specified url loading (before you set cookie). To handle that, you need to call this url once again. Here is working example (but for localStorage in my case):

gemini.suite('login', (suite) => {
    suite.setUrl('/login')
        .setCaptureElements('body')
        .capture('plain', function (actions, elements) {
            actions.executeJS(function (window) {
                // set token for next suite
                window.localStorage.setItem("token", "secret")
            })
        })
})

gemini.suite('main', (suite) => {
    suite.setUrl('/')
        .setCaptureElements('html')
        .capture('plain')
});

nbasov avatar Jul 23 '17 09:07 nbasov