HTML page got returned as part of API response in karate. Now how to enter username and password on that? - karate

I have an API which redirects to browser and on that we have to enter username and password.
The API returns the HTML page as part of the response. How from HTML response we can pick username and password via locator Id and click button?
I have tried below but as it is returned in the response I somehow need to tell where in response find that field and input.
And input('#username', 'username')
And input('#password', 'password')
When click('#kc-login')

What I would do is scrape any information needed out of the HTML like this: https://stackoverflow.com/a/61605535/143475
And then form an HTTP request to do what the clicking of the button actually does. Remember no matter what HTML and complex JS / UI you see, finally everything becomes some HTTP request. Use the developer tools "network" part of the browser to figure this out.
The rest is up to your creativity. Work with some web-developers if required.

Related

Selenium Chromedriver call to logout page not working

I want to write an automated test with Selenium using Chromedriver and Behat.
This scenario in question should go to a page, register a user, logout and register another user.
Now the problem is, on the website in question, after registration you get an annoying overlay, so that the logout button is not reachable anymore. I can either make the test fill out the overlay and complete it properly, which will take much more effort, or try to logout some other way.
My idea was to simply go to the domain again with /?event=logout added which normally works to log out the current user. However when I do this in the automation it fails, apparently because of a bad http response code.
Is it not possible to use a url like this with Selenium? Anyone have an idea?
You can achieve this with Selenium using a site that makes GET requests. So you can go to URL http://requestmaker.com/, fill the www.website.com in the Request URL, and 'event=logout' in the Request data, then click "Submit".
It's a bit hacky, so I would prefer using a GET request directly in the code, depending on your programming language... Something like so:
https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/
Some options would be:
Navigate to URL to logout and try to hide the modal via jQuery/javascript
After registration navigate to homepage and see if the modal is there and if you can logout as you should
Clear session and navigate to the page you need
Pick one of them.

Opening an XPage (single page application) to a specific anchor (appPage) for unauthenticated users

I have a mobile XPages application which uses the single page application control (xe:singlePageApp) of the XPages extension library. The application also uses a workflow engine which sends out emails with links to documents to users so they can approve requests.
The link URL is composed like
http://hostname/app.nsf/m_page.xsp?action=openDocument&documentId=2A2A#requestForm
where requestForm is the name of the appPage containing the form to display a single request document.
If the user is already logged in, the browser opens and displays the document as intended.
However, if the user is not already logged in, the Domino login form is displayed (session based authentication). When the user then logs in, the same XPage is opened, but to the default page (selectedPageName attribute of the singlePageApp) instead of the appPage with the pageName requestForm. The reason for this behavior is that after submitting the login form the anchor part (#requestForm) is no longer present in the URL the browser is redirected to because the #requestForm-part is never sent to the server where the redirect URL is computed in the first place.
Possible solutions I can think of are
put the intended pageName in a real URL parameter (like documentId), parse the URL and modify the browser location (from ...&documentId=2A2A&pageName=requestForm to ...&documentId=2A2A#requestForm)
check the URL for the existence of the documentId parameter and modify the browser location (add #requestForm) if it is present
modify the Domino login form as per Jake Howlett's Suggestion (which is a not always permitted)
I was wondering now if there are more elegant solutions to this.
I would take the first option in your case. But instead of handling the url change at the client-side, I would handle this on the server-side. Otherwise, client will load the initial page once and submit an additional request to the server.
On the beforePageLoad event:
var url:XSPUrl=context.getUrl();
if(url.hasParameter("pageName")) {
var pageName=url.getParameter("pageName");
url.removeParameter("pageName");
facesContext.getExternalContext().redirect(url.toString()+"#"+pageName)
}
This will do the redirection before loading the page.

How to avoid popup in http request

I have a url. when i access this through browser a popup comes and ask for user name and password and by giving right credential it opens the page. I want to know how to avoid the popup by passing the user name and password url itself and how to do that
note my username contains # symbol
Thanks A Lot
You can use the form:
http://<user>:<pass>#<host>:<port>/<path>
It even works with # in the username (IE might not support this).

Apache Wicket how to render a (non-wicket) response page

I'm using Apache Wicket and I have following problem:
Inside a onSubmit() method I am sending a POST request to external web address with Apache httpClient. As a response I get html (inside my response object).
How can I get Wicket to render this html in browser?
So basically what I'm trying to do here, is simply what would normally happen if I submitted a html form to this web address. However for security reasons I don't want to give user pages containing forms that contain this data I'm trying to send.
You can get the response via getResponse() in any component. (I assume the onSubmit() is on a form).
How about something like:
getResponse().reset();
getResponse().write(htmlPage);
htmlPage should be a CharSequence containing the html page to be rendered.

scrape the reponse which would be loaded from ajax event

I am using scrapy tool to scrape content from website, i need help from you guys how to scrape the reponse which is dynamically loaded from ajax.
when content loading from ajax at that mean time url not changing it keep remains same but content would be changed so on that event i need to crawl.
thank you,
G.kavirajan
yield FormRequest('http://addons.prestashop.com/en/modules/featureproduct/ajax-homefeatured.php',
formdata={'type':'new','ajax':'1'},
callback=self.your_callback_method)
bellow are the urls that you can easily catch using fiddler or firebug
this is for featured tab http://addons.prestashop.com/en/modules/featureproduct/ajax-homefeatured.php?ajax=1&type=random
this is for new tab http://addons.prestashop.com/en/modules/featureproduct/ajax-homefeatured.php?ajax=1&type=new
you can request on these url directly to get results you required, although website is using POST request to get data for these url, but i tried with parameter GET request is also working properly