I'm relatively new to end to end testing with Protractor, Mocha and Yadda (for integration with Mocha so I can use Gherkin and step definitions).
I've seen a plugin called Mochawesome which generates an HTML report which can be viewed offline, along with this JSON object of the test results, all of which contained in a 'reports' folder.
I presume it's Mochawesome which generates these JSON objects as the HTML page seems to have corresponding tags etc. Is there any way to generate a JSON object of the tests ran without the HTML reporter? The idea was to create my own sort of 'dashboard' containing information about the tests based on the JSON information.
Yes you can create a JSON report of your specs/tests with protractor.You just have to put resultJsonOutputFile: './Report.json' in your config file.
your config file should somewhat look like this:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://juliemr.github.io/protractor-demo/',
framework: 'jasmine2',
specs: ['*spec.js '],
allScriptsTimeout: 180000,
getPageTimeout: 180000,
jasmineNodeOpts: {
defaultTimeoutInterval: 180000
},
resultJsonOutputFile: './Report.json', // It would create report.json file in your current folder
onPrepare: function () {
browser.driver.manage().window().maximize();
browser.ignoreSynchronization = true;
}
};
You can consume this json report and use it in your way!
I'm not sure about generating JSON object directly in protractor. But what i know is that, we can generate results in XML and then convert xml to json by writing some customized code.
Code for generating XML reports are as follows:
framework: "jasmine2",
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters'),
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
savePath: '../result/',
filePrefix: ‘report’,
consolidateAll: true
});
);
},
Related
I want to keep my test data in a JSON file that I need to import in cucumber-protractor custom framework. I read we can directly require a JSON file or even use protractor params. However that doesn't work. I don't see the JSON file listed when requiring from a particular folder.
testdata.json
{
"name":"testdata",
"version":"1.0.0",
"username":"1020201",
"password":"1020201"
}
Code in the Config.js
onPrepare: function() {
var data = require('./testdata.json');
},
I don't see the testdata.json file when giving path in require though its available at the location.
I wish to access JSON data using data.name, data.version etc.
Following is my folder structure:
You should make sure your json file is located in the current directory & and in the same folder where your config file resides as you are giving this path require('./testdata.json'); -
There are many ways of setting your data variables and accessing them globally in your test scripts -
1st method: Preferred method is to use node's global object -
onPrepare: function() {
global.data = require('./testdata.json');
},
Now you could access data anywhere in your scripts.
2nd Method Is to use protractor's param object -
exports.config = {
params: {
data: require('./testdata.json');
}
};
you can then access it in the specs/test scripts using browser.params.data
I am using the example provided on the chimp website for gulp-chimp
gulp.task('chimp-options', () => {
return chimp({
features: './features',
browser: 'phantomjs',
singleRun: true,
debug: false,
output: {
screenshotsPath: './screenshots',
jsonOutput: './cucumber.json',
},
htmlReport: {
enable: true,
jsonFile: './e2e_output/cucumber.json',
output: './e2e_output/report/cucumber.html',
reportSuiteAsScenarios: true,
launchReport: true,
}
});
});
the problem i have and that it's killing me is that when I run gulp chimp-options i get :
Unable to parse cucumberjs output into json: './e2e_output/cucumber.json' SyntaxError: ./e2e_output/cucumber.json: Unexpected end of JSON input
What am I doing wrong ?
I believe chimp is just a wrapper on multiple frameworks/libraries out there and I'm pretty sure they just use cucumber-html-reporter to generate its HTML reports.
If you still can't get it working automatically via chimp, just generate the options file as usual and npm install cucumber-html-reporter and then use it to generate the same report.
Create a separate file called generate_html_report.js and paste in the code under Usage. Then add this to your npm script to run after your test suite has finished. I'd avoid putting it in your afterHooks as I've had issues in the past where the JSON file hadn't been completely generated before it tries to run the script expecting the JSON file to be there.
I am using Typeahead Bootstrap in a form field (with a WP framework).
I have a .json file stored in my root, which I can grab using prefetch:
prefetch: {
url: '
../json/test.json',
ttl: 1
}
menu works just fine. Now, let's say I dont want to use prefetch, but load the datum in a local json array.
I have the same json file that looks like:
[{"title":"Title 1","content":"Loopty loos"},{"title":"Title 2","content":"Diddly Bones"}]
If I load that directly into the new Bloodhound class:
local: [{"title":"Title 1","content":"Loopty loos"},{"title":"Title 2","content":"Diddly Bones"}]
again, works like a charm. However, if I try to load the same data in as a variable, rather than explicitly written:
jsonObject = [{"title":"Title 1","content":"Loopty loos"},{"title":"Title 2","content":"Diddly Bones"}]
var content = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.content);
},
local: jsonObject
...
It doesn't work. This seems like it's something simple and I am just completely missing it.
Full clarification, I am querying the wp database, and with that result set creating the json file and writing it to the test directory, then passing it to a .js file using wp_localize_script.
After declaring Bloodhound object, try to initialize the object.
var content = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.content);
},
local: jsonObject
...
})
content.initialize();
I want to use grunt-hash plugin for renaming my js files.
This plugin create a new file containing map of renamed files:
hash: {
options: {
mapping: 'examples/assets.json', //mapping file so your server can serve the right files
Now I need to fix links to this files by replacing all usages (rename 'index.js' to 'index-{hash}.js') so I want to use grunt-text-replace plugin.
According to documentation I need to cofigure replacements:
replace: {
example: {
replacements: [{
from: 'Red', // string replacement
to: 'Blue'
}]
}
}
How could I read json mapping file to get {hash} values for each file and provide them to replace task?
grunt.file.readJSON('your-file.json')
is probably what you are looking for.
I've set up a little test. I have a simple JSON file 'mapping.json', which contains the following JSON object:
{
"mapping": [
{"file": "foo.txt"},
{"file": "bar.txt"}
]
}
In my Gruntfile.js I've written the following simple test task, which reads the first object in the 'mapping'-array:
grunt.registerTask('doStuff', 'do some stuff.', function() {
mapping = grunt.file.readJSON('mapping.json');
grunt.log.write(mapping.mapping[0]["file"]).ok();
});
When invoking the Grunt task, the console output will be as follows:
$ grunt doStuff
Running "doStuff" task
foo.txtOK
Done, without errors.
I hope this helps! :)
I have created a WebAPI using .Net 4.5 and want to document this API using Swagger.
I have added swagger-ui in my .Net project. Now when i browse to ../swagger-ui/index.html it successfully opens pet store api-docs (json) in swagger UI format.
My question is how can I create such (swagger) json for my WebAPI controllers and models? As I have put in required XML summaries/comments to c# classes and attributes.
I saw that Swagger.Net and Swashbuckle are there doing similar things but I could not really understand how to generate swagger-json file using any of them. There might be very small mistake I am doing but unable to point out.
Please help.
As stated, /swagger takes you to the swagger UI.
If you're using Swashbuckle, then /swagger/docs/v1 should take you to the swagger.json file - I found this using Chrome Dev tools.
Edit: if you're using Swashbuckle.AspNetCore, then the url is slightly different - /swagger/v1/swagger.json
You need to integrate Swagger.NET into your project so that you end up with the following controller:
public class SwaggerController : ApiController { /* snip */ }
and you should also have the following route registered:
context.Routes.MapHttpRoute (
name : "Swagger",
routeTemplate: "api/swagger"
defaults: new
{
controller = "Swagger",
action = "Get",
});
assuming that is working you should be able to call /api/swagger and get something like the following:
{
apiVersion: "4.0.0.0",
swaggerVersion: "2.0",
basePath: "http://localhost:5555",
resourcePath: null,
apis: [
{
path: "/api/docs/Values",
description: "No Documentation Found.",
operations: [ ]
},
{
path: "/api/docs/Home",
description: "No Documentation Found.",
operations: [ ]
}
]
}
then in SwaggerUI/index.html you'll want to update the discoveryUrl:
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl: "http://localhost:5555/api/swagger",
apiKey:"",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put']
});
window.swaggerUi.load();
});
</script>
You can use "NSwagStudio" desktop application to load the json document without running the api project.
By providing the api assembly.
https://github.com/RSuter/NSwag/wiki/NSwagStudio
Download the (NSwagStudio) windows desktop application.