Problem connecting to localhost with watir - ruby

I have a set of cucumber tests that normally run fine against our site. But if I make any changes and want to run the tests locally, the tests fail immediately, even before the initial page is finished loading.
I tried in IRB without cucumber and get the same error, using the following code:
require 'rubygems'
require 'watir'
browser = Watir::Browser.new
browser.goto("http://localhost:1234/somepath")
browser.text_field(:id, 'Username').set('jimbob')
Which fails with the following:
WIN32OLERuntimeError: unknown property or method `document'
HRESULT error code:0x800706b5
The interface is unknown.
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.7.1/lib/watir/ie-class.rb:467:in `method_missing'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.7.1/lib/watir/ie-class.rb:467:in `document'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.7.1/lib/watir/container.rb:836:in `locate_input_element'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.7.1/lib/watir/input_elements.rb:5:in `locate'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.7.1/lib/watir/element.rb:55:in `assert_exists'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.7.1/lib/watir/input_elements.rb:366:in `set'
Versions:
OS: Windows 7
Browser: IE8
Ruby: 1.8.7 (I tried using 1.9.2, but it didn't have a problem)
Watir: 1.7.1

You need to run as Administrator on Windows 7 when using Watir against localhost.
Credit to http://chowamigo.blogspot.com/2010/03/setting-up-cucumber-to-use-watir-test.html

Same thing applies to Server2008 btw gotta run the command line window as admin in order for watir to work correctly. Something to do with IE security I'm sure.

Related

When running an application under ruby 2.3.1 using the rails server command, the following error occurs: can not modify a frozen array (RuntimeError)

I have to run an application developed in Ruby on rails. ruby 2.3.1 and rails 4.2.0
When I execute the rails server command. I get the following error:
.... config / initializers / doorkeeper.rb: 75: in <top (required)>: can not modify a frozen array (RuntimeError).
Can I explain how to succeed to no longer have this error, thank you
Info :
The "bundle install" command runs successfully.
The code around doorkeepee.rb near line 75 : Doorkeeper.configuration.token_grant_types << "password"
I'm trying to understand how RAIL_ENV works. Can you help me at the same time?

Error: unknown error: DevToolsActivePort file doesn't exist, when executing ruby script with watir

I am fairly new to Centos7 and trying to develop a solution for browser automation in the below environment:
OS: Centos7
Ruby: 2.6
Watir
Browser:Google Chrome 72.0.3626.109
Driver: ChromeDriver 2.46.628388
My script:
require 'watir'
# Initialize the browser with the driver path
site="https://google.com"
browser = Watir::Browser.new :chrome
browser.goto site
Getting error:
`assert_ok': unknown error: Chrome failed to start: exited abnormally (Selenium::WebDriver::Error::UnknownError)
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 3.10.0-957.5.1.el7.x86_64 x86_64)
I found multiple solutions on net that are recommending to modify chrome options like:
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
But I don't know where to set these. The nearest I was able to reach is the answers provided here: How do I pass options to the Selenium Chrome driver using Python?
Can anyone please help me to resolve it in a step-by-step manner?
Also faced similar issue but with npm and protractor configuration but I guess the solution would be similar. You have to install chrome browser in your linux system.
The chromedriver is just a wrapper written to use the chromebrowser for running the test cases.
Also if google-chrome is installed you might want to check the path were it is installed in linux based operating system the path expected is under /usr/bin/google-chrome. This file is generally a link to the actual binary of the chrome.
Hope so this helps

How to resolve unable to connect to chromedriver 127.0.0.1 in ruby

I am using chrome driver 2.35(tried till v 2.9) and chrome browser v 65.
gems used:
watir 6.10.3
selenium-webdriver 3.11.0
error message:
Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/service.rb:142:in `connect_until_stable'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/service.rb:72:in `block in start'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/socket_lock.rb:39:in `locked'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/service.rb:69:in `start'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/chrome/driver.rb:42:in `initialize'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/driver.rb:44:in `new'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.11.0/lib/selenium/webdriver.rb:85:in `for'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.10.3/lib/watir/browser.rb:48:in `initialize'
I downgraded the chrome version to 62 and disabled auto update to resolve this issue.
Older version available here
Before installing the older version some steps needs to be followed.
Uninstall current version of chrome
Navigate to C:\Users\\AppData\Local and delete google
directory
Navigate to C:\Program Files (x86) and delete google directory
Install the intended older version
Don't open the chrome browser,chrome gets updated automatically.
Type 'msconfig' in run command and ensure google update services are in 'stopped' status
Navigate to 'C:\Program Files (x86)\Google' and rename 'update'
directory to some other name.If renaming is denied ensure that all
chrome related tasks are closed in task manager and then try
renaming.
Now open chrome and navigate to Help->About Google Chrome.If you get
a error message for update then chrome won't get updated.
I had the same issue, unable to connect chromedriver. So instead of using different chrome driver versions, I have just added gem called chromedriver-helper to my gem list, now works fine.

