Checking API Status in TestComplete
Introduction I first saw the need to verify the state of an API several years ago with an application that used an address validation API in several of it's operations. If this API was down or did not respond in a timely manor, many of the automated test cases would run and fail. In this case, and in others, I have found that doing a simple call to the API to check the returned status code allowed me to skip, fail or log a warning with a logical message instead of allowing the application to fail with another less direct error message due to the API issue. The aqHttp Object The TestComplete aqHttp object and it's methods are very useful for performing simple checks like this and are also useful for other more complex tasks like leveraging an API to return a test data set or even verifying a certain data is returned prior to running tests against the UI that depend on the data. Sending and Receiving HTTP Requests From Script Tests More Complete API Testing Most proper API testing should be done using a tools like ReadyAPI or SoapUI. Both of these tools will integrate with TestComplete or can be used alone and will provide much more capabilities and automation options. Integration With ReadyAPI and SoapUI Code Example Here I have provided a working example of how to code a Get request using 'aqHttp.CreateRequest' to confirm an API returns a status code of 200 and it will log the returned records. function sendGetRequest() { let resourcePath ="https://restcountries.com/v3.1/all" let resourceQuery = "?fields=name,capital"; let url = resourcePath + resourceQuery; try { // Send GET request let response = aqHttp.CreateRequest("GET", url, false).Send(); // Check for successful response if (response.StatusCode === 200) { // Parse JSON response let allData = JSON.parse(response.Text); Log.Message("Total records received: " + allData.length); // Process each record allData.forEach((record, index) => { Log.Message("Record " + (index + 1) + ": " + JSON.stringify(record)); }); return true; // Send a bool back to the calling function. } else { throw new Error("Failed to fetch data. Status code: " + response.StatusCode); } } catch (error) { Log.Error("Error during request or data processing: " + error.message); } } Enhancements You could accept parameters for the resourcePath and resourceQuery. Parameterize the logging loop run or remove it. Return the JSON to the calling function for use. Perform other tasks based on the return code. Conclusion With the growing use of API calls in desktop applications and the fact that APIs are almost the foundation of any web site checking an API before a test case run is almost a requirement for consistent test runs and good error logging. This small script can bring big rewards to your test runs and reports. Cheers! I hope you find it as useful as I have! If you find my posts helpful drop me a like! š Leave a comment if you want to contribute or have a better solution or an improvement. š Have a great dayRunning ReadyAPI Suite via Command Line / C# took ~ 30 sec to initiate
Hi, I'm currently executing the Ready API suite using C# by triggering testrunner.bat. The execution works as expected; however, it takes approximately 30 seconds to initiate the run. Is there any way to optimize or speed up this startup time? Iād appreciate any suggestions. Below is the command Iām using: string soapCommandLine = $"-s {suiteName} " + $" -c {caseName} {readyAPIprojectPath} ";74Views0likes0CommentsRest request attachments multipart form data for json file with parameterized json data
So I have been trying to do a scenario where i have two attachments for a rest request, one json file which i need to parameterize couple of fields from previous request. The problem with this is once you have cached the attachment you cannot modify it based on the previous test steps, So i have followed the following youtube link https://www.youtube.com/watch?v=iL-zehJmtWw Used query parameter to use a locally store file of json to request but we are getting the error from response that application/octet-stream content type is not accepted ------=_Part_01_136051460.1696260652738 Content-Disposition: form-data; name="testFile" testFile:/Path/to/file/testFile.json I have used parameter like this testFile:${projectDir}/testFile.json What should I do in this case1.3KViews0likes7CommentsRunTestCase input and return proeprties of the same name
Hello! I have a test case module that loads a set of around 100 properties from multiple databases, performs some logic with the data and then outputs the whole set into the testcase properties. I want to have the option to input some of the properties into the test case when I use a Run Test Case test step and if my logic detects the input, it won't load those specific properties from database. What I am struggling with is that if I set the Run test case step properties as Return properties, it ignores the data i put into the Run test case properties, and if I don't set them as return properties, the empty input properties don't get overwritten with the DB loaded data. Do you have any tips how I could achieve to have shared input and return properties?48Views0likes0CommentsData Source test step doesn't output arrays into properties
Hello! I am using Ready Api GUI 3.57.0 and I am trying to setup a modular, data-driven general testcase. I am using GUI only to setup the test, and now I encountered a strange situation when using Data Source test step I have a nested array and I am currently trying to use JSON DataSource to iterate over the root array and save the nested array into a property. And I am failing to do so. When I point to the Array I want to save into the property, if saves Null. When I point to the first member (i = 0) of the array, it shows the data properly. Could anybody please help me check if I am the one who's doing something wrong, or it is ReadyApi being moody? To make the situation more specific: This is my JSON data source: { "name": "Get_PC", "toTest": true, "templatesDirectoryPath": "I:/Testing/AutotestSourceDataFiles/P1/Get_PC", "a_webServiceDefinition":[ { "name":"2018/05", "toTest": true, "webServiceUri": "/P1/2018/05", "o_nameSpaceDefinitions": [ {"nsName": "soapenv", "nsUrl": "http://schemas.xmlsoap.org/soap/envelope/"}, {"nsName": "ns", "nsUrl": "http://www.data.com/2013/08"}, {"nsName": "ns1", "nsUrl": "http://ws.com/2018/05"} ] }, { "name":"2023/09", "toTest": true, "webServiceUri": "/P1/2023/09", "o_nameSpaceDefinitions": [ {"nsName": "soapenv", "nsUrl": "http://schemas.xmlsoap.org/soap/envelope/"}, {"nsName": "ns", "nsUrl": "http://www.data.com/2023/04"}, {"nsName": "ns1", "nsUrl": "http://ws.com/2023/09"} ] } ] } My DataSource test steps configuration is: Data Source Type: JSON Step and property points to the aforementioned JSON string Row Path: $['a_webServiceDefinition'] Column Path: ['o_nameSpaceDefinitions'] According to JSON PATH documentation and validators, the JSON PATH: $['a_webServiceDefinition'][0]['o_nameSpaceDefinitions'] should return the array I want, but it is returning NULL. Also, when I modify column Path to ['o_nameSpaceDefinitions'] [0], it correctly returns the first object in the array. Is there a problem on my side?43Views0likes0CommentsProblem with generated data table and keyword test
Dear Community, I have a problem with a created table type project variable. Here is my script, I checked data inside the generated table and everything is OK for the table. function CreateTestExecutionDataTable(){ // Create a table variable if it doesn't exist if(!Project.Variables.VariableExists("TestExecDataTable")) Project.Variables.AddVariable("TestExecDataTable", "Table"); // Get a reference to the variable var t = Project.Variables.VariableByName("TestExecDataTable"); // Add columns to the table t.AddColumn("Test Execution"); t.AddColumn("Environment"); t.AddColumn("Build Type"); t.AddColumn("Team"); // Create rows TestExecutionData.testExecutionList.length-2 t.RowCount = testExecutionList.length-2; Log.Message("Length of the execution table "+t.RowCount) for(let i = 0; i < t.RowCount; i++){ t.$set("Item","Test Execution", i, testExecutionList[i+2]); t.$set("Item","Environment", i, environmentList[i+2] ); t.$set("Item","Build Type",i, buildTypeList[i+2] ); t.$set("Item","Team", i, teamList[i+2]); } } Then I want to integrate a Data driven loop that will perform actions for each item in the table var. The problem occurs when I want to choose some values and perform actions, because I don't see anything. I don't have any idea about how to use this generated table in my keyword test. Does anyone have an idea? Thank you for your help.Solved102Views0likes6CommentsReadyAPI 3.56.0 does not fail testcase if iteration in datasource fails
Hi, We have a datasource which takes data from excel to feed in the request. This excel has multiple rows, each row creates a different request and each row gets it's own assertion data. Since release 3.56.0, it seems like whenever an iteration fails from the datasource that is NOT the very last row in the datasource, the test case will still be reported as passed. As a workaround, I'm trying to create a custom testcase property "hasFailed" with a standard value of "false". Whenever an assertion fails, the testcase property is set on "true", but whenever I try to execute the follow script in my test case teardown script: def hasFailed = testRunner.testCase.getPropertyValue("hasFailed") if (hasFailed == "true") { log.info(hasFailed) testRunner.fail("Testcase failed, check transaction log for more details") } it doesn't seem to work. The log.info is displayed but the testRunner.fail doesn't fail the test case itself. Any tips on how to fix this?94Views2likes1CommentSpecifying a specific Schema when connecting to Postgres Database Connection
Hi all .. I have no trouble connecting my ReadyAPI application to a Postgres database. However, I need to specify a specific schema to connect to. Say the schema i need to connect to is called bluesky how do i modify my connection string so that the queries hit that specific schema? jdbc:postgresql://0.0.0.1:5432/oompaloompa?user=player1&password=PASS_VALUESolved87Views0likes1CommentPassing test data randomly to script tests from Excel file
Hello everyone, Have a productive week. I just started playing around with TestComplete so I will around for some time. Thanks in advance for any comments. My question is: I created data by using TestComplete's data generator to an external file. How can I pass this data to my code that I record in script testing? I could not find much things to read in official documentation. RegardsSolved68Views0likes3Comments