Search code examples
javascriptautomationpostmanpostman-collection-runnerpostman-testcase

Add a few more values ​to the previous array in postman


in my test i sholud compare response permission with my rolepermission_array variable in envirment

but there is diffrent , the reponse permission has 4 more permission because of it i should update my envirment what should i do First

in this image my response has 4 more value

Second

"authenticated", "manage_profile", "manage_account", "verify_email"

i should add this values to rolepermission_array

i update my code but still get error

PreRequest

Test Result


Solution

    • You can add element to array using push(element1, element2, ...)
    • To save array to environment, remember stringify
    • To get array from environment, use parse

    In tab Test

    const res = pm.response.json();
    const per = res.data.permissions;
    
    const rolepermission = JSON.parse(pm.environment.get("rolepermission_array"));
    
    rolepermission.push("authenticated", "manage_profile", "manage_account", "verify_email");
    
    pm.test("check permissions", () => {
        pm.expect(per).eql(rolepermission);
    })