Verify the response code of the page with Capybara and Selenium - ruby

I'm trying to verify the response code of a page by using capybara. I used the expect statement as -
expect(page.status_code).to eq(404)
I'm getting the error as -
Capybara::NotSupportedByDriverError:
Capybara::Driver::Base#status_code
Might be status_code is not supported by Capybara. Is there any other way to verify the status/response code or I'm doing something wrong in the expect statement.

The Selenium driver doesn’t support status_code because it’s not really something you should be testing in a feature/system test. The idea of feature/system tests (which Capybara is aimed at) is to test from a users perspective. Since a user cares about what is shown in the browser thatts what should be tested for rather than the status code. If you still want to test for the status code it should be done in a request spec rather than a feature/system spec

If you don't need JavaScript you can try to fall back on the default rack_test driver:
it "responds with status code 404", js: false do
expect(page.status_code).to eq(404)
end

Related

Data entry through Jmeter not reflected in UI of application

I'm using Jmeter to perform load test on Moodle application
I followed the below steps to replicate a simple "add company " test scenario
1: Recorded the browser actions through HTTP Test script recorder and created a test plan with thread user of 1
2: Added HTTP Cache Manager,Added regular expression extractor for retrieving dynamically generated session for login HTTP request.
For Http request of adding new company, addded user parameters containing new company name
I run the test, everything seems ok in the view results tree- response section (response code: 200,response message:OK), all the required variables are passed in the HTTP POST
PROBLEM: New company added through Jmeter test is not reflected in UI of the moodle action
Can any of you please let me know
Is there something I could be missing or anyway I can debug the problem?
P.S: I'm new to Jmeter and looked around a lot for data inputted through Jmeter not being displayed in the UI of the web application,dint find useful results.
The answer to questions of this sort is almost always that you missed some necessary dynamic value besides session ID which you did catch.
An HTTP200 response just means the server returned a "good" response. Which could also happily contain an error message.
I would check the actual html body of the returned response for any errors. Checking the log on the server side can give you clues to what went wrong sometimes. You should also try adding a cookie manager.
Run your test with 1 virtual user in GUI mode with View Results Tree listener enabled and inspect responses to see where your scripts fails. My expectation is that you simply cannot log in.
See Moodle-JMeter-LoadTest.jmx file for reference, it uses XPath Extractor to get session key and course id.
I don't think you can test using JMeter. Try JUnit Test cases instead http://jakarta.apache.org/jmeter/usermanual/junitsampler_tutorial.pdf

What does "HTTP request failed" mean in an rspec/capybara/poltergeist/phantomjs spec?

Even when all tests are passing, I see many many instances of this message amid the successful test output:
...
in the single-post view
behaves like editing a comment
HTTP request failed.
HTTP request failed.
HTTP request failed.
...
What is causing it?
One possibility is that requests made by for example third-party analytics scripts on your page are failing.
You can see their activity by inspecting the output of poltergeist's page.driver.network_traffic at the end of a test.
If you think this is the problem, you could take those scripts out of the picture by
including them in the page only if you're not running tests, or
using poltergeist's page.execute_script to replace appropriate functions in those third-party scripts with no-op functions. (That takes more work but leaves the page contents more production-like, which might catch a few more possible errors.)

How to debug a failed ajax request in google chrome?

I have a web application that crashes on ajax requests with google chrome (it works with every other web browser it was tested it). After debugging I found that the error is caused by response.responseText being undefined. The xhr object looks like this:
argument: undefined
isAbort: false
isTimeout: undefined
status: 0
statusText: "communication failure"
tId: 3
In debugger in the 'network' tab I get "(failed)", however all the headers are there and I can even copy into clipboard the response body (which is a valid JSON).
My question is - how can I debug this problem? Where to find additional information, what causes this request to fail?
I finally found the solution to my problem : AdBlocks, when it blocks an ajax request, it just says "communication failure".
The first thing I would double-check is that the data coming back from the response is valid JSON. Just pass it through a JSON validator like this online JSONLint: http://jsonlint.com/
I assume that you are using something like jQuery to make your AJAX requests. If so, then make sure that you are using the development version of that library. Now that you are using the development version (uncompressed) of the script, find the particular function that you are using (eg. $.ajax) and then, within the Chrome inspector, insert a breakpoint in the code where the AJAX response is first handled (eg. https://github.com/jquery/jquery/blob/master/src/ajax.js#L579). Then proceed to step through the code, inspecting various return-values to see exactly what is going wrong.
If you are not using something like jQuery to make AJAX calls, then I'd recommend using a framework to avoid possible cross-browser compatibility issues like you might be experiencing right now.

Cucumber/Capybara returning 'Not Found' page after a redirect

first, sorry for the bad english.
I have a test that submit a login form.
after redirect, when I test for a message 'successfully logged...'
then my page.body is
'<h1>Not Found</h1>'
but this works perfectly on browser manual test.
what should I'm doing wrong?
Sounds likely that one of your steps is redirecting in a way that you do not expect.
Check your before filters on the controller and application_controller to determine whether a login/I18n filter is redirecting your page.
If you have the launchy gem installed, you can also add the following to your steps:
And show me the page
Which will fire-up a browser with what capybara is actually looking at, which is useful for sanity checking your steps.
Good luck!
Tests run under their own clean copy of the database. Make sure you've set it up first using rake db:test:prepare, and that you're creating all the data you need for your tests as part of the feature. (I.e. Given there is a user named "Joe"...)

Need to debug recorded jmeter script

I recently recorded a test script in Jmeter intended for use as a load test script (using this handy set of instructions. The recording itself worked great and I even figured out how to grab and parametrize the session ids and timestamps. However, if I run the recorded steps just as they were recorded some of them don't work -- they generate "500--Server encountered and internal error ...nested exception is java.lang.NullPointerException" The failing steps are all Ajax calls that populate sidebar elements. If I copy the request GET call (Request tab, ViewResultsTree) and paste it into a browser I get the exact same error. Do I need to record my script differently, or hand-code the ajax calls? Other, earlier steps work correctly and send the expected POST data, so it isn't the application under test or forgotten proxy settings. Currently running against Firefox 3.6.10
Any suggestions on how I can debug this would be greatly appreciated.
The first thing I'd do is determine if the java.lang.NullPointerException is happening on the client side (JMeter) or on your server. If it is happening in JMeter, than something is terribly wrong with either your script or with JMeter.
But assuming that the error is encountered on your server, then looking into the cause of the exception may shed light on what is wrong with the request issued by JMeter. Do you have access to the code where the exception is thrown?
I would also recommend comparing the request in the recording with the request that generated the error. You may need to determine which parts of the request are session-specific and ensure those fields are populated correctly.
It sounds like Jmeter isn't executing the AJAX calls, and this can be fine depending on your site. Can you simply do an HTTP request to get the pages the AJAX calls populate?
I would recommend reading this post, as it looks pretty good.
I've seen that situation caused by a few things:
a page is required to load and be cached BEFORE making the failing request;
the failing page needs to automatically redirected to work properly;
the failing page has sub-requests JMeter failed to record. Devs can help with this.
Hope this helps.

Resources