 So, I will get straight into it, I have just 30 minutes and open source project that is you can consider this as a backdoor open source project because I work out of backdoor office it may not be obvious from here, as you can see I work for Intuit and I have been there for 5 years and this is a project that I started on the site around 2 years back and as I hopefully demonstrate it is taken on a life of its own, it is reasonably popular and I in fact met a couple of happy Karate users right now so that is amazing to see. What I hope to do in this session is talk about how Karate can be used for API testing, I am sure all of you know what APIs are and I am sure everyone uses APIs and we in Intuit use a lot of APIs and we have this need to test them which is where Karate came from. So, I hope to put them also I am going to be a little brave and I think a big takeaway for you is that Karate is 3-in-1, it is not only a functional testing tool and you may have used functional testing tools already or you can also act as a mock server for APIs. A very new capability which I personally found very exciting, which I hope for those of you who haven't seen this because you can reuse your functional tests as performance tests which actually not many other tools can do. Q&A but I will try depends on how we progress, this is a marketing slide I want to spend too much time on it but obviously you expect from any good framework, it should be easy and fast. One thing that really strikes people who use Karate is the maintainability, very stable and as I will again try to prove if you write test using some competing framework or if you use Java or some programming language then there will be more lines at home and I will try to explain that in a moment. Little bit of background, open source as I said you know I am the primary contributor this is one and half years old as of now, it is a domain specific language and we do a deep dive into it in a moment and it is based on QCumber, how many of you have kind of used QCumber, you are aware of it. In fact at this point how many of you have the need to do API testing right now, this might get a pulse. And what are the tools that you are using, is it rest assured, how many hands, postman so that most of you have used. Are you using postman for automation of your test cases as well like using that human man and all that, probably not right. So this is where actually Karate comes in and kind of competes with postman and it is in my opinion easier and better but you can really touch on that. We are close to 1,000 GitHub stars which I think is a very proud thing again for a project that only did not exist more than one and half years back. You can see already a lot of people have come forward as contributors so your take away is that this is showing every side of being a reputed, popular, healthy open source project. And then again please do contribute if you can, at least use it. I would love for you to go back to your organizations and your friends and really spread the word because hopefully as you see Karate is pretty compelling. One data point before I get into the code and all that again, why should you care about Karate? This was almost 6 months after Karate was released. It was actually rated by one of the prominent test evangelists that it is up there with grapes. You can see all the usual suspects of automation there which was pretty special for all for Karate. So we are getting into code and this is a hello world example of Karate. So for those who haven't seen Karate, I think the first thing that should strike you doesn't look like any programming language that you are used to. This is not Java but that to me is actually one of the selling points of Karate. And for those who used to cover or are aware of BDD, there is this testing theory where you start your scenarios with given where then you have the three phases of testing. You set up something, you do something and then very important, you need assert what has happened is what we are expecting. Json. So again to repeat Karate is a framework for testing web services. All of us have heard of REST. Karate can test XM also we can talk about that. But when you have a lot of Json and most companies I am sure all of you are just dealing with lots of Json nowadays. The beautiful thing about Karate when you compare it with how would you do this in Java? You would have to put double quotes, escape all the other double quotes, put quotes around one of the keys. It's really, really hard to do. You will see examples of that. You can see Karate's design decision to kind of base itself on cucumbers, format, file structure is amazing because you just work with, it's not just Json. This is an immediate Json. That's what I call it, right? This is Json the way that JavaScript program was write Json. No double quotes needed, no quotes around the keys. It's very clean and it's very readable. I keep saying that Karate is a DSM, it's the main specific language and you can see here the thing. Look at the second word on each line. You are on request, method, status, response, paths. It should immediately make sense to anyone who is working with REST. Totally make sense and that is what I like about Karate. It's self-descriptive. I'm very crisp. Another thing I like about this file is that there's no character which is extra, which is unnecessary. Everything makes sense, everything has a reason. And I keep repeating this. One of the biggest drawbacks of most of the testing tools that I have seen out there is the capability to do assertions. This is the most important thing you need to do as someone who is testing something. You need to validate data. This line is very special for two reasons. Again, this is pure Json. You can validate the entire data in one line and this is a hello world I know, but here's your take away. Even if you have this very complicated Json with a lot of nested elements, it's going to work. Karate built to a deep equal. You see the non-null? This is one of the biggest pain points for anyone testing web services. There is a lot of dynamic data that comes back, UU IDs, timestamps, random numbers. You can ignore only those things and test everything else. And that is one of the superpowers of Karate. A lot of people love this. Last but not the least, you never test one API in isolation. You will be always making a sequence of requests. Most typically, your first request is going to be authentication, right? You sign in somewhere, get a token and use that token for all your next requests. And you can see this, even though it's a simple example, it's already calling two web services, right? It's making a request for posts on the third line. And at the end, it's doing a get. And when it's doing a get, it's using data that came from the previous response into the next request. You need to do this all the time if you're testing API. And those that help you do that are needed. So how many of you don't like Java? You guys are going to love this, right? So what you see here is Json, right? Json is great. One of the things as a Java programmer that you envy about JavaScript programmers is that they just put one curly brace and they are working in pure data. Whereas this is what Java programmers are used to. This is a pojo or a class. All those getters and setters. You really need that much code in order to express that data. It's so beautiful in Json. And it gets worse. You're not there yet. You need to instantiate the class and then populate the data. Then only would you reach where you're trying to reach. This line is actually valid karate script. And it's actually doing something pretty complex if you ask me, right? It's testing whether the getters array contains a particular complex object. Not a primitive. If you had to do this in Java, you would have to do some null checks, some code like this. And this is actually a quick and dirty example. If you're writing an enterprise version of this method, you would have to accept the generic cat parameters and all that. And you can see, I'm pretty sure I've made some mistake in this code. And you know, right? And this honestly is what a lot of people do to take for testing web services. Karate came out of the pain I experienced seeing people do this using the rest session and the competition to Karate. So hopefully that makes sense. Some smart Java programmers come, they get very upset when I show them the slide. And they say, you know what, if I implement equals and hash code, I'll be there. But then I show them this. And this is something else that Karate can do. It's actually checking. Not only am I trying to find one kitten, but you're trying to find any kitten whose ID is greater than 25. That is a mathematical expression that Karate supports. I'll talk more about that. And when I show people this, they're kind of, you know, I don't get very convincing answers at this point. So you already noticed that Karate has some special capabilities. It's not, it takes JSON and kind of extends it to these macros or fuzzy matching is what I call it. You can see it already handles a few types. And I'll show you some examples. You can check whether an array contains particular elements. You can check for data types, like number or Boolean string and all that. I think it's one of my favorites. You can imagine this is really, really powerful when you have very complex data coming back. And this is a twist. You know, that's the JavaScript function. And in the next slide you're actually reusing the JavaScript function as part of fuzzy matching. This is really powerful because you can actually define all your JavaScript functions abstract. And then reuse them all across your tests. And that's pretty powerful. Keep that in mind. You've already seen that one of Karate's, I think the thing that really makes Karate special compared to the other solutions out there, the way that it embeds a JavaScript engine. That is something you should really think about. It's pretty cool. For those of you who may be unfortunate enough to be still dealing with XML, again Karate has one of the few tools that actually supports XML almost at the same level as JSON, right? So XPath expressions are no problem. One thing that surprised me personally after I created Karate was a lot of people using Karate out there or are using it for SOAP testing. So clearly there is a gap in the industry for a free alternative to maybe SOAP UI for testing SOAP and a lot of people very happy with it. I won't spend too much time on this slide but again the take away for you and something that I keep saying, Karate is really, really good at assertions on complex JSON. It has a whole lot of special constructs to assert whether an array contains this, whether an array contains partial JSON. So instead of going through all of this, I just show you one example and the documentation of Karate is pretty top notch. You should be able to figure this out. But let's say you have a JSON that is an array with two objects. You only worry about this key value there. You don't want to worry about all the other bloat that you may have on the JSON. The last line allows you to say that that array I don't find any object that has only that key value. Seriously if you had to do this in Java it's going to take you at least 20 lines of work. So it's something that you should really think about. When people see a new framework like Karate, they can get a little worried because yet another framework, I know it works for halloween use cases but you know when you really hit some complex problems but fail and you be stuck, here's the thing. Because of the way that Karate uses the JavaScript engine, it actually allows you to pull any Java code from either the JDK or a class that you wrote and then start working methods and constructors and what not on that class. And this is the amazing part. If redraws in this case returns a hash back on the Java side when it comes back into Karate it becomes a JSON. That's really powerful because what it means is that once you have JSON, Karate is one of the best engines on the planet that can assert the game of JSON. So, yes you have ready reports, if you want parts, ready reports and I can start trying to do a demo. This is intelligent so you will notice we have syntax coloring, that's a good thing. Although Karate is an alien format that is not a programming language because we have based on Cucumber Cucumber has pretty good support in many tools and you can even right click and run a test and you get that same experience like green bar, unit testing reports down that. But let me do one thing, let me show you the parallel test. Parallel testing is really really important for API's. API testing takes much more time than unit tests, we all know that we call some remote API and we wait for the response to come back. Typically, your test suite if you are doing a lot of API testing would be taking minutes, right? Karate is probably one of the few tools that allows you to start multiple threads and run all your tests. It's built into the framework you don't need to fool around with Maven or Jenkins or any other tool it's all built in and people love it and I'll just quickly show you the report. And one of the great things about Karate is that you can see the HTTP requests in line with the report. This is beautiful. Now reports are not very useful when everything is green so let me demo a report failing so I'm going to introduce a typo for the validation, refresh the report you saw by the way you know the log is pretty, the script it tells you hey there's a spelling mistake and all that if I oops yeah, it's refreshed there's one test that failed you can see which test failed very quickly zoomed in and you immediately see what failed all the reasons. You can even look at the HTTP request a percent before this it's all there. Again, I repeat not many tools actually develop this level of flexibility where you see such a good report along with the HTTP papers. And it works even when you run it in parallel. So far we've seen Karate's functional testing capabilities. You can call a service, you can get something back, you can do some 30 good assertions against what you get back. One of the things I love about the Java ecosystem is that thing in the middle it's called NASCon. Some of you may know this is a JavaScript engine that is embedded in the JDK since Java version 8 onwards. It's an amazing place of technology that is what brands the JavaScript, you know, integrating capabilities of Karate and the seamless interlock between Java and JavaScript I just love it. Without that Karate wouldn't exist to be honest. Now, I'm going to talk about two things that are surprises. To me myself, when I started Karate I thought I would end here. It's just good to have functional testing great lot of people use it. But then Karate has an ability to mock an API server. I won't show you that in a minute. And the last thing which is very, very new and really this is something you should be telling people about. There is no other open source tool that does this. And I repeat, if you are a QE person you really, if you haven't heard of this before, this should be pretty compelling. It's something I have been personally wanting in the industry for many years. And it is this. I have an existing functional test case. I want to reuse that same test case as a performance test. And Karate actually takes a design decision to just leverage Gatling for that. And most of you have heard of Gatling. I'm sure in the Java world it's written in Scala. It runs on the chain. It's a very, very good tool for performance testing. The reports are pretty awesome as well. I'll show you that. Mocking is all about it. Some of you have used wire lock. I'm sure if you are in the Java space. And I've already given you an idea that Karate has this amazing ability to express JSON in a clean way. And not just express JSON. You have this. If you see that UUID call there you can inject some dynamic nature into JSON in a very, very powerful way. That works. Because of the lack of time this demo is explained in detail in a blog post that you can find from the Karate documentation. The last two lines are using state which has been set up. The depth catch is a variable that takes a JSON. It's an empty JSON to start with. As and when post requests are coming in, that happens. And at the end when you make another call to this mock you will see the state of anything that has happened. This is very difficult to do. And here's another shocking thing which I will dare to say here. What you're looking at is actually almost like a replacement for Toncat for Node.js and Express and all that. It's a very strong statement to make. We don't care about maybe performance to that extent. But if you want to create a horrible service and reuse some complicated JSON in a few minutes this is going to work really well for you. Okay. Mock is important because in many times all the QE people will identify this. You don't have control of somebody's test environment. That service is not available. It is flaky. That's when you use this mock. You stand up the mock in your local service, all your integration against it and you know there's not more I can talk about this but in the interest of time we would stop here do quick demo so you can see what the mock looks like and let's see how that goes. And there's a mock.feature that we're going to run. Before this let me stop one of these servers I have started for a demo because that's running on port 8080. What I'm doing is I'm invoking a Karate.jar and that is a single binary X20MD that has entire Karate bundled into it. So if you are part of a team that doesn't want to touch Java you can use this way of using Karate. Alright. That's the world's fastest startup of an HTTP server and if I open in you let me know one thing. Let me open this HTML file something. You can see it's actually making requests and if I open a new tab to look at a get request to the server you're seeing all the JSON come back. It's just working. I just want to show you one more thing before I go to Katrin which is the Karate UI you can actually run a test from this interface but I'm going to show you something very very cool if you are again someone who is testing web services let me reset and introduce the type or here. What I'm going to do is something you cannot do even in Java when you debug which is I'm going to fix the test case and I'm going to re-run that step. I'm actually going to go one step back and replay it and all the state is maintained and it's green right and then I can go to the end and continue my test. This is super huge because if you are testing web services one of the biggest things you keep doing is that you would be working in the last part of your test case and you would be re-run everything from the start where you can log and sign in and you just save time here. I have 5 minutes so the last thing to demo is the Katrin demo that's going to be quick with no Katrin you know that you have to write performance test scripts in Scala and it's actually quite complex you need to know Scala really well in order to write some reasonably good test cases but you can see this performance test is actually re-using 100% two existing Karate test cases and you can run them in parallel you can define the number of users content in the world what not so this is set up and I'm going to run this right now maybe clean tests it's something the Java programmer does for a lifetime and yes it's actually kicking off a Katrin test Katrin is a separate framework but again I repeat it's one of the world's best frameworks for performance testing and I'm going to show you the reports in a moment and we are re-using Karate tests I have deliberately introduced one of the errors because remember Karate is great at assertions one of the test steps is designed to fail the way Katrin works is it prints the file of the URL at the end to the browser is a pretty beautiful port because of the Karate integration it actually tells you the line number of what failed new Katrin test and what their message was yes if you haven't used Katrin you should check it out it's pretty awesome you can drill down to all kinds of things you can see which was the slowest call and all that alright so I just did the demo my last slide again your take away is that please do go and spread the word to your teams all of you must be using web services in your organizations this is a new tool but I think as hopefully I've demonstrated this this actually a tool that shows great promise and again a plug this is a Bangalore open source project so you have every reason to contribute and you know make us proud in a sense comprehensive STTP support functional testing mocks which are very useful if you really came in for advanced testing and performance testing I have one minute to take questions or we can certainly meet after this I'll be around for some time how should you compare it with your postman compare it with postman very quickly two things assertions postman is not as good right if you have a big chase one coming back and you want to do assertions and ignore fields and if you have this complex arrays and contains things very difficult to do in postman number two reason if you wanted to automation of postman if you want to run them under Jenkins and especially to parallel testing Karate is forward thank you very much