API Automation Testing Full Course | JavaScript API Automation

Sdílet
Vložit
  • čas přidán 7. 07. 2024
  • #automationbro #javascript #apiautomation
    How to do API Automation Testing using Javascript with Supertest & Mocha? In this full course, I'll walk you through that step-by-step to get your Javascript API Automation framework ready.
    Github Repo - github.com/dilpreetj/JavaScri...
    So let's take a look at what we will be covering in this series:
    - Basics: Check out this video series to learn API Basics - • API basics for beginners
    - Installation / Configuration
    - Write API automation tests with Javascript using Mocha, Chai JS, and SuperTest HTTP Library
    - Scale API automation test framework
    ○Writing advanced integration tests
    § Learn how hooks work and when to use it
    § Write some negative tests to increase our test coverage
    - Generate fake test data to make tests more dynamic
    - Generate HTML reports using Mochawesome reporter
    - Integrate tests with Jenkins
    Note: this video is the consolidation of my JavaScript API Automation video playlist - • Javascript API Testing...
    🔗 Check video Resources in the description of the links attached below:
    - Library & Frameworks: • Which libraries or fra...
    - Installation: • Installation / Setup -...
    - Write your first API Test: • Write your first API t...
    - HTTP GET method: • API Tests for HTTP GET...
    - HTTP POST method: • API Tests for HTTP POS...
    - HTTP PUT method: • API Tests for HTTP PUT...
    - HTTP DELETE method: • API Tests for HTTP DEL...
    - API Tests Optimization: • API Tests Optimization...
    - Using Async/Await with Supertest: • Using Async-Await with...
    - Write negative API test: • Writing Negative API T...
    - Config & Random data: • API Tests Optimization...
    - Mochawesome Reporter: • Mochawesome Reporter |...
    - Jenkins Integration: • API Tests Jenkins Inte...
    📧 Subscribe to my mailing list for all the latest updates as well as get access to Private Facebook Community -
    automationbro.com/mailing-list
    ✒️ Check out my blogs at - automationbro.com
    🚀 Enjoying my content and would like to support my work? Why not buy me a coffee! or Subscribe to this channel! 🚀
    www.buymeacoffee.com/automati...
    www.youtube.com/@dilpreetjoha...
    Chapters:
    0:00 - API Automation Testing Full Course Introduction
    1:39 - Which libraries & frameworks to use for Javascript API Automation
    7:33 - Installation & Setup
    13:12 - Write your first API test using Javascript
    27:37 - API tests for HTTP GET method
    39:02 - API tests for HTTP POST method
    50:44 - API tests for HTTP PUT method
    59:26 - API tests for HTTP DELETE method
    1:04:50 - API Tests Optimization
    1:16:58 - Using Async/Await with Supertest
    1:36:15 - Writing negative API tests
    2:00:09 - Mochawesome Reporter
    2:07:31 - API tests Jenkins Integration
    2:21:04 - Course Wrapup
    Follow me on other social platforms:
    🔗 Twitter: bit.ly/dilpreet-twitter
    🔗 LinkedIn: bit.ly/sdet-u-linkedin
    🔗 Dev.to: dev.to/automationbro
    Thanks for watching :)
    Automation Bro
  • Věda a technologie

Komentáře • 96

  • @sdetunicorns
    @sdetunicorns  Před rokem

    Check out all the Courses - bit.ly/sdet-u-academy
    Join Mailing List - bit.ly/sdet-u-mailing-list
    If you like this video, make sure to subscribe to the channel and share this video :)

    • @user-nt7kp9vq1h
      @user-nt7kp9vq1h Před 23 dny

      Hey I keep getting the following error:
      Exception during run: Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\tuboo\Desktop\super-api-test
      ode_modules\chai\chai.js from C:\Users\tuboo\Desktop\super-api-test\test\user.js not supported.
      Instead change the require of chai.js in C:\Users\tuboo\Desktop\super-api-test\test\user.js to a dynamic import() which is available in all CommonJS modules.
      at Object.newLoader [as .js] (C:\Users\tuboo\Desktop\super-api-test
      ode_modules\pirates\lib\index.js:121:7)
      This is 2024, i've tried everything possible, no luck still, i know it has to do with the way i Imported chai for assertion... any suggestions please?

  • @sunmoon1414
    @sunmoon1414 Před 2 lety

    Amazing and extremally useful video. Thank you!

  • @nadiaerdynieva8534
    @nadiaerdynieva8534 Před 2 lety

    Amazing tutorial!!! So clear and concise. Thank you so much, Dilpreet

    • @adam1320
      @adam1320 Před rokem +1

      Huh sounds too amazing for buryat people ?

  • @mornemarais4198
    @mornemarais4198 Před 2 lety

    love it brew!!

  • @tranquocthanh949
    @tranquocthanh949 Před 2 lety

    Love the content so muchhhh!

  • @alinamozol2385
    @alinamozol2385 Před 2 lety +1

    Thanks!

    • @sdetunicorns
      @sdetunicorns  Před rokem

      Glad you enjoyed the content. We have created multiple courses that takes our students from ground level. If you want to become a full stack Automation engineer, Please check out the academy at: sdetunicorns.com/courses/

  • @sweetthirty2
    @sweetthirty2 Před rokem

    Wow u r gr8🙏

    • @sdetunicorns
      @sdetunicorns  Před rokem

      Thank you! Stay tuned for more exciting things related to API test automation.

  • @uniqueramya3632
    @uniqueramya3632 Před 2 lety

    Thank you Automation Bro. Much helpful. Can you tell how can we read the JSON file in supertest and pass it to POST request body? I have a request body that has 100 lines of data. My idea is to read the JSON file from the local drive and pass it to the post command. How can we do this?

  • @criscarlod
    @criscarlod Před 2 lety +1

    Hi Bro, Is this applicable for now? the API link URL has updated to version 2

  • @MrDaz1184
    @MrDaz1184 Před 2 lety

    Using Async/Await section, I was getting the Error:
    User Post
    "before all" hook for "/posts":
    TypeError: (0 , _user_helper.createRandonUser) is not a function
    To fix this I had to change the user_helper export to "module.exports.createRandomUser.."
    Hope this helps anyone else that may come across the same error when following along :)
    Dilpreet, awesome content and so clear and precise! I will look further into why I needed to add module for it to work as its not the first time I've come across this, for which I come across something similar with ava (from what I've seen so far the export is to allow something to be public), but any pointers into the right direction to get a better understanding would be great, I suspect this is related to nodejs with modules and versions of ES, and certain packages (I could be wrong), but I will be sure to do some further learnings after finishing this tut. Thank you for the awesome content!

  • @mandarajgaonkar9003
    @mandarajgaonkar9003 Před 2 lety

    This is exactly what I wanted to implement in my project. Thanks for this video.
    Is there any documentation available for Chai and Mocha? There are few more things i need to understand before I start working.

    • @sdetunicorns
      @sdetunicorns  Před 2 lety +1

      You can find the docs here -
      - mochajs.org/
      - www.chaijs.com/

  • @etrajnime1791
    @etrajnime1791 Před 3 lety

    I'm very new to testing, and they told me to learn more about performance, load and stress testing. What do you suggest me to do?!
    Can you explain it in short terms what it is, what are the best tools to use etc... I'm more in javascript langugage. Thanks!

    • @sdetunicorns
      @sdetunicorns  Před 3 lety +1

      Hey, you can look into JMeter to do performance and load testing. It's quite easy to setup and there are multiple resources out there already as well.

  • @minakshifarakate2673
    @minakshifarakate2673 Před 2 lety

    When I tried to log response body it's returning as [object, object]...But all assertion get passes

  • @hasankarimjonov8604
    @hasankarimjonov8604 Před 2 lety

    Thanks for the video Dilpreet.
    When I write blocks it or descripe(on vs code) there is not pasted automatically brackets or other symbvols. How to correct set up plugin?

    • @rob6rr
      @rob6rr Před rokem

      I had the same problem. I think the video needs a bit more details regarding the setup steps and any extensions that might be needed.
      The following worked for me to fix this.
      In vs code. View >extensions
      Add the following extensions
      Mocha snippets
      Es6 mocha snippets
      Once these are added the following statements should complete with intellisense.
      dsc - enter: completes a describe block
      It - enter: completes an it block
      Describe and it - enter: completes a describe and it block in one operation

  • @hapham5500
    @hapham5500 Před 2 lety

    I got the error TypeError: Cannot read property 'gender' of undefined all time when running npm test. Can anyone help me? Thanks so much

  • @MyDIVYENDU
    @MyDIVYENDU Před 2 měsíci

    Hello, can you also add jsonSchema validation in the existing project, it will be helpful.

  • @hasankarimjonov8604
    @hasankarimjonov8604 Před 2 lety +1

    Some times I get the error "Error: Timeout of 2000ms exceeded.". If any one get the same error just add on the end of descripe block timeout(10000).
    describe('nameOfDescribe', () => {}).timeout(10000).

  • @user-ez1fj6km8y
    @user-ez1fj6km8y Před rokem

    I was given an assignment for a Job Interview! I completed it with the help of this course and I got a call for the next round :) Now I am prepping for it! Thanks @dilpreetjohal

    • @sdetunicorns
      @sdetunicorns  Před rokem

      That's amazing! I am glad this video helped you out to prep for your interview. Good luck in the next round :)

  • @manasatweets3994
    @manasatweets3994 Před 2 lety

    Thanks for the detail video on API autoamtion i have limitied knowledge on this ,but with this am able to get knowledge and able to relate to the project,tq u so much can i get the reply from u having few more doubts can i ask on api automation

    • @sdetunicorns
      @sdetunicorns  Před 2 lety

      That's good to hear! Sure, what doubts do you have?

    • @manasatweets3994
      @manasatweets3994 Před 2 lety

      @@sdetunicornsI would like to connect on the existed project framework,as one here to help found ur videos

  • @mangatjass
    @mangatjass Před 2 lety +1

    Can you please make a video on using the basic auth instead of bearer token

  • @richardmeadows1706
    @richardmeadows1706 Před 3 lety +1

    Are there plans to create a video that uses Oauth 2.0 to authenticate? That would be super useful.

    • @sdetunicorns
      @sdetunicorns  Před 3 lety +1

      I have added that in the list, will look into creating one in the future.

  • @swatikakkar4967
    @swatikakkar4967 Před 2 lety

    is deserialization of response possible in this framework? Like in Java Rest Assured.

    • @sdetunicorns
      @sdetunicorns  Před 2 lety

      No that is not required here as you can directly access and manipulate JSON data with JavaScript.

  • @mohsinshaikh9994
    @mohsinshaikh9994 Před 2 lety

    I am getting following error :
    Assertion failed: new_time >= loop->time, file c:\ws\deps\uv\src\win\core.c, line 39

  • @pradeepkumar123ful
    @pradeepkumar123ful Před 3 lety

    Hello daljit I have doubt .
    1. Why you use Babel here . Balel use for transfer ES6+ code to ES5 code for old browser but why you install and configure babel

    • @sdetunicorns
      @sdetunicorns  Před 3 lety +4

      Hi Pradeep, first off my name is Dilpreet (not daljit) :)
      Second, since we are using ES6 code such as import statements we need to use babel to support that. There are other workarounds that we can do to avoid that but simply using babel makes it easy to use both import and require statements.

    • @pradeepkumar123ful
      @pradeepkumar123ful Před 3 lety

      @@sdetunicorns Thankx for cleaning my doubts it's helpful.greatfull for such awesome valuable content.

  • @sf4a220
    @sf4a220 Před 3 lety

    Hi Bro, How to make Curl request I need to use Curl . With super test. And I am new to Api testing .can you help me

    • @sdetunicorns
      @sdetunicorns  Před 3 lety +1

      Hi, curl request is simply an HTTP request which you can do with SuperTest itself. You can watch this course to learn how to make different kinds of HTTP request.

  • @debjanighosh5947
    @debjanighosh5947 Před rokem

    Hi Dilpreet, Thanks a ton for this amazing video. I have one question here, I have to also define header things as we define in postman tool. so where shall I define them in the user file ?
    Thanking you in advance

    • @sdetunicorns
      @sdetunicorns  Před rokem

      In Supertest, you can define headers for a request using the .set() method. This method sets a header value for the next request to be sent. You can chain multiple .set() methods to set multiple headers for the same request. You can find examples here - www.npmjs.com/package/supertest

    • @debjanighosh5947
      @debjanighosh5947 Před rokem

      @@sdetunicorns Thanks for your prompt reply. I will do the changes and will let you know about this.

    • @debjanighosh5947
      @debjanighosh5947 Před rokem

      @@sdetunicorns I have set the header value as return request
      .post('loginUser')
      .set(('Accept','application/json'),('Content-Length',[500]),('Host',[600]))
      .send(data)
      .then((res) => {
      console.log(res.body.accessToken);
      in postman(Header) : Content-Type: application/json
      Content-Length:
      Host:
      Error in Javascript: TypeError: Header name must be a valid HTTP token ["application/json"]
      please let me know what is wrong I am making here

  • @thienphongvu2452
    @thienphongvu2452 Před 2 lety

    Does anyone has issue with npm: command not found ? I am very new with Jenkins

    • @sdetunicorns
      @sdetunicorns  Před 2 lety

      That's because you need to get NodeJS plugin installed in your Jenkins first and then you will be able to run the npm command.

  • @K_H-Channel
    @K_H-Channel Před rokem

    Hi, Could you please tell me what I need to do to create this framework in TypeScript? Thank you

    • @sdetunicorns
      @sdetunicorns  Před rokem

      All these libraries are supported with TS as well, so you don't need to do anything different for TS.

    • @K_H-Channel
      @K_H-Channel Před rokem

      @@sdetunicorns Do I still need babel with ts? What do I need to install differently to do this in ts? Thanks.

    • @sdetunicorns
      @sdetunicorns  Před rokem

      Well that depends on your project needs but in general you would not use Babel, just TS compiler is sufficient.

  • @ranjitumakanthan994
    @ranjitumakanthan994 Před 2 lety

    Hi @39.40 I am getting error as TypeError: res.body.data.forEach is not a function . Any idea Why this error occurs? I followed all your steps

    • @sdetunicorns
      @sdetunicorns  Před 2 lety +1

      You can try to print out what you are getting for - res.body.data and troubleshoot from there

    • @ranjitumakanthan994
      @ranjitumakanthan994 Před 2 lety +2

      @@sdetunicorns Got it, I changed the res.body.data to Array.from(res.body.data) and now that works. Thanks for your response

  • @Bored-Panda
    @Bored-Panda Před 2 lety

    Hi Dilpreet,
    Thanks for the video. I need to implement my framework so that we can run the scripts in different environments by providing an environment parameter through cli or any other way. Would you know how this can be implemented in supertest + mocha. I am using the same stack as your tutorial.
    Thanks in advance.

    • @sdetunicorns
      @sdetunicorns  Před 2 lety +3

      Hi, you can use process.env.BASE_URL and then through CLI you can pass in your BASE_URL dynamically

    • @Bored-Panda
      @Bored-Panda Před 2 lety

      @@sdetunicorns Thanks for your response!

  • @satyajitligade2840
    @satyajitligade2840 Před 2 lety

    People say that learn Java for API Automation testing most of companies use that. What should I do? Do I need to learn JavaScript for API automation orJava?

    • @sdetunicorns
      @sdetunicorns  Před 2 lety +1

      It's not the language that matters, it's about understanding the concepts behind API Automation and learning best practices. Once you know that, you can pick any language of your choice to automate it.

  • @mohamedfazil9237
    @mohamedfazil9237 Před 2 lety

    How can i use axios instead of super test

    • @sdetunicorns
      @sdetunicorns  Před 2 lety +1

      Install axios and everything else will pretty much same

  • @vidmeelabs9688
    @vidmeelabs9688 Před 2 lety

    Hi, I ran my test on GET /users. I see my test passing but cannot see response body :(
    My response looks like :
    null
    {}

    • @vidmeelabs9688
      @vidmeelabs9688 Před 2 lety

      Do you know the reason why my response body is blank ?

    • @sdetunicorns
      @sdetunicorns  Před 2 lety

      can you please share your entire request url?

  • @amitmistry1845
    @amitmistry1845 Před 2 lety

    Hi, I am trying to run the first test itself!!It is giving me an error 'SyntaxError: Cannot use import statement outside a module'. Could you please help me. I am new to API Testing

    • @sdetunicorns
      @sdetunicorns  Před 2 lety

      You need to make sure you have babel installed and setup. It's included in the video 09:53.

    • @amitmistry1845
      @amitmistry1845 Před 2 lety

      @@sdetunicorns Hi yeah I have everything installled already!! I figured out the problem. The problem was actually in the extension of the user.js file. It shud be mjs due to the ES6 update. If I want to use the .js extension then I need to enter the "type module" in the package json file.

    • @amitmistry1845
      @amitmistry1845 Před 2 lety

      But thank you for your timely reply!! I have not followed the entire video yet but so far it is good. But I am somehow not getting the entire json log as you are getting at 21.13. Perhaps you could tell me how could I view that. As the test is passing but there is no json log displayed.

  • @piyushmathpal4244
    @piyushmathpal4244 Před 3 lety

    Can you please make a video on API testing using AXIOS library?

  • @rekhaaswani562
    @rekhaaswani562 Před rokem

    Can you please share git hub repo for this framework.

    • @sdetunicorns
      @sdetunicorns  Před rokem

      There you go - github.com/automationbro/JavaScript-API-Automation-Tests

    • @rekhaaswani562
      @rekhaaswani562 Před rokem

      @@sdetunicorns Thanks alot !!!!

  • @kalyanchakravarthy7904
    @kalyanchakravarthy7904 Před 2 lety +1

    @23:15 >> seeing this error 'Uncaught AssertionError: .empty was passed non-string primitive undefined'

  • @akshayhalurkar4859
    @akshayhalurkar4859 Před rokem +1

    Hi Dilpreet
    How can we rerun a specific test case if it fails because of 500 issue?

    • @sdetunicorns
      @sdetunicorns  Před rokem

      You can add this.retries(3); inside your it or describe block and it will retry on failure automatically.

    • @akshayhalurkar4859
      @akshayhalurkar4859 Před rokem

      @@sdetunicorns i tried doing that but it still fails on the first try itself

    • @akshayhalurkar4859
      @akshayhalurkar4859 Před rokem +1

      it worked. Thanks Dilpreet! I was using arrow functions for the test cases which was the reason for it failing before

    • @sdetunicorns
      @sdetunicorns  Před rokem

      Glad it worked out for you.

  • @mohammadfaisal8741
    @mohammadfaisal8741 Před 2 lety

    I am getting an error on post request. it shows authentication failed

    • @sdetunicorns
      @sdetunicorns  Před 2 lety +1

      Try to do these steps in postman to make sure it works fine there. If it does then you can review your code and see what you are doing wrong.

  • @archanas8463
    @archanas8463 Před rokem

    Is the github link removed from description?

    • @sdetunicorns
      @sdetunicorns  Před rokem

      Updated - github.com/dilpreetj/JavaScript-API-Automation-Tests

  • @Farquad123
    @Farquad123 Před rokem

    In the Async / Await section, my text is passing but it’s say “user_id : “must not be a number”. Has anyone else experienced this? What’s the fix?

    • @sdetunicorns
      @sdetunicorns  Před rokem

      You will likely need to parse the user_id to string and then pass it to the API.

    • @Farquad123
      @Farquad123 Před rokem

      @@sdetunicorns how would I go about that? I’m super new to Java and API testing

    • @Farquad123
      @Farquad123 Před rokem

      @@sdetunicorns parse.string(“user_id”)?

  • @vijaymanda22
    @vijaymanda22 Před rokem

    In the HTTP get methods. expect(res.body.data.id) , it's not working . Supertest not recognising '.data' and getting this error 'TypeError: Cannot read properties of undefined (reading 'id')' .

    • @sdetunicorns
      @sdetunicorns  Před rokem

      Hello, try to print out what you are getting from res.body as that's probably not returning the right response which is causing this error for you.

  • @mangatjass
    @mangatjass Před 2 lety

    if i try using the helper folder , I get an error ,
    Is there a plug in that I am missing
    Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/jaspreetmangat/Repo/camundatest/helper/user_helper' imported from /Users/jaspreetmangat/Repo/camundatest/test/task.js

    • @mangatjass
      @mangatjass Před 2 lety

      I got it , Import requires the file extension .

  • @mangatjass
    @mangatjass Před 2 lety

    If I use expect(res.body.data).to.be.not.empty;
    I get below error
    Uncaught AssertionError: .empty was passed non-string primitive undefined

    • @sdetunicorns
      @sdetunicorns  Před 2 lety

      Try to print out what you are getting back as part of `res.body.data` and make sure you have proper data being returned

    • @mangatjass
      @mangatjass Před 2 lety

      @@sdetunicorns the response body is as below
      [
      {
      "id": "295ab6e5-4ec4-11ec-8138-0a126fbd7918",
      "name": "Verify checklist",
      "assignee": null,
      "created": "2021-11-26T14:21:35.601+0000",
      "due": null,
      "followUp": null,
      "delegationState": null,
      "description": null,
      "executionId": "295a8fc1-4ec4-11ec-8138-0a126fbd7918",
      "owner": null,
      "parentTaskId": null,
      "priority": 50,
      "processDefinitionId": "defaultProductFlow:29:e3d70e16-4dd4-11ec-8138-0a126fbd7918",
      "processInstanceId": "295a8fc1-4ec4-11ec-8138-0a126fbd7918",
      "taskDefinitionKey": "verifyhecklist",
      "caseExecutionId": null,
      "caseInstanceId": null,
      "caseDefinitionId": null,
      "suspended": false,
      "formKey": null
      }
      ]
      Also I am stuck at another point , in some cases I will only get
      []
      But cannot verfiy this "if (expect(res.body.data).to.be.null == true)
      {
      console.log("body not found");}"
      I get
      AssertionError: expected undefined to be null
      Also tried using expect(res.body.data).to.be.undefined but no luck V