Search code examples
bddrest-assuredgherkinweb-api-testing

Is this the correct syntax to validate authorization of API? given().get("url").when().auth("username","pwd").then().assertthat().statuscode(200)


I am testing for preemptive authorization using BDD for API automation using Rest assured. Is this the correct syntax?

given().get("url").when().auth("username","pwd").then().assertthat().statuscode(200)

Can I write get() after given() or should it be in when()?


Solution

  • Try this, it works for me when i use this with Testng.

    httpreq.auth().preemptive().basic("ToolsQA", "TestPassword");
            reponse = httpreq.request(Method.GET,"/authentication/CheckForAuthentication");
    

    Thanks for Asking,