Behat/Mink: how can I evaluate a xml response - testing

I am trying to test a RSS feed via Behat/Mink. Unfortunately I am getting an error message all the time:
The current node list is empty.
Does anyone know how to test an XML response (search for a string in xml) via Behat/Mink?
edit
I need to find some way, and best would be to get it running with Behat/Mink.
But if thats not possible at all, I can live with a workaround too.
An example on how to do that would be great!

In your FeatureContext.php file You can get raw content by
$xml = $this->getSession()->getDriver()->getContent();
And then you can use Regex/DomDocument to test the returned xml content.

Mink is a browser emulation abstraction layer. Some browsers can read RSS, some can't. Parsing custom XML is not Mink responsibility. Use combination of Behat + Web crawler + DomDocument (or any PHP RSS parser) for that.

As #everzet mentioned, Mink is not the best tool for the job, since it's a browser emulator rather than an http client.
You're not limited to Mink though and you could use any PHP http client (like guzzle or buzz) or even file_get_contents() to fetch the rss feed.

Related

How to interact with network tab in chrome using karate DSL when doing web automation

I am writing UI automation script using karate DSL. In this at certain point I need to get value from network call in chrome. I want to interact with one of the webservice call in chrome devtools network tab and get the json response of that webservice.
I need this because I have to extract the value from that particular call and pass it on to the next step in my automation script.
I have seen the question related to sessionStorage(Is there a way of getting a sessionStorage using Karate DSL?) but I wonder how to do the same for network call using script command or any other way?
The first thing I would recommend is don't forget that Karate is an API testing tool at its core. Maybe all you need to do is manually make that call and get the response. You should be able to scrape the HTML and get the host and parameters needed.
That said - there's a new feature (only for Chrome) which is documented here: https://github.com/intuit/karate/tree/develop/karate-core#intercepting-http-requests - and is available in 0.9.6.RC2
It may not directly solve for what you want, but in a Karate mock, you should be able to set a value for use later e.g. by using a Java singleton or writing to a temp-file.
If there is something oddly more specific you need, please contribute code to Karate. Finally, there is an experimental way in which you can actually make raw requests to the Chrome DevTools session: https://github.com/intuit/karate/tree/develop/examples/ui-test#devtools-protocol-tips - it is for advanced users, but maybe you are one :)

How to set a request header in behat tests?

I am developing a Rest API and testing it with Behat and mink-selenium2-driver (for the first time) . For security purposes, every call needs to contain a apikey in the request header.
My Problem is, i cannot set the header. My test looks like this:
Given I add "X_ApiKey" header equal to "test"
When I send a GET request to "/notice"
Then the response status code should be 200
But I keep getting a 403.
Any solutions?
In selenium it is imposible.
Need to test this on other driver, like guzzle
To my knowledge, selenium driver lead chrome, but not how it is working. Proposition to check of use others drivers like guzzle, where you can set headers is a answer, in my opinion.
No i found you could additionally other option. It's recommended you use a proxy to inject additional headers to the requests generated by the browser.
To do this i found
* http://wiremock.org/
You should use the behatch package which includes a behatch/rest context.
However, the selenium driver should only be used when you specifically need a browser, for javascript for example. In this case, as you are testing a API endpoint, using a browser will only slow you down and not bring any benefit.
It's possible to use Restler, a micro framework which can help with RESTful API testing in Behat. It support behavior Driven API testing using Behat and Guzzle.
Here is the example:
Given that "X_ApiKey" header is set to "test"
When I request "/notice"
Then the response status code should be 200
Here is another example from negotiation-format.feature file:
Scenario: One with more `q` should be selected, q = 1 when not defined
Given that "Accept" header is set to "application/json;q=0.8,application/xml"
When I request "/examples/_003_multiformat/bmi"
Then the response status code should be 200
And the response is XML
And the type is "array"

RESTful Service not working for multiple calls

I have created a Restful Service which accepts input xml and outputs response xml. Before giving output xml it calls Web Service and gets the xml from it. I do some modifications to the xml and output it.
The client reports that when they do load testing, sometimes the response comes properly and sometimes does not from RESTful Service.
How can I do load testing with JMeter and find the loophole in it. This happens for multiple calls.
2 great references for jmeter are:
- http://blog.milamberspace.net/ if you talk french
- http://theworkaholic.blogspot.fr/ if not
But you should definitely start by reading :
- http://jmeter.apache.org/usermanual/index.html
Then ask questions on jmeter user list if you are stuck.
Regards
Philippe
First create new test and save test scenario with JMeter Proxy (records user clicks in a browser).
Then use the recorded components to compose your actual test.
Don't forget to use JMeter Plugins (invaluable).

How to set http headers in dotCMS

I'm trying to create a XML data feed with dotCMS. I can easily output the correct XML document structure in a .dot "page", but the http headers sent to the client are still saying that my page contains "text/html". How can I change them to "text/xml" or "application/xml"?
Apparently there's no way to do it using the administration console. The only way I found is to add this line of (velocity) code
$response.setHeader("Content-Type", "application/xml")
to the top of the page template.
Your solution is the easiest. However there are other options that are a bit more work, but that would prevent you from having to use velocity to do the XML generation, which is more robust most of the time.
DotCMS uses xstream to generate XML files (and vise versa). You could write a generic plugin to use this as well.
An JSONContentServlet exists in dotCMS that takes a query and generates json or xml (depending on your parameters). It is not mapped on a servlet by default, but that is easy to add.

XML Parser problem

i have to parse data xml.
any one suggest me a simple parser so i can get the data. please don't suggest of ASIHTTPrequest method..
In my xml file there are tad's in which data contain [CDATA] block. iseen this first time i get the null value for this tag
At this link you will find a list of popular XML parser libraries for iOS and differences between them. I used TouchXML in my apps and it was really easy to use.
ASIHTTPrequest is not a parsing library, it's a wrapper for the CFNetwork API. It is used to perform basic HTTP requests and interacting with REST-based services (GET / POST / PUT / DELETE).