michaelkeeling / cucumber-rest-api-assistant Goto Github PK
View Code? Open in Web Editor NEWA set of step functions to help test REST based web services
License: MIT License
A set of step functions to help test REST based web services
License: MIT License
Occasionally a response will be returned which has characters that cannot be converted to UTF-8. I've hit this issue frequently when using debugging and depending on the response this tests in examples.feature
will throw it.
Scenario: Use shorthand to save response values for reuse
Given a GET request is sent to 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
And the value of '0' in the response is saved in a key called 'some_identifier'
And a GET request is sent to 'https://hacker-news.firebaseio.com/v0/item/{some_identifier}.json?print=pretty'
Then the response is successful
And the response code is 200
Which will throw the error:
And a GET request is sent to 'https://hacker-news.firebaseio.com/v0/item/{some_identifier}.json?print=pretty' # lib/cucumber-api-assistant/request_steps.rb:144
"\xE2" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
features/example.feature:141:in `And a GET request is sent to 'https://hacker-news.firebaseio.com/v0/item/{some_identifier}.json?print=pretty''
There seem to be lots of opinions out there on how to address this so I didn't attempt a quick fix.
The specific line of code throwing this error is in scenario_to_documentation.rb
File.open(output, 'w') { |file|
file.write(content) # <<<<< Right here
}
I think this can be fixed by changing the File.open
params to wb+
File.open(output, 'wb+') { |file|
file.write(content)
}
This is up for discussion. But I think in most cases a user of this gem won't want documentation to be generated on each test run since it adds lots of output to the logs and the terminal.
Some APIs require that extremely large amounts of data be posted. These APIs accept form data as their request. We need a way to post form data from a file. Why load this data from a file? We don't want to put a huge payload in the feature file.
We should create a new step that allows for this to happen.
Not sure if you saw this in the steps file for FE API but I did something like this for json formatted files
Given(/^the request body is set from the file '(.+)'$/) do |path|
file_stuff = File.read(path)
my_output = JSON.parse(file_stuff)
#DEBUG: Leaving the below statement for now in case there are problems again
#with the sub step.
#@request_body = my_output.to_json
step "the json request body is #{my_output.to_json}"
end
It's not for form data but it's probably something close to this.
URIs should be properly encoded. If a value with a space is passed in via a template (or used directly) then we attempt to use it as is and Excon throws an exception. This can give a false negative on a test, or at least makes it not obvious that the failure happened as a result of a bad step function vs. the subject under test.
The request_steps.rb:190
file defines a step for checking a JSON field's value: "the <name> field in the response contains <value>"
. The code checks for equality, but "contains" is usually used for a substring comparison.
Both seem useful; maybe the existing "contains" step could be changed to do a containment check, while a new step using the word "equals" would do the current equality check.
I'd like to be able to use simple syntax when referring to an endpoint (or and enpoint_template) which expects the base_url to be set. The only way I know to do this is through an environment variable but maybe there is another way.
When(/^a (GET|POST|PATCH|PUT|DELETE) request is sent to the endpoint '(.+)'$/) do |verb, endpoint|
base_url = ENV['BASE_URL']
step "a #{verb} request is sent to '#{base_url}#{endpoint}'"
end
cucumber-api-assistant/request_steps.rb has a method:
Then /^the '(.+)' field in the response has a value$/ do |field|
expect(@response.body).not_to be_empty
value = CucumberApiAssistant::Helpers.fetch_from_JSON_with_shorthand(field, @response.body)
expect(value.size).to be > 0
end
For a field with float value, like:
"percent_used": 8.96
the method crashes with error
undefined method `size' for 10.97:Float (NoMethodError)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.