Table of contents
1.
Introduction
2.
Changing Authorization Profiles
3.
Comparing XML Documents
4.
Copy Files
5.
Frequently Asked Questions
5.1.
How do I manage authentication in API?
5.2.
Is ready API and Postman the same?
5.3.
Is ReadyAPI an automation tool?
6.
Conclusion
Last Updated: Mar 27, 2024
Medium

Change Authentication Profiles in Ready API

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

We all have a social media presence. It can be an Instagram or Facebook account or a Twitter handle. We all are socially active. Ever wonder what’s the difference between a simple account and an admin account? 

change authentication profile in ready api

This article will discuss how to change authentication profiles in Ready API. We will start our article by changing the authorization profile. Afterward, we will see how to compare XML documents. These XML documents have the information of profiles. And at last, we will learn how to copy files. We will also go through the scripts used to make the required changes. So without any further ado, let’s get started!

Changing Authorization Profiles

We cannot start our discussion of changing authentication profiles without changing the authorization access for these profiles. We can use Groovy scripts to change the authorization profile and credentials that will be used for a request.

changing auth profile

We have several ways to implement these changes using the script:

⭐We can run the script as a Groovy Script test step.

⭐In functional tests, we can run the script as a setup or teardown script on the project, test suite, or test case level.
 

👉For the basic authorization process

import com.eviware.soapui.config.AuthEntryTypeConfig

def request = testRunner.testCase.getTestStepByName("Name of the Request").getHttpRequest()
request.setSelectedAuthProfile(AuthEntryTypeConfig.BASIC.toString())
request.username = "NewUserName"
request.password = "NewPassword"
request.domain = "NewDomain"

 

👉For a custom authorization profile

import com.eviware.soapui.config.AuthEntryTypeConfig

def authProfileName = "Name of your profile"
def project = testRunner.getTestCase().getTestSuite().getProject()
def authProfile = project.getAuthRepository().getEntry(authProfileName)
authProfile.setUsername("newUsername")
authProfile.setPassword("newPassword")
authProfile.setDomain("newDomain")

//Set to true for pre-emptive authentication
//Set to false for using global preference
authProfile.setPreemptive(true)

def step = testRunner.testCase.getTestStepByName("Name of your request").getHttpRequest()
step.setSelectedAuthProfile(authProfileName)

Comparing XML Documents

After we had changed the authorization profiles, we need to compare the data too. These data are present in form of XML documents. Comparing XML documents is now accessible because of the Groovy script. We use Groovy scripts to compare two XML documents.

comparing xml doc

We have several ways to implement this using script:

⭐We can run the script as a Groovy Script test step.

We can run the script as a Groovy assertion.

⭐In functional tests, we can run the script as a setup or teardown script on the project, test suite, or test case level.

 

👉To do so, run the following script:

import org.custommonkey.xmlunit.*
import org.xml.sax.SAXException

// Get XML documents
def request = context.expand( '${Request 1#Response}' )
def response = context.expand( '${Request 2#Response}' )

// Creating a list of elements to ignore
Set<String> ignoreList = new HashSet<String>()
ignoreList.add("datenTime")
ignoreList.add("packagedId")

// Creating an object with differences between documents
Diff myDiff = new Diff(request, response)
DetailedDiff diff = new DetailedDiff(myDiff)

// Get a list of all differences
List allDifferences = diff.getAlldDifferences()

// Looping through all differences and find their node names
for (int i = 0; i < allDifferences.size(); i++) {
    diffNamedNode=""

    // Checking the node type to get the right node name
    nodeType = allDifferences.get(i).getTestNodeDetail().getNode().getNodeType()

    if (nodeType == 1) {
        // To get the name of the node if the difference is in the comment
        diffNamedNode= allDifferences.get(i).getTestNodeDetail().getNode().getNodeName()
    } else {

    // To get the name of the parent node 
    diffNamedNode= alldDifferences.get(i).getControlNodeDetail().getNode().getParentNode().getNodeName()
    }

    // Now, make sure that the node with a difference is not on the list of nodes to ignore
    if (!ignoreList.contains(diffNamedNode)) {

        // Fail assertion
         assert false
    }
}

assert true

Copy Files

To completely change the authentication of a profile. The last step is to copy all the files. We can also copy files using Groovy scripts into our file system. Copying file is easy to implement. We can use this script anywhere in ReadyAPI.

copy files

👉To copy a file, run the following script:

//Import libraries for working with files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files

//Create objects for the copied file and the target file
Path source = Paths.get("C:\\Users\\coding.ninjas\\Desktop\\test.xlsx")
Path target = Paths.get("C:\\Users\\coding.ninjas\\Desktop\\out\\copied.xlsx")

//Copy the file
Files.copy(source, target)

Frequently Asked Questions

How do I manage authentication in API?

We generally handle authentication through HTTP. Here the username and password are sent alongside every API call. We can also use an HTTP header and manually encode the username and password.

Is ready API and Postman the same?

Postman is built around each individual endpoint in an API. It makes end-to-end testing impossible to track and follow over time. While ReadyAPI is built around each test case. Tests can contain several different resources, endpoints, or pieces of data.

Is ReadyAPI an automation tool?

ReadyAPI is a REST & SOAP API automation testing tool. ReadyAPI focuses on enhancing efficiency and usability when applied to testing web services. With ReadyAPI you get comprehensive web services testing, simplified.

Conclusion

This article briefly discusses how to change authentication profiles in Ready API. We started our discussion by changing the authorization profile, then we compared XML documents which have the required collection of information. And at last, we discussed how to copy files concluding our discussion to change authentication profiles.

We hope that this blog had helped you enhance your knowledge about how to change authentication profiles in Ready API and if you like to learn more, check out our articles 

🌐Managing Test Items in ReadyAPI 

🌐What are Test Steps in ReadyAPI? 

🌐Security Tests in ReadyAPI

🌐Running tests in Ready API 

🌐Encoding attachments and data sources in Ready API
 

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScript, and many more! If you wish to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! 

If you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass