capybara how to get operating system info - selenium

I need to get the operating system info to handle OS related tasks. I tried to get it via page.driver.browser but it doesn't return os info. It could be in header but there is no function header.
How can I get OS information by page object?
irb#1(main):016:0> page.driver
=> #<Capybara::Selenium::Driver:0x007f84a35c0858 #app=nil, #browser=#<Selenium::WebDriver::Driver:0x1a664c8c1eb09ac0 browser=:firefox>, #exit_status=nil, #frame_handles={}, #options={:browser=>:firefox}>
irb#1(main):017:0>
irb#1(main):018:0* page.driver.browser
=> #<Selenium::WebDriver::Driver:0x1a664c8c1eb09ac0 browser=:firefox>
irb#1(main):019:0>
irb#1(main):020:0* page.driver.browser.header
NoMethodError: undefined method `header' for #<Selenium::WebDriver::Driver:0x007f84a34cb9e8>

Using selenium you should be able to look at
page.driver.browser.capabilities.platform
That will only work for the selenium driver though, not the other available capybara drivers

In your ruby console you can run
Config::CONFIG["host_os"]
Or
RUBY_PLATFORM
OUTPUT:
2.0.0-p598 :001 > Config::CONFIG["host_os"]
(irb):1:in `irb_binding': Use RbConfig instead of obsolete and deprecated Config.
(irb):1:in `irb_binding': Use RbConfig instead of obsolete and deprecated Config.
=> "linux-gnu"
2.0.0-p598 :001 > RUBY_PLATFORM
=> "x86_64-linux"
Hope it helps!

Related

Sinatra and PostgreSQL - running the entire database and app

I have been struggling with rerunning my apps from MAC OS to my windows OS. I have never liked databases. Anyway, the thing is that I cannot even load up my seeds. It looks like it cannot run the pg gem methods. Here's my error
:in `ensure in run': undefined method `close' for nil:NilClass (NoMethodError)
here's the code the method gets stuck on
require_relative('../models/collection')
require_relative('../models/product')
require('pry')
Product.delete_all()
Collection.delete_all()
fw2015 = Collection.new({
'name' => 'Fall Winter 2015/2016'
})
fw2015.add()
I am pretty sure that it's something with postgres. Thank you for your help
This is a gem issue, not a PostgreSQL issue. It is probably relating to the fact that there are binary portions of the gem and they may not be building right. So you need to make sure that you have the PostgreSQL client libraries and header files installed, and that you have all necessary compilers.
Try uninstalling and re-installing the gem and see what errors and warnings show up.

Locking the version of PhantomJS that Poltergeist uses

I have a Ruby on Rails app that runs feature tests using Capybara, Poltergeist and PhantomJS.
Version 2.0.0 of PhantomJS has a rather significant bug that breaks a lot of tests (https://github.com/ariya/phantomjs/issues/12506) so I'd like to force the app to use a different version of PhantomJS when running the tests.
Is this possible from within Poltergeist's configuration, to raise an error or a warning if this buggy version is used, or is my best bet simply putting a note in the app's readme saying 'don't use version 2.0.0 due to this bug'?
at the moment my Capybara/Poltergeist configuration is very basic:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :timeout => 90)
end
As #pguardiario commented, you can just do something like
if `phantomjs -v`.start_with? '2'
#output whatever kind of warning you want
end
however the Poltergeist master branch has a fix for that particular issue so you could just try using that instead

Capybara Webkit Capybara::Webkit::ConnectionError failed to start

I'm using capybara webkit on Ubuntu (14.04 LTS) and I'm getting the following error when trying to use it:
Capybara::Webkit::ConnectionError: /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/bin/webkit_server failed to start.
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:75:in `parse_port'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:81:in `discover_port'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:62:in `start_server'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:25:in `initialize'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/driver.rb:17:in `new'
I installed QT using:
sudo apt-get install libqt4-dev libqtwebkit-dev libqt5webkit5-dev
Using gem versions: capybara (2.4.4) and capybara-webkit (1.3.1)
The same program works fine on mac (qt installed using homebrew)
Thanks
It has been a long time since this question was asked, but I had the same problem even though I used much more ancient versions of anything. It turned out that webkit needs to be able to connect to some X-Server and this is its reaction if it fails. I ended up installing xvfb and using
xvfb-run --auto-servernum bundle exec rake test
(aliased of course) when running my tests. This is probably less than optimal, but it was good enough for me. Maybe this helps the next person who stumbles across this error.
I beat my head against this all morning. Turns out I had omitted this code from rails_helper.rb :
if ENV['HEADLESS']
require 'headless'
headless = Headless.new
headless.start
at_exit { headless.stop }
end
We use the HEADLESS environment variable to trigger this. Not sure if that's typical or a local convention. Regardless, I needed to add export HEADLESS=1 to .env to fire that off.
I also had to add gem 'headless', '~> 1.0.2' in Gemfile.

No method error_messages selenium and capybara-webkit

When using capybara-webkit I have come across the issue of selenium not having an error_messages method, although, the documentation for capybara-webkit says that I should be able to access it through page.driver.error_messages once my flag on the scenerio is set with :js => true. However, trying to access it, it throws:
NoMethodError:
undefined method `error_messages' for #<Capybara::Selenium::Driver:0xc501fc0>
and I have tried to access the messages using:
page.should_not have page.driver.error_messages
I have also tried:
page.should_not :have_errors
as well as:
page.should_not have_errors
but with not avail.
My understanding is that error_messages is a method included in the capybara-webkit driver. It is not available for the selenium-webdriver driver.
Based on the exception you are getting, you are using the selenium-webdriver. By default, Capybara uses selenium-webdriver when :js => true is specified.
You likely want to change your javascript_driver to use :webkit (as mentioned in the usage documentation - https://github.com/thoughtbot/capybara-webkit).
Capybara.javascript_driver = :webkit

Ruby-on-rails gem failing for "where" condition of meta_where

I have a question about what is probably a gems problem, but may be meta-where. I used gems to install meta_where-1.0.4, and the response was that I succeeded and the uri for meta_where was provided, but when I tried a where-condition in the search method of a controller, similar to this example that meta-where provides:
Person.where(:skill_set.matches => 'Hello%'
an error was reported:
"undefined method 'matches' for :skill_set:Symbol"
It's as if the gem's methods aren't being accessed. I tried using "require" but that didn't help.
I'm using Windows XP, Firefox, Ruby 1.9.2.
What do I need to do?
Thanks, Barney
I assume you have run the migrations and there is a skill_set attribute in the person table: you don't need require. Just add 'gem meta_where' to your Gemfile and then run 'bundle install'.