Ask a Question

Read aws secrets from ReadyAPI

Occasional Contributor

Read aws secrets from ReadyAPI

Did anybody tried to read aws secrets from ReayAPI groovy code,


We have built java code to read secrets but the same not working from ReadyAPI groovy script


1. copied respective aws-java-sdk jar file to ReadyAPI installation folder(Getting error NoClassDefFoundError)

2.whatever working java code we built jar out the java project, copied jar to ReadyAPI installation location folder(Getting error NoClassDefFoundError)


If Anybody tried the same please suggest

Reference link for java code -

Community Hero

In which directory of installation the files are copied? Is the tool Restarted after copying the files?
And the list of files?
What groovy script did you try?

SmartBear Alumni (Retired)

Thank you Rao!


Hi @ArunS , the Community needs more information from you to be able to try and provide a solution. Thank you.

Sonya Mihaljova
Community and Education Specialist

I Think this is what you are looking for. You'll need an http test step to follow the groovy script to actually log into AWS and retrieve secret, accesskey and token info then another groovy script to simply pick up these values and store them for use with you aws user you'll need to define in the authorization manager, and of course you'll need to use that profile on all subsequent test steps making calls to the cloud.....BTW don't be surprised if your requests fail due to a bad signature being generated by readyApi, I've had tickets in for a long time :-). You can write your own code to generate a signature if you want to give that a try Let me know how this works out.


Groovy Script 1

// Import Required libraries
import java.util.concurrent.TimeUnit
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxBinary
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxDriverLogLevel
import org.openqa.selenium.firefox.FirefoxOptions

// Define geckodriver path


// Define closures

def query_string_to_map = {
it.tokenize('&').collectEntries {
it.split('=', 2).collect { URLDecoder.decode(it, 'UTF-8') }

def map_to_query_string = {
it.collect { k, v -> "$k=${URLEncoder.encode(v.toString())}" }.join('&')

// Define vars

def username = context.expand( '${#Project#contactNameQaone}' ) //
def password = context.expand( '${#Project#password}' ) // $56&pass
def clientId = context.expand( '${#Project#clientId}' )
def redirectUri = context.expand( '${#Project#redirectUri}' )
def signInTitle = context.expand( '${#Project#signInTitle}' )
def passwordInputId = context.expand( '${#Project#passwordInputId}' )
def submitButtonId = context.expand( '${#Project#submitButtonId}' )
def staySignedInButtonId = context.expand( '${#Project#staySignedInButtonId}' )
def authorizeUrl = context.expand( '${#Project#authorizeUrl}' )

// Builds the authorizeUrl if not yet defined

if (!authorizeUrl) {
String url = ''
String path = 'common/oauth2/authorize'

def params = [
tenant : 'common',
nonce : 'nonce01234',
response_mode: 'query',
redirect_uri : redirectUri,
response_type: 'id_token code',
access_type : 'offline',
client_id : clientId

String query_string = map_to_query_string(params)
authorizeUrl = "https://${url}/${path}?${query_string}"

authorizeUrl += "&login_hint=${username}"'Getting authentication token') 'Authorize URL: ' + authorizeUrl

FirefoxBinary firefoxBinary = new FirefoxBinary()

FirefoxOptions firefoxOptions = new FirefoxOptions()

FirefoxDriver driver = new FirefoxDriver(firefoxOptions)
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

WebDriverWait wait = new WebDriverWait(driver, 30)

WebElement passwordInput = driver.findElement(

WebElement submitButton = driver.findElement(
sleep (2000)

if (driver.findElements( > 0) {
log.debug('Clicking "Yes" on "Stay Signed in?" prompt')
String redirect_url = driver.getCurrentUrl() 'Redirect URL: ' + redirect_url


def query_map = query_string_to_map(new URL(redirect_url.replace('#', '?')).query)

String id_token = query_map.id_token
String code = query_map.code 'idToken: ' + id_token 'code: ' + code

testRunner.testCase.setPropertyValue( "idToken", id_token )
testRunner.testCase.setPropertyValue( "code", code )



Groovy Script 2

/// Import AWS credentials from HTTP POST
import java.lang.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;


def accessKeyId = context.expand( '${HTTP Retrieve AWS Credentials#Response#$[\'accessKeyId\']}' )
def secretAccessKeyId = context.expand( '${HTTP Retrieve AWS Credentials#Response#$[\'secretAccessKey\']}' )
def sessionToken = context.expand( '${HTTP Retrieve AWS Credentials#Response#$[\'sessionToken\']}' )
def signatureScope = context.expand( '${HTTP Retrieve AWS Credentials#Response#$[\'signatureScope\']}' )
def expiration = context.expand( '${HTTP Retrieve AWS Credentials#Response#$[\'expiration\']}' )
def serviceName = context.expand( '${#TestCase#serviceName}' )

testRunner.testCase.setPropertyValue( "accessKeyId", accessKeyId )
testRunner.testCase.setPropertyValue( "secretAccessKeyId", secretAccessKeyId )
testRunner.testCase.setPropertyValue( "sessionToken", sessionToken )
testRunner.testCase.setPropertyValue( "signatureScope", signatureScope )
testRunner.testCase.setPropertyValue( "serviceName", serviceName )

SmartBear Alumni (Retired)

Thank you sprice090161 !


@ArunS Is this still an ongoing issue for you? Please let us know if this suggestion works.

Sonya Mihaljova
Community and Education Specialist

Showing results for 
Search instead for 
Did you mean: