NoMethodError - undefined method `now' for Watir::Time:Class - ruby

I get the following error anytime I try to interact with a Watir element.
/Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/wait/timer.rb:40:in `current_time': undefined method `now' for Watir::Time:Class (NoMethodError)
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/wait/timer.rb:6:in `initialize'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:656:in `new'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:656:in `element_call'
from /Library/Ruby/Gems/2.0.0/gems/watir-6.0.1/lib/watir/elements/element.rb:114:in `click'
from fund_cc.rb:8:in `<main>'
Here is my code:
require 'watir'
# require 'time'
b = Watir::Browser.new(:chrome)#, :url => "http://localhost:9515")
b.goto "https://www.bankofamerica.com/"
contact_us= b.link(:text, "Contact Us")
contact_us.click
Does anyone know how to resolve this?

This should be fixed in version 6.0.2.
From Titus Fortner on the Watir-General mailing list:
The latest version of Watir attempts to use monotomic time where
supported and it looks like we grabbed the wrong Time class for where
it is not supported.
I just updated and pushed the fix to 6.0.2. You should be able to just
bundle update now.

I was able to reproduce this behavior. You can monkey patch your gem locally by tweaking the current_time method in /lib/watir/wait/timer.rb:
def current_time
::Time.now.to_f # was Time.now.to_f
end
And I'd suggest logging an issue on https://github.com/watir/watir/issues.

Related

Watir - Error when I try to take screenshot of div

I use Watir and Watir-element-screenshot to get screenshot of elements.
Browser: Chrome and Firefox (latest versions)
My code:
require 'watir'
require 'watir/extensions/element/screenshot'
browser = Watir::Browser.new :firefox
browser.goto 'google.com.ua'
browser.text_field(id: "lst-ib").set "ruby\n"
browser.window.maximize
browser.element(id: "resultStats").screenshot("2.png")
browser.close
And take this error:
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/color.rb:968:in `scanline_bytesize': undefined method `>>' for 2439.0:Float (NoMethodError)
Did you mean? >
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:207:in `encode_png_image_pass_to_stream'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:174:in `encode_png_image_without_interlacing'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:161:in `encode_png_pixelstream'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:85:in `to_datastream'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/image.rb:62:in `to_datastream'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:35:in `write'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:43:in `block in save'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:43:in `open'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:43:in `save'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/watir-extensions-element-screenshot-0.0.3/lib/watir/extensions/element/screenshot.rb:12:in `screenshot'
from 2.rb:11:in `<main>'
What the reason of this message and how can i repair it?
You can use this code to take screen shot and save in specific location.
browser.screenshot.save("path to save image/2.png")

Using ruby and aws-sdk to pull ec2 tags

Folks,
I am trying to pull in the EC2 tags via ruby aws-sdk and iam roles. The following bit of code produces error below. What am I doing wrong?
require 'rubygems'
require 'aws-sdk'
require 'fileutils'
ec2 = AWS::EC2.new()
instance_id = `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
outdir = '/opt/facts/tags/'
unless File.directory?(outdir)
FileUtils.mkdir_p(outdir)
end
ec2= AWS::EC2.new()
instance = ec2.instances[instance_id]
tags = instance.tags
tags.each do |num|
File.open(outdir+num[0], "w") do |f|
f.write(num[1])
end
end
Following output:
/usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/http/connection_pool.rb:127:in `session_for': undefined method `continue_timeout=' for #<Net::HTTP ec2.us-east-1.amazonaws.com:443 open=false> (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/http/net_http_handler.rb:52:in `handle'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:236:in `make_sync_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:262:in `retry_server_errors'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:229:in `make_sync_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:489:in `client_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:371:in `log_client_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:457:in `client_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:353:in `return_or_raise'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/core/client.rb:456:in `client_request'
from (eval):3:in `describe_tags'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/ec2/filtered_collection.rb:44:in `send'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/ec2/filtered_collection.rb:44:in `filtered_request'
from /usr/lib/ruby/gems/1.8/gems/aws-sdk-1.9.0/lib/aws/ec2/resource_tag_collection.rb:156:in `each'
from ./puppetclient.rb:22
That seems to be a bug that was already reported today: undefined method `continue_timeout=', you could try pointing to the main branch of the git repository since there's already a patch for it.
Edit:
You can already point the latest version in rubygems since they already deployed the fix on version 1.9.1:
https://rubygems.org/gems/aws-sdk
There was a bug announced today in AWS-SDK-ruby https://github.com/aws/aws-sdk-ruby/issues/232
You can fix it by updating your gemfile
gem 'aws-sdk', "1.9.1"
And then running "bundle"

Ruby NoMethodError in Redmine from script/runner

