Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Suites for authenticated pages #799

Open
zouxuoz opened this issue Jul 15, 2017 · 1 comment
Open

Suites for authenticated pages #799

zouxuoz opened this issue Jul 15, 2017 · 1 comment

Comments

@zouxuoz
Copy link

zouxuoz commented Jul 15, 2017

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?

@nbasov
Copy link

nbasov commented Jul 23, 2017

.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')
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants