Let's say that you need to automate file upload with Secured HTTPs Rest calls using selenium.
You might get the following error:
Remote host closed connection during handshake
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
Here some of the code to use, to solve this issue:
#HTTPS path
String urlPath = "#https://xx.xx.xx.xxx:xxxx/<API PATH>";
String json = "<JSON String>";
URL url = new URL(urlPath);
HttpsURLConnection connection = null;
connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/json");
connection.setRequestProperty("Accept", "application/json");
OutputStreamWriter streamWriter = new OutputStreamWriter(connection.getOutputStream());
This, of course, won't work, why?
1. Try to send your RSA key by overriding transport layer and also pass your certificate as an argument.
2. Selenium is a wrong tool for API automation - you should try Rest Assured framework. Try jayway.RestAssured library to automate. You can also integrate it with Selenium
3. You can use HTTPClient API to automate rest API testing.
4. You can also use rest assured API (best for rest API) to automate web services. It works in BDD style and quite easy to implement.
5. You must add authentication ticket to establish the connection..check which services you are using in your project for authentication.
So, don't break your head - ask community
If you need to combine web service testing with functional testing, what is your first choice??
I found good article for Web services testing in the following link: How to perform Web Services Testing using HTTPClient
(if you have good links for Web services testing, please comment)