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
Documentation - REST API GET & POST commands #1541
Comments
Thanks a lot for your post! I appreciate this collaboration. |
I can't seem to get this working at all. This is my test:
|
Hi, I have a Query : I want to get the href value of a link and get HttpResponse status code for that, how can it be done ?? Instead of clicking on each link and asserting the page i want to get the http response code of each link href value..suggest me if any other solution for this |
Hello ! In my use I would like to know how to add a header with an Authorization and a Content-Type on your "Test POST sample" ? would it be possible to help me on that ? thank you very much for your help :) |
Have you put the commands in the right folder? ./commands/apiGet.js And make sure that in nightwatch.json the following path is added ` "custom_commands_path": "./commands", In case you have a different custom_commands_path, you should put the files in there. |
I have not tested this, but it could point you in the right direction:
Rough idea:
|
Then you could something like this. REMARK: not fully tested module.exports = {
}; |
indeed ! it works thank you very much ! |
I have updated the POST command code above to support this case. I know it's not perfect but feel free to improve it. |
Thanks this helped me heaps! I chose to refactor my apiGet function to be more in line with the current format of the examples provided for custom commands. I am not sure how accurate/safe it is but it's working fine for me, but any feedback is welcomed. var util = require('util');
var events = require('events');
var request = require('request');
function apiGet () {
events.EventEmitter.call(this);
}
util.inherits(apiGet, events.EventEmitter);
apiGet.prototype.command = function(options, callback) {
var self = this;
this.api.perform(function() {
setTimeout(function() {
defaultOptions = {
method: 'GET',
json : true,
};
options = Object.assign(defaultOptions, options);
request(options, function(error, response){
if (error) {
console.error(error);
return;
}
if (callback) {
callback(response);
}
});
self.emit('complete');
}, 10);
});
return this;
};
module.exports = apiGet; The call in a test var url = 'http://yourapi.com/api/lookup?query=whatever'
var data;
browser.apiGet({
uri: url,
auth: {
'user': 'username',
'password': 'password123',
},
}, function(response) {
data = response.body;
}); |
Thanks for your response , I have tried like this but I get below error when i run my Code My Requirement is to check Http Response status for all the links present on a web Page instead of clicking and checking each link separately.
Below is Test code , I took an example of facebook url here
|
This issue has been automatically marked as stale because it has not had any recent activity. |
Hi All, When I am using Success function in apipost.js in commands file, Why I am getting Success is not valid function. Please need the help how to overcome this issue. Thanks, |
when doing the request you need to specify all the params not just the ones in the example: then the call is like this if you don't have headers or oath: |
Hey, Did you get it worked? |
After having a lot of struggle to hook in API REST calls in a test scenario, I wanted to share my code.
Based on several discussions on StackOverflow and GitHub (#444), I landed on this result:
1) Install a HTTP client
npm install request --save
PS: I know that there are better HTTP clients but this one works for now
2) Add custom commands
in the
commands
folder, add the following files:PS: I know that there are better manners to implement the Request methods using Promises, but for now it works.
The
apiGet.js
content:The
apiPost.js
content:3) Update nightwatch.json
add the following to your nightwatch config
` "custom_commands_path": "./commands",
Test GET sample
Test POST sample
The text was updated successfully, but these errors were encountered: