using page.find( 'some-element' ).native consistently returns a string, say '4'. Documentation states it returns some object that allows me to access native methods. Anyone ever run into this?
Capybara version is 1.1.2
Capybara-Webkit version is 0.12.1
Sounds like you might be using Capybara Webkit, which represents internal nodes as Integers. You can still access the native Rack::Test node using:
page.find( 'some-element' ).base.native
More Details here: https://github.com/thoughtbot/capybara-webkit/issues/634
Related
In my Rails app front-end I use JavaScript's Array.includes method as follows
if (['a', 'b', 'c'].includes('b')) {
// do stuff
It works fine in a live Chrome browser, but my RSpec test is failing. I believe Capybara Webkit doesn't seem to support it?
I can confirm this by pausing the spec with binding.pry and running
> page.evaluate_script("['a', 'b', 'c'].includes('b')")
=> nil
It returns nil when it should return true.
Just out of curiosity I tried this same thing on another Rails app, and miraculously it worked on that app
> page.evaluate_script("['a', 'b', 'c'].includes('b')")
=> true
So I'm scratching my head as to why it would work on one app but not another?
App #1 (Failure)
Capybara 2.18.0
Capybara Webkit 1.15.0
App #2 (Success)
Capybara 2.13.0
Capybara Webkit 1.14.0
In fact the first app where it failed seems to have a more recent version of Capybara/Webkit..
Thanks!
capybara-webkit gets it's JS support based on the version of QtWebkit it is built against. The last released stable version of QtWebkit supported ES5 (and most of ES 5.1) and is basically equivalent to a 6-7 year old version of Safari.
Since Array.prototype.includes() wasn't included in the JS standard until ES2015 it is not supported natively by capybara-webkit. You can however add support for includes via a polyfill and I'm guessing that's what you have in your App #2.
In order for capybara-webkit to be useful with modern apps you need to make sure all JS used in your app is transpiled to ES5 and polyfilled (using babel, etc). If your apps requirements don't include old/obsolete browsers a better solution for headless testing is to use headless Chrome or Firefox via capybaras selenium driver since those combinations support modern JS and CSS.
According to the docs, execute_script will perform and javascript much better, I have replaced evaluate with execute in my e2e tests
newbie. I would like a full list of the rspec api - particularly the built in matchers. It appears this web site: http://www.relishapp.com/rspec/rspec-expectations/v/3-4/docs/built-in-matchers appears to be done base on version.
the problem I have is, lets say I need a have(n).items matcher. I would have no idea this matcher existed by looking at version 3.4. I would potentially have to view all ~20 versions to discover it. Why is it done this way? Doesn't this seem like an awkward way to publish an API? is there a full list somewhere? :)
That matcher was removed in RSpec 3:
http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/
To find which matchers are available, check your Gemfile.lock to see which version of RSpec is in use, then refer to the corresponding documentation.
I've been trying to test a pusher app with Poltergeist. So far I've only had success with capybara-webkit. I've created a minimal example app which demonstrates this in a spec. The spec passes with capybara-webkit but fails with Poltergeist.
Am I missing something or is this type of Pusher (WebSocket) testing not possible with Poltergeist at the moment ?
Thanks in advance.
Update your Pusher javascript library to 2.1.5 (or higher) and it should work (assuming you are also using PhantomJS 1.9 or higher).
Poltergeist automates PhantomJS. PhantomJS does support WebSockets, however it's an older version (until PhantomJS 2.0 comes out, see https://github.com/ariya/phantomjs/issues/11018). The Pusher javascript library also supports various versions of WebSockets so in theory they should work together.
In practice I had trouble getting it to work when using version 2.1.3 of the Pusher JS library (and from the date of this question I imagine you were using an even older version). As of 2.1.5 my poltergeist tests are successfully testing Pusher functionality.
Is it possible to use the page-object gem and capybara to automate Ruby on Rails testing? When I attempt to access a page object after starting up my test I receive the following error:
Unable to pick a platform for the provided browser (RuntimeError)
This makes sense as I think I'd have to pass the browser instance of capybara to the page-object, not sure if anyone else has tried this before.
There is a gem that lets you use the Page Object pattern with capybara: SitePrism. Find it here: https://github.com/natritmeyer/site_prism
Currently there is no support for capybara but it has been requested a few times. Part of the challenge is that the API was built upon selenium and watir which are much richer than capy and in it would be a very large undertaking to build add that functionality to the page-object gem to make capy behave the same way.
I've thought several times about splitting the page-object gem into a "basic" form that will allow capybara to utilize and an "advanced" form that will add the additional capabilities found in selenium and watir but haven't seen enough demand.
https://github.com/andyw8/capybara-page-object looks like it started existing in the last 8 months or so.
I want to use nokogiri for my rhodes mobile application. I got an error like
Error: no such file to load --nokogiri.
How can i use nokogiri in rhodes ?
I would imagine (though I haven't used Rhodes properly myself) that due to the way it is written, gems that include C extensions, like Nokogiri, would not work on Rhodes.
Rhodes apparently includes both the Ruby standard ReXML as well as a lightweight implementation called RhoXML. I did find this link that might help: http://wiki.rhomobile.com/index.php/RhodesExtensions#XML_handling.
I went through the full exercise of trying to use nokogiri when I found a bug in REXML that I didn't want to use the workaround for. I was unsuccessful in adding the library. (I got it to the point where it would load, but every single parsed document returned nil.)
According to the developers who watch http://groups.google.com/group/rhomobile , they do not support nokogiri on the device -- only on the RhoSync platform.