Coder Social home page Coder Social logo

Data driven test using Frisbyjs about frisby HOT 8 CLOSED

vlucas avatar vlucas commented on August 29, 2024
Data driven test using Frisbyjs

from frisby.

Comments (8)

damehta avatar damehta commented on August 29, 2024

+1

from frisby.

vlucas avatar vlucas commented on August 29, 2024

I'm sure you could, but I'm not sure how it would look. Can you give me any examples of the type of thing you are looking for?

from frisby.

damehta avatar damehta commented on August 29, 2024

For example: I am looking to get student details by making REST call by passing studentId parameter to my api method. In this case I imagine to have studentId in tabular format in xlsx file. The for each row in xlsx file make a rest call & validate expected response data.
Pls Let me know if you need more specific details. TIA.

from frisby.

damehta avatar damehta commented on August 29, 2024

Want to do something similar to what is explained here in "Scenario Outlines" section: http://docs.behat.org/guides/1.gherkin.html

from frisby.

damehta avatar damehta commented on August 29, 2024
  • Below is my pseudo code that I am trying to read CSV file and make API request using data from each row in csv file.
  • Upon execution of this code, I get my console logs as expected. It reads csv file content and returns array. I can iterate array with recursive callbacks. However, I am not getting any api responses nor I am getting any verification done. No errors even.
  • Here is the console output: Finished in 0.001 seconds
    0 tests, 0 assertions, 0 failures, 0 skipped

File - short.csv:
Tag Title Status
1 api method 1 200
2 api method 2 200

File - test_spec.js:
var csv = require("fast-csv");
var fs = require('fs');
var frisby = require('frisby');
var stream = fs.createReadStream("short.csv");

var dataTable = new Array();
var i=0;
var api_key = "f4a0b09fb912ccde933ed42b2776ed8a";

csv(stream, {headers : ["Tag", "Title", "Status"]})
.on("data", function(data){
// console.log(data);
dataTable[i++] = data;
}) // End of csv.on
.on("end", function(){
console.log("done reading CSV into an array");
// for(var j=0; j < dataTable.length; j++)
// console.log("dataTable Title: " + dataTable[j].Title.toString() + " - Status: " + dataTable[j].Status.toString());

function recursive (dt,next){
   var curr = dt.pop();
   console.log("curr Tag: " + curr.Tag + " curr Title: " + curr.Title);
   if (curr != null){
       callApi(curr,function(){
            console.log("Recursive callApi for Next value in array");
            next(dt);
       })
   }
} // End of recursive function

recursive(dataTable, recursive);

function callApi(curr, callback){
    console.log("Current API "+ dataTable.length);
    console.log("Current Tag: " + curr.Tag + " - Title: " + curr.Title.toString() + " - Status: " + curr.Status.toString());
            frisby.create('Get myapi.getInfo')
            .get('http://localhost:8080/services/rest/?method=myapi.getInfo&api_key='+api_key+'&format=json&nojsoncallback=1')
            .inspectStatus()
            .expectStatus(200)
            .inspectHeaders()
            .expectHeaderContains('content-type','application/json')
            .after(callback()) // callback after api response
            .toss()
} // End of callApi

}) // End of csv.on
.parse();

from frisby.

lyxsus avatar lyxsus commented on August 29, 2024

+1

Need that one to test uncommon authorization calls sequence.

from frisby.

namuol avatar namuol commented on August 29, 2024

API Blueprint might be what you're looking for. It's mostly meant for documenting an API, but can also be used as a tool to describe API tests declaratively using a tool called dredd.

dredd is interesting but not really feature-complete, which is why I'm using frisby.

But thankfully, the APIary folks have a module for parsing the API Blueprint format already; there is a node binding for it called protagonist.

Using this, one should be able to translate the markdown-esque format of API Blueprints into a JSON format, and from there it should be pretty easy to call the necessary frisby commands based on this data.

Not a bad idea, really.

from frisby.

vlucas avatar vlucas commented on August 29, 2024

This is now much more possible with v2 since you can just return the Frisby spec object from the test, and since it doesn't call any Jasmine describe/it functions directly anymore. Please update to v2 and try it out.

from frisby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.