We've been trying to automate a webservice using selenium eclipse and http components.
In one of the queries we have we are passing two parameters "Param1" and "Param2" which will look like this in the endpoint url: http://xxx.xx.xx.xxxx:8080/sample/?Param1=value1&Param2=value2
We have an existing framework where we get the parameters from an excel sheet data table so users are free to change Param1, Param2, value1 or value2 and then pass the values as part of the whole url for execution
We won't have any problems when handling only one parameter/value as we would have something like this:
String url = "http://xxx.xx.xx.xxxx:8080/sample/"+Param1+"="+value1;
where both Param1 and value1 will be retrieved from our data table.
My question is, what will be the best approach in setting up the string url when parameters can be one or two. So that when I pass two parameter values they will automatically be joined by "&" (?Param1=value1&Param2=value2) but when I'm only passing one it will stop at this (?Param1=value1).
Sorry if this is a dumb question, I'm just starting to learn automation and would like to get the best approach for this. I was thinking this can be done by simple if else statement or having Param2 include the & character but still would like to get advise