Home > Software engineering >  Is there any way to send authornicated Post and Get API requests with Selenium?
Is there any way to send authornicated Post and Get API requests with Selenium?

Time:11-25

I can share the real time scenario.

Step 1: Lunch the browser perform some functional test like navigate to some page and upload a image/video file

step 2: Send a authenticated post request.

{

  "predicateParams": {

    "type":"dam:Asset",

    "p.offset": "0",

    "p.limit": "-1"

  },"dateParams": {

  "group.1_daterange.lowerBound":"2021-11-19T00:10:15",

  "group.1_daterange.upperBound":"2021-11-19T23:59:15"

  } 

}

Steps 3: Read the response and find the preview URL from the response.

{
    "totalAssetsModifiedOrCreated": 1,
    "totalAssetsDeleted": 0,
    "deletedAssets": [],
    "hits": [
        {
            "path": "/content/dam/global-asset-library/Products/automation/download.jpg",
            "renditions": [
                "/content/dam/global-asset-library/Products/automation/download.jpg/jcr:content/renditions/cq5dam.web.1280.1280.jpeg"
            ],
            "metadata": {
               //Asset metadata
            },
            "previewLink": "https://qa.dam.com/content/dam/global-asset-library/Products/automation/download.jpg?qtm=1637340248265"
        }
    ],
    "status": {
        "code": "200",
        "message": "Search results found.",
        "success": true
    }
}

Step 4: Send a get request using to the preview link in the above response.

{

  "predicateParams": {

    "type":"dam:Asset",

    "p.offset": "0",

    "p.limit": "-1"

  },"dateParams": {

  "group.1_daterange.lowerBound":"2021-11-17T00:10:15",

  "group.1_daterange.upperBound":"2021-11-18T23:50:15"

  } 

}

Step 5: validate the previously published asset returned(ex: Image) Response of get request

Your help is highly appreciated. Thank You.

CodePudding user response:

Authorization(Basic) details can be passed through

given().auth().preemptive().basic("username", "password")

preemptive() method will send the username and password irrespective of server need authentication or not.

  • Related