Issue
i have a API url http://test:1000/v5/accounts/101/transactions?limit=10&offset=10. in my automation script, my test case sometimes have either limit or offset or both with values changing in consecutive calls. If url has offset, i need to update the url with offset with next value as "&offset=20" and so on in next calls too. how can i do it dynamically inside the java script? any idea please.
Solution
If I understand correctly what is you asking for, you can do the following:
- Retrieve from the URL offset value (in case there is such there)
- Update the offset value
- Update the URL with the new offset value.
Simple Java code to do this can look as following:
String url = "http://test:1000/v5/accounts/101/transactions?limit=10&offset=10";
String offset = url.split("offset")[1];
if(offset != null && !offset.trim().isEmpty()){
offset = offset.substring(offset.indexOf("=") + 1);
int updatedOffsetValue = Integer.parseInt(offset) + 10;
url = url.substring(0,url.lastIndexOf("=")+1) + String.valueOf(updatedOffsetValue);
}
Answered By - Prophet
Answer Checked By - Candace Johnson (JavaFixing Volunteer)