Forum Discussion
Hi ktimbal,
Cool use case. You’re very close — the script you’ve written is on the right track. There are just a few ReadyAPI behaviors that explain what you’re seeing, plus small tweaks you can make.
1) Endpoint not showing
When an Environment is active, the endpoint you set in the script is saved but won’t appear in the UI unless that environment also defines it. You can switch to No Environment, or keep an environment active and set the endpoint inside it.
Example A – make the endpoint visible with no environment:
project.setActiveEnvironment(null)
request.setEndpoint("https://sample.endpoint.com")
Example B – keep an environment active and map the endpoint inside it:
def env = project.getEnvironmentByName("Local")
if (env == null)
env = project.addNewEnvironment("Local")
env.setRestServiceEndpoint(restService, "https://sample.endpoint.com")
project.setActiveEnvironment("Local")
2. Auth profile not applying
The line request.authProfile = "BasicAuthProfile" only works if that profile already exists at the project level. Some older versions (like 3.59) may not expose an API for creating Basic profiles from Groovy. If that’s your case, set the Authorization header directly (same result on the wire):
import com.eviware.soapui.support.types.StringToStringsMap
def creds = "myuser:mypassword".getBytes("UTF-8").encodeBase64().toString()
def headers = new StringToStringsMap(request.getRequestHeaders())
headers.put("Authorization", "Basic " + creds)
if (!headers.containsKey("Content-Type")) {
headers.put("Content-Type", "application/json")
}
request.setRequestHeaders(headers)
3.WADL vs JSON (OpenAPI)
If you don’t bind an OpenAPI definition, the interface appears as WADL. If you want JSON/YAML in the UI, bind your spec before adding resources:
try {
restService.setDefinition("file:///C:/path/to/openapi.json", false)
restService.importDefinition(false)
} catch (t) {
log.warn("OpenAPI bind failed: " + t.message)
}
Notes:
I tested these changes on ReadyAPI 3.62; 3.59 is very similar, but some method names may differ slightly. For general reference, here’s the ReadyAPI scripting guide:
https://support.smartbear.com/readyapi/docs/en/test-apis-with-readyapi/scripting.html
Hope this helps!
John Monahan
SmartBear Solutions Engineer