Header Ads

  • Breaking News

    Automate REST APIs using Playwright and Typescript - explained with live coding

    Till now we have learn how to automate UI using Playwright. Playwright has capabilities to automate APIs as well. One can easily automate REST API calls and verify the response using Playwright and typescript. In Playwright APIRequestContext can be used to trigger APIs for end-to-end automation. APIRequestContext has all the methods to automate like Get, Post, Fetch, Head, Put, Patch, Delete. 

    To Automate API using Playwright

    1. Create a repo or use existing repo
    2. Start writing test case 
    3. Hit the request and store response in the variable
    4. Verify the response using expect 
    5. Verify some strings from the response in case of POST

    I have created a YouTube video in the "software testing tips and tricks" channel where I have explained how to automate REST APIs using playwright and typescript with live coding. in this video, I have shown
    1. Test example APIs and how they work using Postman Manually.
    2. How to Automate Rest APIs with the live scripting?
    3. How to validate APIs in Automation using expect?
       


    Example Code for the GET request - 

    test('API test - GET', async ({ request }) => {
    const requestURL = "URL";
    const response = await request.get(requestURL);
    const responseBody = await response.json();
    console.log('API response', responseBody);
    expect(response.ok()).toBeTruthy();
    expect(response.status()).toBe(200);
    expect(await response.json()).toContainEqual(expect.objectContaining({
    name: 'Responce String'
    }))
    });


    All Playwright Tutorial Posts -


    No comments

    Post Top Ad

    Post Bottom Ad