Random Segmentation Faults (Incomplete Responses) caused by Rails/Nokogiri

I recently updated my Rails application from Rails 3 to Rails 4 and updated Ruby from 1.9 to 2.3. (I later tried 2.2 and 2.1 with the same results).
I'm using Passenger with NGINX. The application runs fine for the most part, but, once every 10 or so requests, was randomly returning this message to the browser:
Incomplete response received from application
The NGINX logs showed the following:
[Client 2-623] Sending 502 response: application did not send a complete response
28741/7f94e2312700 age/Cor/CoreMain.cpp:819 ]: Checking whether to disconnect long-running connections for process 2521, application /home/admin/apps/<myapp>/current/public
App 2059 stderr: request_handler/thread_handler.rb:226 ]: *** Passenger RequestHandler warning: someone tried to connect with an invalid connect password.
stderr: /home/admin/apps/<myapp>/shared/bundle/ruby/2.2.0/gems/builder-3.2.2/lib/builder/xchar.rb:146:
stderr: [BUG]
stderr: Segmentation fault at 0x00000000000000
After some debugging, I found that the issue seemed to be a strip_tags call within my view, and removing it stopped the issue. I assume the segmentation fault has something to do with Nokogiri since Rails sanitization is done by Nokogiri in Rails 4.
This issue is very hard to debug because helper.strip_tags seems to work fine in the console, yet it is causing these issues in the view.
I tried the following to fix the issue with no success:
Make sure libxml2 and all related Nokogiri libraries are installed and up-to-date
Build Nokogiri with and without --use-system-libraries, with and without specifying specific library locations, same issue with any config.
Build with Nokogiri 1.6.0 and 1.6.7. Neither works, although an additional Rails mailer segfault seems to appear when using 1.6.7.
Built on Ruby 2.1, 2.2, 2.3 using RVM. All have the same issue.
Rails 4 secrets.yml is set up correctly with the secret_key_base key.
With strip_tags included, I also get the following Rails application errors randomly. Sometimes the page loads fine, sometimes these errors are triggered:
RuntimeError: rehash occurred during iteration
<my controller>#index
[GEM_ROOT]/gems/nokogiri-1.6.0/lib/nokogiri/xml/document.rb, line 210
NoMethodError: undefined method `empty?' for false:FalseClass
<my controller>#index
[GEM_ROOT]/gems/haml-4.0.7/lib/haml/compiler.rb, line 193

'Learn Ruby on Rails' tutorial: Can't submit contact form

I am getting the error below following the tutorial in the book Learn Ruby on Rails.
I am able to launch my app manually by typing the URL into my browser but am wondering why Heroku open does not work.
Any idea what is happening here?
Heroku open error...
$ heroku open
Opening peaks-app... failed
! Heroku client internal error.
! Search for help at: https://help.heroku.com
! Or report a bug at: https://github.com/heroku/heroku/issues/new
Error: Unable to find a browser command. If this is unexpected, Please rerun with environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file a bug at
https://github.com/copiousfreetime/launchy/issues/new (Launchy::CommandNotFoundError)
Backtrace: /home/action/.heroku/client/vendor/gems/launchy-2.4.2/lib/launchy/applications/browser.rb:63:in `browser_cmdline'
/home/action/.heroku/client/vendor/gems/launchy-2.4.2/lib/launchy/applications/browser.rb:67:in `cmd_and_args'
/home/action/.heroku/client/vendor/gems/launchy-2.4.2/lib/launchy/applications/browser.rb:78:in `open'
/home/action/.heroku/client/vendor/gems/launchy-2.4.2/lib/launchy.rb:29:in `open'
/home/action/.heroku/client/lib/heroku/helpers.rb:328:in `block in launchy'
/home/action/.heroku/client/lib/heroku/helpers.rb:227:in `action'
/home/action/.heroku/client/lib/heroku/helpers.rb:326:in `launchy'
/home/action/.heroku/client/lib/heroku/command/apps.rb:342:in `open'
/home/action/.heroku/client/lib/heroku/command.rb:217:in `run'
/home/action/.heroku/client/lib/heroku/cli.rb:33:in `start'
/home/action/.parts/bin/heroku:24:in `<main>'
Command: heroku open
Version: heroku-toolbelt/3.12.1 (x86_64-linux) ruby/2.1.1
The short answer is that Heroku uses Launchy to launch my app and Launchy is looking for my browser. Since I am using Nitrous.io, I do not have a browser installed, so Launchy does not know what to do.
The author of Launchy explains that "...launching a browser from within the virtual box would do nothing if there was no browser installed." https://github.com/copiousfreetime/launchy/issues/78
Launching manually appears to be my only option at this point.

Resources