How to click on response body link (that keeps changing) and verify that Id = Global Admin exists within the link?

Hi,

I have the following url below, but for my test i want to click on it and check if the url has Global Admin as a User Role.

API1 =

Click on the link (which is always changing after every send)

and verify once you send the url - User Role = Global Admin …
I want to be able to do this in the test scripts of the first api call … is this possible?

I am already sending the request for that url and it is coming up as pass, but what would be next…

postman.setEnvironmentVariable("UserAdminUrl", pm.response.text());

var UserAdminUrl = pm.environment.get("UserAdminUrl");

pm.test("Expecting Response to have text Url",function (){
    pm.expect(pm.response.text()).to.include(UserAdminUrl);
});

pm.test("UserAdminUrl hits the server successfully", function () {

    pm.sendRequest(UserAdminUrl, function (err,response){
        pm.expect(err).to.not.be.ok;
        pm.expect(response).to.have.property('code', 200);
        pm.expect(response).to.have.property('status', 'OK');
    });
});

Hey @shahbaz.shiekhqa

Would something quick like this work for you?

pm.test("UserAdminUrl hits the server successfully", function () {
    pm.sendRequest(UserAdminUrl, function (err, response){
        pm.expect(response).to.have.property('code', 200);
        pm.expect(response).to.have.property('status', 'OK');
        pm.expect(response.text()).to.include('Global Admin')
    });
});

It looks like the response is HTML so to extract that exact point in the response, would be slightly trickier but not impossible.

1 Like

Thank you so much, that worked perfectly,
i changed it to include the whole id and user role and global admin

pm.expect(response.text()).to.include('<span id="ctl00_RoleLbl"><b>User Role:</b> Global Admin</')

thanks :slight_smile:

1 Like