Post url using protractor
Does protractor allow post as well as get. My app requires a post to my api however I can not find a post that allows me to specify the url and params.
I can do this
ptor.get('http://localhost:22222/pathtoapi?params=1');
but I can not do
var params = 1; ptor.post('http://localhost:22222/', params,);
is this something that maybe added in the future or is it already possible via another method.
The name is slightly confusing, but 'get' doesn't actually issue a get request. Webdriver is all about testing the page as the user would, so 'get' just means 'navigate to this URL'. The way a user would 'post' is usually something like 'fill out a form and click submit'.
Can you add more details about why you need to do a post command?
I am testing an application that contacts an external api and during development the only way to test the external functionality is with their testing scenario. What I have to do is (using postman) send a post request to their Api which returns a response redirectUri which I then navigate to (at present manually) to tell their Api that I have received the success status. At that point I receive a javascript snippet with the final redirectUri which places me back into my angular application.
I should add. On their live systems there are forms to fill in. on the test systems there are images that replace this and the only means of user interactions is via a button click. until the point where I need the post request.
Update:
I have today tried to send the data via a form but the data must go in a post uri, Is there a way of appending the params to the form uri in a view which I could then submit a click to.
I have tried the code below. However, driver.findElement(protractor.By.name('formelement')).setAttribute('action', attr); returns Object has no method setAttribute
driver.findElement(protractor.By.name('externalFormData')).getText().then(function(result) { var attr = driver.findElement(proractor.By.name('formelement').getAttribute('action'); attr += result; driver.findElement(protractor.By.name('formelement')).setAttribute('action', attr); driver.findElement(protractor.By.name('submitRequest')).click(); });
A user wouldn't set an attribute, so it's not a feature of webdriver. Can you find a way of running your test manually just using your page? It seems that you might have to use angular and $http.post() instead of just relying on the <form>'s action attribute.
I've worked round it by passing the uri to my own api via a form, parsing the uri into an acceptable format and then passing the data to the external api via a post action. so far all looks good. Thanks you for all of your assistance and kudos on protractor.
I'm facing the same issue here. My use case is that my webapp is normally accessed via an external portal that calls us with a POST request. This external portal is only used from the production environment and similar ones are used on UAT environments. In development, we directly access the webapp through a test page making POST requests emulating the portal.
From protractor, I can't use the portal because it would not target the right platform, neither can't I go to the test page because of security reasons. I simply want to navigate to my webapp via a POST request.
So far, I started my tests with browser.get(), passing all params in the URL, but that is not consistent with what actually happens in real life, so I'd like to perform an actual browser POST. Isn't this at all possible?
I perfectly understand that a user would not do a POST on his own, and my problem is very specific. However, as a more general use case, anyone that wants to write protractor tests that don't start at the very beginning of the flow (for whatever reason) cannot do so by reaching the first tested page with a POST. Or is there something I am missing?