Rails 5 + Capybara: XHR request report status 0 - phantomjs

In the process of upgrading our application to Rails 5, I'm seeing some really baffling behavior with Javascript XHR requests during our Capybara-based feature specs.
Here is the code (CoffeeScript) in question:
$.ajax(
url: "/foobar"
).done((_data, _status, _jqXhr) ->
# *snip* all is well
return
).fail((jqXhr) ->
# This should be 422 but is 0 instead
status = jqXhr.status
console.log("AJAX request returned with error code #{status}")
return
)
Everything works when using a Rails server in development mode and a real browser (i.e. Chromium or Firefox)
Poltergeist/PhantomJS reports status 0
capybara-webkit also reports status 0
Selenium Webdriver (geckodriver) correctly reports status 422
The versions of Poltergeist (1.11.0) and PhantomJS (2.1.1) stayed the same. During gem updates to Rails 5, Capybara was upgraded from 2.10.2 to 2.12.0, but I also upgraded the old branch to Capybara 2.12.0 without anything breaking, so it's likely that this isn't the problem either.
I was able to bring up the fabulous PhantomJS developer console and, in the "network" panel, saw that the status code was, also in test mode, 422 as expected, which means that the problem must really be somewhere in JavaScript-land.
Note that this is not a cross-origin request and the request is not aborted (the usual causes for status code 0). And since it works when in development mode, I'm a bit baffled who might be the culprit for this behavior.
I also tried looking at other properties and arguments to the callback function and whether I could find the status code in some other property, but haven't had any luck with that.

Related

Playwright - URL is not loading sometimes

when I start the test, the browser is opened but it does not load the URL.
After 10-15 seconds it stopped to load (see screenshot).
I had updated intelliJ, updated playwright to version 1.28.1 (doesn't help)
It happened 7 out of 10 trials.
Any idea why it suddenly becomes that behavior?
Many thanks!
there are 3 probabilities causing this error when hitting the URL:
Your browser version could be a outdated which the site is blocking, so try updating playwright browsers using the command 'npx playwright install'.
Check whether the site is being blocked due to any firewall or proxy setting and if so, get it whitelisted.
As the request also seems to be a crash due to timeout, kindly check whether you have decent internet speed.

Testcafe caught in page reload loop

I have a set of Testcafe tests for our application, which since recently fails to run in some of our environments. The test only opens the browser, loads the start page specified in the fixture (or navigated to in within the test) and then only appears to continuously reload the page without proceeding with the test. This happening across all browsers (Chrome, Firefox, Edge) and different versions of NodeJs and Testcafe on Windows 10.
After enabling debug logging I found this message repeatedly in the log:
{
cmd: 'wait-for-file-download',
sessionId: '0X_DqYtz0'
}
The browser console also showed two page resources/scripts that failed to load with net::ERR_FAILED errors due to violating the Content Security Policy, so I assume that these might cause the problems. However it does not seem to have any impact on manual page interaction or automated test using other frameworks like PyTest.
While we are investigating on the conflicting resources, is there anything I can do in Testcafe to bypass the issue and allow the tests to run? Or alternatively is there a way to fail a Testcafe test when encountering this issue instead of reloading and possibly eventually timing out?

PhantomJS HTTP request cache (or something else?)

I wrote a small Bash script which runs a few PhantomJS tasks.
For example:
./node_modules/.bin/phantomjs "phantomjs/snapshot.js" "$url" >file.html
As you see, I use the logged info from PhantomJS to write it to a file.
I ran the command on a URL with JavaScript errors. For some unknown reason each time I now run that command with the same URL I still get the errors... Although everything's fine if I do the same with a different Linux user. Also, if I use a different URL, everything is also fine (but I need to use the one which throws errors).
Is there a way PhantomJS uses cached response? I tried to add clearCookies() and clearMemoryCache() methods before opening the page, also tried to add random parameter on each call, but nothing helped...
PhantomJS is the latest version.
The problem was that the broken call made an entry to localStorage, which then was causing all other errors. Apparently PhantomJS keeps the localStorage on a file, so removing appropriate entry from /home/USER/.local/share/Ofi Labs/PhantomJS cleared the localStorage and the problem is gone now.

Sails server shutting down whenever there's an error in SailsJS

I used to program with Ruby on rails and I have just started SailsJS.
With rails when I had an error in my backend, it didnt kill my server. I used to have a nice error displayed in my web browser and I even used the gem better error to have a live console displayed in my webbrowser when an error occured.
How can I prevent the server to shut down everytime there's an error in Sails JS ?
Is there a way to have a nice way to display errors with Sails (with the live console in the web browser, just like with the gem better errors) ?
For running your server despite errors, take a look at foreverjs. However, I'd advise you to be defensive about your programming and properly handle errors.

RSpec request specs and routing specs occasionally failing in CI

We're using Jenkins as a CI server, and without any pattern that I can determine, sometimes the request and routing specs fail - only on the CI server though, never on the development machines.
It's currently using Selenium as the Capybara driver, and I've seen problems with that configuration before, but the routing specs failing sporadically is baffling me. Can anybody make any suggestions for things to check?
Update:
I have a single failure now happening sporadically:
NoMethodError: undefined method `to_a' for false:FalseClass
(in /blah/app/assets/stylesheets/application.css.scss)
/home/paul/.rvm/gems/ruby-1.9.3-p374/gems/sass-3.2.5/lib/sass/selector/simple_sequence.rb:153:in `block in to_a'
This is definitely the same error message I've seen before, but I've never seen the line before... investigating.