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

How to pass variable in POST request #143

Closed
desaip01 opened this issue Oct 9, 2014 · 4 comments
Closed

How to pass variable in POST request #143

desaip01 opened this issue Oct 9, 2014 · 4 comments

Comments

@desaip01
Copy link

desaip01 commented Oct 9, 2014

Hello,
var postJSON = [{'queryString': 'First String'},
{'queryString': 'Second String'}];

for(var i=0; i<postJSON.length; i++) {
var obj = postJSON[i];
frisby.create('Execute Query to verify the Query Results')
.post(serverName + port + runQuery, {
--> How can I pass a variable --> obj.queryString
})
.expectStatus(200)
.expectHeader('Content-Type', 'application/json')
.inspectJSON()
.toss();
}

@moses-gangipogu
Copy link

var frisby = require('/usr/local/lib/node_modules/frisby/lib/frisby');

// Global setup for all tests
frisby.globalSetup({
request: {
headers: {
'Accept': 'application/json, application/x-httpd-php',
'Cookie': 'authToken=xx; activationId=1; userId=1;'
}
},
timeout: (30 * 1000)
});

/**

  • Tests -> testPostSample
    */

var requestData = {
"mainone": [{
"mainonesubone": "Apple",
"mainonesubtwo": "xx",
"mainonesubthree": "500.00",
"mainonesubfour": [{
"mainonesubfoursubone": "",
"mainonesubfoursubtwo": ""
}],
"mainonesubfive": ""
}],
"maintwo": [{
"maintwosubone": "ebay.com",
"maintwosubtwo": true,
"maintwosubthree": true
}]
};
frisby.create('testPostSample')
.post('http://localhost/url/to/api', requestData, {
json: true
})
.expectStatus(200)
.expectJSON('status', {
message: "success",
code: "1"
})
.toss();

this might help u

@desaip01
Copy link
Author

Worked, Thank you

On Mon, Oct 13, 2014 at 3:16 AM, Moses Gangipogu notifications@github.com
wrote:

var frisby = require('/usr/local/lib/node_modules/frisby/lib/frisby');

// Global setup for all tests
frisby.globalSetup({
request: {
headers: {
'Accept': 'application/json, application/x-httpd-php',
'Cookie': 'authToken=xx; activationId=1; userId=1;'
}
},
timeout: (30 * 1000)
});

/**

  • Tests -> Create Compare Product */

var requestData = {
"mainone": [{
"mainonesubone": "Apple",
"mainonesubtwo": "xx",
"mainonesubthree": "500.00",
"mainonesubfour": [{
"mainonesubfoursubone": "",
"mainonesubfoursubtwo": ""
}],
"mainonesubfive": ""
}],
"maintwo": [{
"maintwosubone": "ebay.com",
"maintwosubtwo": true,
"maintwosubthree": true
}]
};
frisby.create('testPostSample')
.post('http://localhost/url/to/api', requestData, {
json: true
})
.expectStatus(200)
.expectJSON('status', {
message: "success",
code: "1"
})
.toss();

this might help u


Reply to this email directly or view it on GitHub
#143 (comment).

@moses-gangipogu
Copy link

great 👍

@vlucas vlucas closed this as completed Feb 9, 2015
@dnascimento
Copy link

For sake of simplicity, we should create a .postJson(url, data) alias to

.post(url, data, 
    {json: true} ,
   { headers: { 'Content-Type': 'application/json'}}
)

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

4 participants