new window creation in watir - ruby

I am new to watir. I am trying to create new ie window with
browser = Watir::Browser.new
but it gives error message like
`user_is_bewildered': Error in the default values: :browser's value must be one of 'ie', 'firefox', or 'safari', and '' doesn't look right. (StandardError)
I donno how to set default browser. Can some one help me? There is a another thread here. But I am not able to understand what i need to do in ffi.
Thanks

If this is the original Watir gem, then the following is how I used to launch it:
require 'rubygems'
require 'watir'
Watir::Browser.default = "firefox"
browser = Watir::Browser.new
# Whatever you want to do in watir
IamChuckB's answer may be a more efficient way of doing this, but having not used it, I'm not sure.

You need to tell it which browser to open. Try this:
browser = Watir::Browser.new :ff
I haven't played around with watir since my last job so I had to look this up. As I last recall, WATIR was not entirely integrated with FireWATIR (the Firefox based variant). It's good to see that the two have apparently been reconciled in the meantime.
Taken from Watir in Five Minutes on Zeljko Filipin's github, BTW.

To install devkit,
create a folder in the ruby directory called devkit
get the devkit from here
unpack it into the devkit directory created in step 1
add c:\ruby193\devkit\bin;c:\ruby193\devkit\wming\bin to your path, of course adjusting for your ruby install directory
now open a command prompt to install the gem again
c:\> gem install watir

The issue is resolved. Thanx for the the inputs. The issue was with wrong nokorigi gem installation, initially i installed x86-mswin32-60, i uninstalled it and tried with x86-mingw32, it solved.

Related

How to configure env.rb to start portable chrome (instead of local installation) with Ruby, Selenium and LapisLazuli

Question:
For my Test Automation Suite I would like to know how to configure/setup my portable Chrome to run instead of the local installed Chrome.
Reason:
There is an issue with the application I'm trying to test and Chrome Version 55. Issue: Certain buttons are since this version not clickable and I want to bypass this for the time being by using an older Chrome version.
I use Ruby version 2.3.0p0 (2015-12-25 revision 53290)
And LapisLazuli as described on www.testautomation.info
The setup itself is working. The answer might be simple, but I did not manage to get this running in this combination.
I found information about selenium/Java, but I have no idea how to get that to work with my setup.
Selenium not starting portable chrome but local installation
I also found this website: https://leanpub.com/watirbook/read
And here they mentioned the following:
3 > require "selenium-webdriver"
4 => true
5
6 > Selenium::WebDriver::Chrome.path =
7 'C:\chrome\chrome.exe'
8 => "C:\\chrome\\chrome.exe"
So I tried that in irb and this worked
require 'lapis_lazuli'
include LapisLazuli
Selenium::WebDriver::Chrome.path = 'C:\chrome_portable_v53\chrome.exe'
browser :chrome
The portable chrome version was started. Now I only need to know how to place this in my env.rb file (I assume), which looks currently like this:
require 'lapis_lazuli'
require 'lapis_lazuli/cucumber'
LapisLazuli::WorldModule::Config.config_file = "config/config.yml"
World(LapisLazuli)
I think the following is answering the question. I've added require selenium-webdriver and that Chrome.path to the env.rb and this seems to work.
require 'lapis_lazuli'
require 'lapis_lazuli/cucumber'
require 'selenium-webdriver'
Selenium::WebDriver::Chrome.path = 'C:\chrome_portable_v53\chrome.exe'
LapisLazuli::WorldModule::Config.config_file = "config/config.yml"
World(LapisLazuli)

how to use geckodriver with watir webdriver

I ran a bundle update yesterday night and selenium-webdriver got updated to the latest version.
My watir-webdriver tests pointed to firefox are now broken.
The error message said to add geckodriver to the path. On my mac, I copied geckodriver to the /usr/bin and ran the tests again.
This is the error I am getting now
unable to connect to Mozilla geckodriver 127.0.0.1:4444 (Selenium::WebDriver::Error::WebDriverError)
The watir-webdriver documentation does not seem to be updated on how to do this?
Did anyone manage to fix this
There is no extra documentation because there is nothing extra to do with Watir. It's finding the geckodriver file , but can't run it. Check to make sure it is executable on your system.
If your test not only just stick to firefox, you can use chromedriver instead of geckodriver, which is much easy, as far as my experience goes.
1, Add gem watir to your gemfile.
2, Download file on this page https://sites.google.com/a/chromium.org/chromedriver/downloads, and copy chromedriver to /usr/bin path.
3, And then just run it:
browser = Watir::Browser.start(url)
html = Nokogiri::HTML.parse(browser.html)
browser.close
4, Also, you can use headless to start a virtual X screen to hide browser windows like this:
headless = Headless.new
headless.start
browser = Watir::Browser.start(url)
html = Nokogiri::HTML.parse(browser.html)
browser.close
headless.destroy

RubyGems - require, file location and (load error) complications

very new to coding so, having exhausted Google and Stack Overflow, would really appreciate some advice...
I am currently building a web-scraper to get familiar with CMD vs Sublime Text, feeling Ruby in action; So i am working my way through this tutorial
After having actioned in CMD
C:\gem install HTTParty
SUBLIME TEXT - starts with this code:
require_relative 'HTTParty'
require_relative 'Nokogiri'
etc
But before i can get to anything more from CMD, i hit web_scraper.rb and it returns with:
C:/Users/ATH18/Desktop/nokogiri_tutorial/web_scraper.rb:1:in `require_relative': cannot load such file -- C:/Users/ATH18/Desktop/nokogiri_tutorial/httparty (LoadError)
from C:/Users/ATH18/Desktop/nokogiri_tutorial/web_scraper.rb:1:in `<main>'
[Finished in 0.1s with exit code 1]
I think this has to be due to one of the following:
i) maybe gems have to have their actual files dragged into whatever folder you're creating a new program in?
ii) i'm missing another piece of information that would let it run properly?
iii) perhaps there's another way to tell CMD/ruby that the "require"d gem is not in the current folder (I read this somewhere but their advice didnt seem to work either).
NOTE - i have done gem install xxxxxx in both the C:\ directory and C:\users\desktop\projectFolder\
Help?
You have to use require instead of require_relative. The difference between both a is explained here: https://stackoverflow.com/a/3672600/92049
Use require 'GEMNAME' for gems installed with gem install GEMNAME; use require_relative 'PATH' to require a file relative to the file containing require_relative. (Most often you will find yourself using require.)
To come back to your question: As it says in the tutorial, you have to write require 'HTTParty' instead of require_relative 'HTTParty'.
Does this answer your original question?

can't load gem in macruby

I just started using MacRuby for a simple Mac Application, and I now have a problem.
For my project I use the rmagick gem.
I installed it as described with the command
sudo macgem install rmagick
Everything worked well, but the problem is that if I try to load it in my AppDelegate.rb file with require 'rmagick'. I get an error saying that there is no such file to load.
This is strange, because I noticed that if I first build the project normally and then build the deployment target, I'm able to execute the application without any problems.
It would be really cool if there would be a way to use the gem in the development target, because otherwise I need 30 seconds after each change I made which in total is really much xD
Yeah RMagick can be a tricky one:
require 'rubygems'
require 'RMagick'
is the answer. Also macruby apparently still requires the require 'rubygems'. But beware, the module you actually will be using is called Magick.
A short example:
require 'rubygems'
require 'RMagick'
image = Magick::Image.new "path/to/image.png"
Here you will find the RMagick-documentation.

Sinatra cannot find views on Ruby 1.9.2-p0

I'm quite new to Ruby language (up to now I developed in Groovy + Grails) but since I was curious about it I wanted to try Sinatra on Ruby 1.9.2-p0.
I have a trivial website that is contained in /mywebpage and has 2 files:
# blog.rb
get '/' do
'Hello World!'
end
get '/impossible' do
haml :index
end
and
#config.ru
path = File.expand_path "../", __FILE__
$LOAD_PATH << (File.expand_path ".") + "/views"
require 'haml'
require 'sinatra'
require "#{path}/blog"
run Sinatra::Application
then in the same folder I have a /views/ folder that contains index.haml.
I try to run the server with rackup -p8080 but when I try to get /impossible I receive the following error:
Errno::ENOENT at /impossible
No such file or directory - /home/jack/mywebpage/<internal:lib/rubygems/views/index.haml
By searching over internet it seems that this maybe caused by "." not being included in $LOAD_PATH so I tried to add it or add directly views ./views so that actually $LOAD_PATH.inspect gives me correct path: ..., "/home/jack/mywebpage/views"]
But still it doesn't seem to work. Being quite new to the framework and the language I was wondering if I'm doing something wrong. any clues?
Running Sinatra with Ruby 1.9.2 the template directory is no longer implicitly 'views', you need to set it yourself.
set :views, File.dirname(__FILE__) + "/views"
Note that currently Ruby also has Kernel#__dir__() method that is equivalent to File.dirname(__FILE__).
This, and other issues with 1.9, will be have been solved in Sinatra 1.1. You could use this fork: http://github.com/rkh/sinatra/tree/1.1
I ran into a similar problem, and solved it like this. I didn't dig into the problem, but this is what I found and it works. It'll supposedly be fixed in the next version of Sinatra (which they should really get out the door, just to fix these few 1.9.2 bugs).
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
enable :run
get '/' do
"Hello, world!"
end
Edit: It seems there are multiple bugs with Sinatra on 1.9.2. This one will fix Sinatra apps not starting on 1.9.2. I don't use a views directory (I like to keep my apps single-file), so I didn't run into your particular problem. This fix most likely won't help you at all. I probably should have read your problem more closely..
gem install sinatra --pre
I ran into that last week and didn't find a suitable fix on the Sinatra site short of tweaking the sinatra code. I'm using rvm for my development and switched to try sinatra on Ruby 1.8.7 and it works fine again, so that's where I left it.
Oh, since you're new to Ruby, you might not know about rvm, so here's the lowdown. RVM is Mac only and highly recommended for managing your Ruby version and gems. It makes it trivial to have multiple Ruby versions and alternate groups of gems for development and testing. Everything is stored in your ~/.rvm directory so it's easy to blow it all away if you need to.
http://rvm.beginrescueend.com/
I just looked at the Sinatra site again about the problem to see if there was anything new, but it appears they consider the following to be an acceptable fix:
http://github.com/sinatra/sinatra/issues/#issue/50
I'm a bit adverse to having to edit the source of Sinatra as recommended by issue #50, but it's not real hard to do. I'd like to see them put out an update so we'd have an official fix but I haven't seen anything yet:
gem env will tell you the "GEM PATHS". Sinatra's gem will be in one of those. The line mentioned in issue #50 goes into base.rb. On my machine it's something like ...gems/ruby-1.9.2-p0/gems/sinatra-1.0/lib/sinatra/base.rb.
Insert:
/<internal:/, # ruby 1.9.2-p0 hacks
at line 1020.
Save the file and you should be good to go.

Resources