I have some Ruby code I need to execute in the Redmine Ruby app in order to enable a module in all projects at once.
Surprisingly, ruby does access the Projects, but raises a NoMethodError when accessing a few particular methods inside each of the "Project" objects.
Here is the code:
Project.find(:all).each do |project|
print "Enabling modules for project '#{project.identifier}' ... "
puts project.methods.sort # this does print "enabled_module_names"
puts project.enabled_module_names
end
This fails with:
hostname:/srv/apps/redmine# script/runner vendor/plugins/customplugin/lib/enable_modules.rb
/var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:260:in `method_missing': undefined method `enabled_module_names' for #<Project:0x7f28985c1cb0> (NoMethodError)
from vendor/plugins/customplugin/lib/enable_modules.rb:14
from vendor/plugins/customplugin/lib/enable_modules.rb:7:in `each'
from vendor/plugins/customplugin/lib/enable_modules.rb:7
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `eval'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:46
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/runner:3
I have scratched my head a lot, but I can't grasp why would the code find the "Project" symbol but not the methods within, especially as "project.methods" does indeed list "enabled_module_names".
Any help most welcome.
Are you sure that enable_module_names is an instance method?
Is it within Project.instance_methods?
Edit (summary of the comments below):
In earlier versions, you have to use following:
enabled_module_names = project.enabled_modules.collect(&:name)
The getter is present in later versions only (see rev.4460 for details of this change)

RSpec view test using RR failing - undefined method stub

I am using Rails 3.1, RSpec 2.6, and rr 1.0.4 and I get a NoMethodError:
undefined method `stub' for #<Activity:0x007faa90996190>
I am trying to utilize the RSpec test below to test my "Activities" show.haml view. If I change my spec_helper.rb file to use RSpec for mocks instead of rr then the test passes. I have tried changing the syntax of the code but to no success.
I found several websites stating that RSpec and rr do not "play well together and one person provided this rpsec-rr solution which did not work for me.
This is my show.haml_spec.rb
require 'spec_helper'
describe "activities/show.haml" do
before(:each) do
#activity = assign(:activity, stub_model(Activity))
end
it "renders attributes in .haml" do
render
end
end
This is the output from my Eclipse compiler using Aptana Studio
Failures:
1) activities/show.haml renders attributes in .haml
Failure/Error: #activity = assign(:activity, stub_model(Activity))
NoMethodError:
undefined method `stub' for #<Activity:0x007faa90996190>
# ./spec/views/activities/show.haml_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.15479 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/views/activities/show.haml_spec.rb:8 # activities/show.haml renders attributes in .haml
Any recommendation to an alternate syntax would be greatly appreciated!!
Note that as of RR 1.0.5 (released 3/28/2013) this problem should no longer be present -- RR is fully compatible with RSpec 2.

What is ths error in Ruby Watir (WIN32OLERuntimeError: unknown property or method `document')?

I have this code in Ruby waitr ..
$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'..') if $0 == __FILE__
require 'test/unit'
require 'Watir'
require 'Watir/contrib/enabled_popup'
class TC_Dialog_Test<Test::Unit::TestCase
$ie=Watir::IE.new
$ie.bring_to_front()
$myDir = File.expand_path(File.dirname(__FILE__))
def setup
$ie.goto "file://#{$myDir}/aa.html"
end
def test_confirm_OK
sleep(3)
$ie.button(:id, 'btnConfirm').click_no_wait
$hwnd = $ie.enable_popup(5)
if ($hwnd)
$popup =WinClicker.new
$popup.makeWindowsActive($hwnd)
sleep(3)
# $popup.clickWindowsButton($hwnd,"OK")
puts "you pressed Comfirm-ok"
sleep(3)
end
end
end
when runnung this code get this error results ...
test_confirm_OK(TC_Dialog_Test):
WIN32OLERuntimeError: unknown property or method `document'
HRESULT error code:0x800706b5
The interface is unknown.
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/ie.rb:417:in `method_missing'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/ie.rb:417:in `document'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/container.rb:767:in `ole_inner_elements'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/container.rb:838:in `locate_input_element'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/input_elements.rb:10:in `locate'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:47:in `assert_exists'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:278:in `enabled?'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:53:in `assert_enabled'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.3/./watir/element.rb:214:in `click_no_wait'
Mo.rb:16:in `test_confirm_OK'
You are using Watir 1.5.3, but the current stable is 1.8.1. I suggest you to update your gem to the latest and try again. There is a good chance that the WIN32OLE object for IE has changed it's behavior and old gem is conflicting with it. (Have you updated IE or smth since last successful run?)
I got the same error using Watir 1.8.1. I don't know if there is anything wrong with your code, but in my case the tests ran fine on other machines.
I am running my tests in RubyMine 3.1.x. Running RubyMine as Administrator allowed Ruby to have the rights to interact with IE properly and the problem went away.
Edit:
Found the forum post which originally helped me solve the problem.

Resources