I want to take a screenshot with each step executed, the code below is taking a screenshot during the entire execution.
How to fix this?
HOOKS.RB
AfterStep do
browser.screenshot.save 'screenshot.png'
encoded_img = #browser.driver.screenshot_as(:base64)
embed("data:image/png;base64,#{encoded_img}",'image/png')
end
ENV.RB
#encoding: utf-8
require 'rspec/expectations'
require 'watir'
require 'rspec'
require 'json'
require 'magic_encoding'
RESULT EXPECTED
I discovered that the environment that I was using was with outdated gems, I solved this with the gem update command.
After refreshing the gems, screenshots are now taken correctly.
Related
does anyone have an example of how to remove the records from the table before starting or after finishing the tests?
My tests are working perfectly fine and all that remains is to automatically remove the records in the table. If anyone has an example link I would be very happy.
use the gem database_cleaner
see: https://github.com/DatabaseCleaner/database_cleaner
Okay, the solution that worked!
1: install gems:
gem 'execjs'
gem 'date'
gem 'ruby-oci8'
gem 'sequel'
require:
require 'execjs'
require 'date'
require 'oci8'
require 'sequel'
in the page (siteprism) or step definitions
def delete_Inclusao
conn = OCI8.new('user', 'password','host:1521/services') conn.exec('table WHERE login = :1', 'xxxx')
conn.commit
end
I've this issue currently when launching my .rb, that says 1: from /var/lib/gems/2.7.0/gems/nokogiri-1.13.1-x86_64-linux/lib/nokogiri/xml/node.rb:56:in `<module:XML>' /var/lib/gems/2.7.0/gems/nokogiri-1.13.1-x86_64-linux/lib/nokogiri/xml/node.rb:59:in `<class:Node>': uninitialized constant Nokogiri::ClassResolver (NameError)
I've put theses lines in my .rb :
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.google.com/search?q=doughnuts'))
puts doc
and my Gemfile contains this :
source 'https://rubygems.org'
ruby '2.7.4'
gem 'rspec'
gem 'nokogiri'
gem 'open-uri'
Does anyone have any idea about the problem or oversight that is causing this error?
Thanks!
The "nokogiri" package updates version might have bugs so try to install lower version of nokogiri package after removes the new version....Try this,
I am not sure about it, I have read it in one senior developer post.
The following fixed it for me:
sudo apt-get remove ruby-nokogiri
This solves the problem for me:
require 'nokogiri/class_resolver'
require 'nokogiri'
Requiring the file that defines the constant (class_resolver) before the file that uses it makes it available, and therefore no error.
I am trying to run some older ruby script (with old ruby version) from within a ruby script. Here is a program:
old_ruby187.rb
#!/usr/ruby/1.8.7/bin/ruby
puts "Hello"
new_ruby230.rb
#!/usr/ruby/2.3.0/bin/ruby
require "rubygems"
require "bundler"
Bundler.setup # Code works if I comment this line
puts `old_ruby187.rb`
I get bundler load error. If I execute ./new_ruby230.rb, it gives an error for the last puts command line.:
'require': no such file to load -- rubygems (LoadError)
If I comment just Bundler.setup and run it, it works fine. Not sure if Bundler.setup tries to load something for system call. I need bundler for other gems used in new_ruby230.rb script.
Any help is appreciated.
Update (02/22/2018):
I ended up using ssh when calling old ruby script. Something like:
new_ruby230.rb
#!/usr/ruby/2.3.0/bin/ruby
require "rubygems"
require "bundler"
require "socket"
Bundler.setup
puts `ssh #{Socket.gethostname} old_ruby187.rb` # this worked!
Pretty sure you're not supposed to require rubygems like that. Bundler is there to manage your gems. Remove that require statement (require "rubygems") and you should be good to go.
I want to disable ActiveRecord in Rails 4. I did the following in config/application.rb
require File.expand_path('../boot', __FILE__)
# require 'rails/all' -- commented
require "action_controller/railtie"
require "action_mailer/railtie"
#require "active_resource/railtie" no need
#require "rails/test_unit/railtie" no need
#require "sprockets/railtie" no need
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module MyApp
class Application < Rails::Application
config.app_middleware.delete "ActiveRecord::ConnectionAdapters::ConnectionManagement"
end
end
By I have an error of
/home/alex/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configuration.rb:95:in
method_missing: undefined method active_record for #<Rails::Application::Configuration:0x00000002005c38> (NoMethodError)
If you are creating a new application, you can use -O to skip ActiveRecord:
rails new my_app -O
For existing applications:
1. Remove database adapter gems from your Gemfile (mysql2, sqlite3, etc.)
2. Change your config/application.rb
Remove require 'rails/all line and require frameworks (among those available in your rails version, the list varies, do not just copy) you want to use, for example:
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
Remove config.active_record.raise_in_transactional_callbacks = true from config/application.rb
3. Delete your config/database.yml file, db/schema.rb and migrations (if any)
4. Delete migration check in test/test_helper.rb
5. Delete any ActiveRecord configuration from your config/environments files (this is what is causing your error)
This is all you need to do for an empty Rails app. If you run into problems caused by your existing code, stack trace should give you sufficient information on what you need to change. You might for example have some ActiveRecord configuration in your initializers.
Hi this is what the default rails new new_app -O gives
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
inside your config/application.rb
Additionally, it comes without database.yml and NO db/migrate/* and schema.rb
Since this is still the first hit when searching Google for disabling active record for Rails 5, I'll add this here:
For Rails 5
Do all the steps in #mechanicalfish answer, but also remove the line
Rails.application.config.active_record.belongs_to_required_by_default = true
from
config/initializers/new_framework_defaults.rb
For those using the rails-api gem you may encounter a similar error when using the --skip-active-record flag when doing rails-api new my_api. The current fix (until a new corrected version of the gem is released) is to edit your rails-api gem to have this commit. Use bundle open and replace the old Gemfile with the new corrected one. Rerun and you should be all set.
For disable ActiveRecord in Rails 4.2 you may create config/initializers/middleware.rb
Rails.application.middleware.tap do |middleware|
middleware.delete ActiveRecord::Migration::CheckPending
middleware.delete ActiveRecord::ConnectionAdapters::ConnectionManagement
middleware.delete ActiveRecord::QueryCache
end
See the terminal rake middleware
For Rails 5:
If you are generating a new app
Use --skip-active-record option to generate an application without a database:
rails new myApp --skip-active-record
Notice the extra hyphen '-' as opposed to previous versions of Rails.
For Rails Plugins (or gems) with a spec/dummy app
When your rails app lives in spec/dummy and you start your server from the plugin-root directory. You might still getting following error:
Cannot load `Rails.application.database_configuration`: Could not load database configuration. No such file - ["config/database.yml"]
To avoid this, remove require rails/all inside the file bin/rails and require frameworks you want to use, for example:
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_cable/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
For Ruby On Rails version 5.1.x
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
I'd like to use bundler/setup to include all of my listed gems but I'm not
succeeding. In go.rb I have
require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
which fails to require httparty as I thought it would:
$ bundle exec ruby go.rb
go.rb:5:in `<main>': uninitialized constant HTTParty (NameError)
What am I doing incorrectly?
I've created a small project for this question, here.
As far as I understand 'bundler/setup' it only manages the require path (removes the default contents and adds paths for gems that are defined in Gemfile.lock). If you don't require the libraries in question, their contents won't be available.
I believe the problem in your particular case is the following snippet:
File.expand_path('Gemfile', __FILE__)
If I run this from a file called /foo/bin/somescript, what the above code expands to is /foo/bin/somescript/Gemfile. Presumably what you actually want is /foo/bin/Gemfile, which you can get with:
File.expand_path('../Gemfile', __FILE__)
So, repeating your original code with the correction:
require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
This seems to work for me, to have files in my ~/bin directory have access to libraries I've installed by running bundle install within that directory, as specified by the Gemfile therein.