Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not run test sequentially #562

Closed
styrus opened this issue May 25, 2020 · 21 comments
Closed

could not run test sequentially #562

styrus opened this issue May 25, 2020 · 21 comments

Comments

@styrus
Copy link

styrus commented May 25, 2020

I am facing problem in running tests which are like


how can I handle this so that it runs sequentially.
**error is for token is undefined.** as it does not find token first.
@vlucas
Copy link
Owner

vlucas commented May 26, 2020

Frisby tests cannot be run sequentially, and your test suite should never depend on the order of tests that are run.

If there is setup you need to do for each successive test in your suite, you have a few options. You can use frisby.use(withTokenAuth).get(...).expect(...) in each test you need it in. Your withTokenAuth function might look like this:

// Define your helper function
function withTokenAuth(spec) {
  const token = '123abc';

  return spec.setup({
    request: {
      headers: {
        'Authorization': 'Bearer ' +token,
        'header':'value'
      }
    }
  });
}


it('make call USING GLOBAL SETUP' , function() {
    console.log('########### In IT  call ###########')
   return frisby
    .use(withTokenAuth) // USE the `withTokenAuth` function here in your test (and in every test you need it in)
    .post('url/call', 
    {
      // json body
    })
    .expect('status', 200);
  });

You can also just use the setup method directly in each test as well.

@styrus

This comment has been minimized.

@H1Gdev
Copy link
Collaborator

H1Gdev commented May 30, 2020

  • It looks like you haven't set token in first it block.
  • -i option is enabled in case of multiple test files in jest.

@styrus

This comment has been minimized.

@styrus
Copy link
Author

styrus commented Jun 22, 2020

@vlucas can you please provide your input on this.
thanks in advance

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jun 22, 2020

HTTP status 415 has wrong Content-Type.
What is Content-Type of request set to ?
Have you changed Content-Type in globalSetup ?

@styrus
Copy link
Author

styrus commented Jun 23, 2020

@vlucas when I am passing token as the hard coded value and calling postCall (url,body) with .inspectRequestHeaders() it works and shows me correct headers getting passed

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jun 23, 2020

Is there issues with getToken() ?

@styrus
Copy link
Author

styrus commented Jun 30, 2020

@vlucas can you please provide you thought on this.
thanks in advance

@styrus
Copy link
Author

styrus commented Jun 30, 2020

@H1Gdev if you check my comment above getToken() works fine and returns me token.

@vlucas
Copy link
Owner

vlucas commented Jun 30, 2020

Can you dump the request headers so we can see what is actually being sent? 415 is a response from your server, and we cannot debug that or provide support for it.

Also:

return spec.setup({
    request: {
      headers: {
        'Authorization': 'Bearer ' +token,
        'header':'value' // Did you remember to delete this line? This was just an example...
      }
    }
  });

@styrus

This comment has been minimized.

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 2, 2020

When I call these method independently it works fine.

Please paste each code.

@styrus

This comment has been minimized.

@vlucas
Copy link
Owner

vlucas commented Jul 3, 2020

We cannot debug your server response for you. This is not a free support forum.

I am closing this issue for now.

You can re-open it If you can give us code for both server and client in an isolated and reproducible way that proves the issue with the Frisby library itself, then we can help with a fix. Otherwise, we cannot spend any more time on this issue.

@vlucas vlucas closed this as completed Jul 3, 2020
@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 4, 2020

I can't understand this code:confused:
At the very least, make code that completes frisby.
(For example, list tests that pass and fail.)

@styrus

This comment has been minimized.

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 6, 2020

@styrus

getToken(url) [this method returns token from body reponse.]

#562 (comment)

getToken(url) returns frisby (that is, Promise).

I don't know how to give advice because the code is incomplete like this...
So if you want to reopen it, write some code that works correctly.

@styrus

This comment has been minimized.

@vlucas
Copy link
Owner

vlucas commented Jul 6, 2020

We need both the client and server code to help you. We need an independent code repository that we can clone and run that has both the server and frisby tests for it.

One test that shows where it is working.
One test that shows where it is not.

You have all the code and the full context so it might be clear to you, but it is not clear at all to us. We need something isolated and reproducible in order to help you.

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 23, 2020

It's no good returning Promise.
If you use async and await like below, you will get the expected behavior.

async function getToken(URL) {
   return frisby
    .setup
        ({
            request:
                {
                    headers: 
                        {
                            'Authorization': 'Basic ' + Buffer.from("usrname:pwd").toString('base64'),
                            'ouc_header':'admin',
                            'Content-Type': 'application/scim+json'
                        }
                }
    })
    .get(apiURL)
    .inspectResponse()
    .inspectRequestHeaders()
    .expect('status', 200)
    .then(res => {
        var token=res._token; // Can you really get it with this ???
        console.log(token);
        return token;
    });
}
const instance_token= await getToken(url);

But first, it's better to understand Promise of JavaScript.

@styrus styrus changed the title could not run frisby test sequentially using Jasmine could not run test sequentially Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants