Open browser with URL in Ruby - ruby

I've been using the following to launch the default browser in OS X:
system('open', url)
This has been working fine until upgrading to Yosemite. Now, I frequently get this message when trying to open various URLS:
LSOpenURLsWithRole() failed with error -1712 for the URL http://blah.com
But sometimes that URL will work. I can try it once, and it'll work, another it might not. Very unpredictable.
I've tried all of these:
system("open #{url}")
`open #{url}`
Launchy.open(url, debug: true)
Launchy.open( "#{ url }" ) do |exception|
puts "Attempted to open #{url} and failed because #{exception}"
end
But they all exhibit this same behavior. There are several URLs being opened at once, like this:
urls.each do |url|
system("open #{url}")
end
How can I consistently open a specific URL in my browser on OS X using ruby?

It looks like you are pushing the Browser with too many urls at the same time.
Using sleep seems to work fine.
15.times {|i| `open http://google.com?q=#{i}` }
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=5.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=6.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=12.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=14.
# => 15
15.times {|i| sleep(0.2); `open http://google.com?q=#{i}` }
# => 15

Related

Watir: ignore invalid Browser certificates

I'm trying to tell Google Chrome to ignore invalid Browser certificates with the command line switch from official documentation [1]:
Watir::Browser.new :chrome, switches: ['--ignore-certificate-errors']
But I get the error:
ArgumentError: {:switches=>["--ignore-certificate-errors"]} are
unrecognized arguments for Browser constructor from
/var/lib/gems/3.0.0/gems/watir-7.1.0/lib/watir/capabilities.rb:79:in
`process_browser_options'
3.0.2 (dev)[1] »
How can I get rid of the error and tell Chrome to ignore the certificate?
[1] http://watir.com/guides/certificates/
Switches get passed on the args parameter:
Watir::Browser.new(:chrome, options: {
args: ['--ignore-certificate-errors']
})

Selenium + Ruby + Cucumber. Weird port error

# encoding: UTF-8
# language: ru
require 'webdrivers'
require 'selenium-cucumber'
options = Selenium::WebDriver::Options.chrome
driver = Selenium::WebDriver.for :chrome, options: options
#driver.get "https://www.google.com"
Given 'Переходим на сайт' do
driver.get "https://www.google.com"
end
sleep(2)
driver.quit
File .feature
# encoding: UTF-8
# language: ru
Функция: Тест
Сценарий: Тест тест
Дано Переходим на сайт
The code is as simple as possible. And it works if you remove the Given function and start opening the site not through cucumber. Everything works and opens. But if you open it through Given, an incomprehensible error with ports appears.
Failed to open TCP connection to 127.0.0.1:9515 (Connection refused - connect(2) for "127.0.0.1" port 9515) (Errno::ECONNREFUSED)
./features/step_definitions/test_steps.rb:23:in `nil'
Linux Mint
This is likely due to lazy initialization in Selenium. When you call driver.get "https://www.google.com" directly it's initializing the selenium driver and browser connection, so when driver.quit is called the connection is up and can then be cleanly shut down. However, when you call
Given 'Переходим на сайт' do
driver.get "https://www.google.com"
end
you are defining a block that can be called later, but it doesn't actually execute the driver.get ... yet, so the driver to browser connection isn't fully setup yet which leads to quit being called on a non-initialized connection and therefore raising an error.

launching appium server through python script gives error

I am launching appium server through terminal by command appium and in another terminal I run my test suite python test.py This works fine.
But if launch through python script I get error between 2 tests
def setup(self):
subprocess.Popen('appium', shell=False)
time.sleep(5)
desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = os.path.abspath('test.apk')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
return self.driver
error: Couldn't start Appium REST http interface listener. Requested port is already in use. Please make sure there's no other instance of Appium running already.
The error has no effect tests still pass
I tried adding killall node in teardown
def tearDown(self, driver):
self.driver = driver
self.driver.quit()
subprocess.Popen('killall node', shell=False)
but it gives me error
OSError: [Errno 2] No such file or directory
How can I get rid of error and stop appium server?
Setup is called through launch app -> click some buttons -> call teardown through close app

Getting pop-up error "Netscape.cfg/AutoConfig failed" when trying to drive firefox via selenium Grid using Watir-Webdriver

Get Error:
Netscape.cfg/AutoConfig failed. Please contact your system administrator.
Error: defaultPref failed: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.setBoolPref]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: prefcalls.js :: defaultPref :: line 58" data: no]
Netscape.cfg/AutoConfig failed. Error: defaultPref failed: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED)
I have the following setup:
Selenium Grid on CentOs 6.4
Slave Node = CentOs 6.4
Trying to run Firefox remotely via Watir-WebDriver
require "rubygems"
require "test/unit"
#require "selenium"
require "watir-webdriver"
caps = Selenium::WebDriver::Remote::Capabilities.firefox
#caps.version = "24"
caps[:name] = "Firefox 24 , port 5555"
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.native_events = true
driver = Selenium::WebDriver.for(:firefox, :profile => default_profile)
#browser = Watir::Browser.new(
:remote,
:url => "http://vm-auto.his.vm:4444/wd/hub",
:desired_capabilities => caps)
#browser.goto "google.com"
#browser.text_field(:name => "q").set "3M"
#browser.button.click
#browser.div(:id => "resultStats").wait_until_present
#browser.screenshot.save ("GoogleSearch_FF24.png")
#browser.close
Firefox version is Mozilla Firefox 24.7.0
there is a reference to this error in https://bugzilla.mozilla.org/show_bug.cgi?id=717438
the resolution being suggested as:
In my case commenting out this pref in mozilla.cfg stops generating this message.
But I do not know origin of this pref.
//stops the request to send performance data from displaying
//pref("toolkit.telemetry.prompted", true);
But, i could not find mozilla.cfg on the filesystem where firefox is installed
That error definitely seems to be related to a problem in the mozilla config file BUT in my case the file was not mozilla.cfg but mozilla-lock.cfg (located at C:\Program Files (x86)\Mozilla Firefox\).
The filename is dictated by the lockset.js file at C:\Program Files (x86)\Mozilla Firefox\defaults\pref\. The line is pref("general.config.filename", "mozilla-lock.cfg")
My issue with the config file was the following lines:
lockpref("security.tls.version.min", "1");
lockpref("security.tls.version.max", "3");
The values should be without quotes:
lockpref("security.tls.version.min", 1);
lockpref("security.tls.version.max", 3);
As addendum, it's entirely possible you don't have a config file at all and the problem exists with a manual configuration in the about:config. Open up the about:config page, and sort by 'status' to look for 'locked', 'user set' or any other non 'default' items.
I had the same issue with Firefox 24 ESR. Mozilla.cfg was in the same directory as the Firefox executable.
In my case this was under "%localappdata%\Microsoft\AppV\Client\Integration[Unique-Code]\Root".
I commented out 'pref("toolkit.telemetry.prompted", true);' and the error message didn't appear anymore.

Capistrano: The deploy has failed with an error: #<Errno::EPROTO: Protocol error # rb_file_s_stat

I am working to upgrade an app to Rails 4/Ruby 2/Cap 3. I feel as if I am 80% there. When running the following capistrano deploy task:
task :copy_shared_db_config do
on roles(:app) do
execute "mkdir -p #{shared_path}/config"
example_config_contents = File.read('config/database.example.yml')
upload!(example_config_contents, "#{shared_path}/config/database.yml", :via => :scp)
end
end
I receive the following error:
The deploy has failed with an error: #<Errno::EPROTO: Protocol error # rb_file_s_stat -
The deploy works fine when I am not using this task. The error mystifies me on where to start debugging.
Update:
I am almost positive that the error has to do with my usage of the update! method, which I believe puts this error into the realm of SSHKit.

Resources