watir get console error - ruby

How I can check browser console if there are any error?
I'm following the watir ubuntu tutorial:
require "selenium-webdriver"
browser = Selenium::WebDriver.for :firefox
browser.get "http://watir.com"

Easy , add this lines at the end
console_logs = browser.driver.manage.logs.get(:browser)
puts console_logs

Related

ruby cucumber tests on multiple browsers

I am using windows 10 32 bit ruby version 233, I am facing these issues with running the tests on a ie 11 browser and the chrome browser for the tests(using page object) that are already running on firefox browser,
ISSUE with IE: Watir::Exception::NoMatchingWindowFoundException:
browser window was closed (eval):1:in `process_watir_call'
ISSUE with Chrome: Errno::ECONNREFUSED: Failed to open TCP connection
to 127.0.0.1:9515 (No connection could be made because the target
machine actively refused it. - connect(2) for "127.0.0.1" port 9515)
i have used the following hooks for ie and chrome:
Before do
case $browser
when 'mozilla'
#browser = Watir::Browser.new :firefox
#browser.window.maximize
when 'chrome'
#browser = Watir::Browser.new :chrome, :profile => "default"
when 'ie'
#browser = Watir::Browser.new :ie
# #browser.window.maximize
# #browser.visible = true
else
#browser = Watir::Browser.new :firefox
#browser.window.maximize
end
# #browser = Watir::Browser.new :firefox
# #browser.window.maximize
# this file contains test data that needs to be changed if tests are being executed in a different environment
$test_data = YAML.load_file('features/support/input_data/data/login_information.yml')
# this file contains base URL that needs to be changed if tests are being executed in a different environment
FigNewton.load('default.yml')
end
I was able to run a small sample test on a separate project from ruby mine with Watir gem.
Is there any way to make it work on the existing firefox tests?
The problem with chrome has been fixed by using the right chromedriver version, but still having problems with the IE using watir.
Found the solution for IE too its something to do with the internet options security and lower down the security level and uncheck the Enable Protected Mode.

Uninitialized constant Selenium::WebDriver::Chrome::OptionsDid you mean? Selenium::WebDriver::Options (NameError)

Recently I went through the chrome headless browser selenium automation. I use Selenium-cucumber with ruby.Now I wanted to run my whole project in chrome headless mode using Selenium::WebDriver::Chrome::Options.
I updated selenium-webdriver, chrome driver and my chrome version is 61.0.3163.100
In order to get to know its working, I created test.rb with below code:
require "selenium-webdriver"
#configure the driver to run in headless mode
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = Selenium::WebDriver.for :chrome, options: options
driver.get('http://stackoverflow.com/')
puts driver.title
driver.quit
I was able to get the response as below:
>>ruby test.rb
[1012/112029.980:ERROR:devtools_http_handler.cc(786)]
DevTools listening on 127.0.0.1:12703
Stack Overflow - Where Developers Learn, Share, & Build Careers
Now as I got the response correctly I want to configure the driver to run my project in headless mode.
so I edited the env.rb file of the support folder:
Imported require 'selenium-webdriver' and edited the below part where we create driver instance:
else # else create driver instance for desktop browser
begin
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('headless')
options.add_argument('--disable-gpu')
driver = Selenium::WebDriver.for :chrome, options: options
driver.get('http://stackoverflow.com/')
puts driver.title
rescue Exception => e
puts e.message
Process.exit(0)
end
end
I ran the command >>cucumber BROWSER=chrome
uninitialized constant Selenium::WebDriver::Chrome::Options
Did you mean? Selenium::WebDriver::Options
Please help me to resolve this issue and How can I run my whole selenium-cucumber project in headless mode?

Error while loading win32ole

I'am trying to read the data from an excel file for automating a website, using RubyMine as my editor and watir-webdriver for automating my test. while doing this I get an Error in my rubyMine editor "cannot load such file -- win32_ole (LoadError)".
require 'watir'
require 'rubygems'
require 'roo'
require 'win32_ole'
browser = Watir::Browser.new :firefox
Given(/^Iam on guru99 site page$/) do
browser.goto "http://demo.guru99.com/v4/index.php"
xl = WIN32OLE.new('Excel.Application')
workbook = xl.Workbooks.open("C:\\Users\TekUser\Desktop.practiceExcel.xlsx")
wrksheet= workbook.Worksheets(1)
wrksheet.Select
username1= wrksheet.Range("a1").Value
password1= wrksheet.Range("b1").Value
end
When(/^I enter Username and password in the respected field$/) do
browser.text_field(:name, "uid").set(username1)
browser.text_field(:name,"password").set(password1)
end
Then(/^I click on login button$/) do
browser.button(:name,"btnLogin").click
end
The library name does not have an underscore. It should be:
require 'win32ole'

Selenium/Ruby unknown driver, firefox

I wrote a selenium test that I have working in chrome, I'm trying to get selenium to run the test in every browser. When I try and access firefox I get an error though.
Code up to the error...
require "rubygems"
require "selenium-webdriver"
driver = Selenium::WebDriver.for :Firefox
I get the following error on the line where driver is declared...
/Users/username/.rvm/gems/ruby-2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/driver.rb:49:in 'for': unknown driver: :Firefox (ArgumentError)
from /Users/samuelowens/.rvm/gems/ruby-2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver.rb:67:in 'for'
from test.rb:47:in `<main>'
Any idea why that might be and how to fix it? Is there an easy way to write a selenium test and check it in multiple browsers? Thanks.
Not capital case Firefox but firefox
driver = Selenium::WebDriver.for :firefox

Capybara - visit() not working with firefox

I'm a noob in cucumber and capybara, so please bear with me.
I'm trying to setup a cucumber project that uses chrome and firefox as the test platform. So far, I have got the test to work on chrome, but not on firefox.
Below is the code snippet:
require 'uri'
require 'net/http'
require 'fileutils'
require 'selenium-webdriver'
require File.dirname(__FILE__) + '/throttle.rb'
#CAPYBARA
require 'capybara/cucumber'
require 'capybara/session'
#require 'capybara-webkit'
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.register_driver :selenium_firefox do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
driver = case ENV['BROWSER']
when 'chrome'
:chrome
when 'firefox'
:selenium_firefox
when 'webkit'
:webkit
when 'ie'
:internet_explorer
else
:chrome
end
Capybara.default_driver = driver
Capybara.javascript_driver = :selenium_firefox
Capybara.run_server = false
Capybara.default_selector = :css
Then, for the test, I just simply did a visit("http://www.google.com").
If I set my browser parameter to chrome, it worked fine. Cucumber openned up chrome and automatically typed in "www.google.com", and the page loaded without a problem.
However, the moment I set it to firefox: $cucumber features/test.feature BROWSER=firefox, it didn't work. It did open up the firefox browser, but nothing was being automatically typed into the URL box.
So, I must be missing something in the setup process that I'm not aware of. I have been looking for solutions on the web (require 'selenium webdriver', put 'selenium webdriver' into my Gemfiles, etc.), but so far none has worked for me.
What am I missing here? How come visit() didn't automatically populate the URL box of firefox, but it did just fine with chrome?
Thank you for your help.

Resources