Selenium RC error unknown protocol: localhost - ruby-on-rails-3

I just begin to start use Selenium with Ruby on Rails 3, I have my code as
before(:all) do
#verification_errors = []
#selenium_driver = Selenium::Client::Driver.new \
:host => "localhost",
:port => 2195,
:browser => "*firefox C:/Program Files (x86)/Mozilla Firefox/firefox.exe",
:url => "localhost:3000",
:timeout_in_second => 60
#selenium_driver.start_new_browser_session
end
after(:all) do
#selenium_driver.close_current_browser_session
#verification_errors.should == []
end
it "should open the create new user page" do
page.open "http://localhost:3000/"
!page.is_text_present("translation missing").should be_false
page.click "link=Register"
page.wait_for_page_to_load "30000"
!page.is_text_present("translation missing").should be_false
page.is_text_present("New Account").should be_true
end
But when I'm trying to run them, I got
11:02:29.118 INFO - Command request: getNewBrowserSession[*firefox C:/Program Files (x86)/Mozilla Firefox/firefox.exe, localhost:3000, , ] on session null
11:02:29.118 INFO - creating new remote session
11:02:29.119 INFO - Allocated session 5cbd2c60271b490ea90eccb193cb1d84 for localhost:3000, launching...
11:02:29.119 ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: java.net.MalformedURLException: unknown protocol: localhost
at org.openqa.selenium.net.Urls.toProtocolHostAndPort(Urls.java:32)
at org.openqa.selenium.browserlaunchers.LauncherUtils.getDefaultRemoteSessionUrl(LauncherUtils.java:121)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:413)
at org.openqa.selenium.server.browserlaunchers.FirefoxLauncher.launchRemoteSession(FirefoxLauncher.java:110)
at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:373)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:125)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:87)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:786)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:423)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:394)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:147)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.net.MalformedURLException: unknown protocol: localhost
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.openqa.selenium.net.Urls.toProtocolHostAndPort(Urls.java:24)
... 19 more
11:02:29.121 INFO - Got result: Failed to start new browser session: Error while launching browser on session null
I didn't understand how come localhost become an unknown protocol, and I didn't find much help by my own searching.
Can someone help me please, thanks in advance

Localhost is becoming an unknown protocol because you're not specifying any protocol before it, you should change :url => "localhost:3000" to :url => "http://localhost:3000" to include the protocol (http).
Also, (at least on Selenium on Java) one usually uses relative paths when doing the equivalent of page.open.

Related

How do I use Capybara/Firefox with proxy on Heroku? I get "The proxy server is refusing connections"

I have the following code:
Capybara.register_driver :selenium_headless do |app|
...
proxy = Selenium::WebDriver::Proxy.new(
http: proxy_address,
ssl: proxy_address
)
desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(
proxy: proxy
)
Capybara::Selenium::Driver.new(app, {
browser: :firefox,
desired_capabilities: desired_caps,
...
})
end
driver = Capybara::Session.new(:selenium_headless)
driver.visit('https://api.ipify.org')
The code works without errors locally, as well as on Heroku if you remove all the proxy business (and forgo browser_options).
This code errors on Heroku with:
Selenium::WebDriver::Error::UnknownError (Reached error page: about:neterror?e=proxyConnectFailure&u=https%3A//api.ipify.org/&c=UTF-8&f=regular&d=Firefox%20is%20configured%20to%20use%20a%20proxy%20server%20that%20is%20refusing%20connections.)
That URL locally looks like this:
When I turn on Selenium debug logs Selenium::WebDriver.logger.level = :debug, I get:
>>> http://127.0.0.1:4444/session/84439a4e-a26d-41f3-ae30-f61f508ca569/url | {"url":"https://api.ipify.org"}
{"value":{"error":"unknown error","message":"Reached error page: about:neterror?e=proxyConnectFailure&u=https%3A//api.ipify.org/&c=UTF-8&f=regular&d=Firefox%20is%20configured%20to%20use%20a%20proxy%20server%20that%20is%20refusing%20connections.","stacktrace":"WebDriverError#chrome://marionette/content/error.js:179:5\nUnknownError#chrome://marionette/content/error.js:484:5\nhandleReadyState#chrome://marionette/content/listener.js:273:21\nhandleEvent#chrome://marionette/content/listener.js:242:14\n"}
My proxy options are logged roughly like "proxy":{"httpProxy":"207.000.00.00:0000","proxyType":"manual","sslProxy":"207.000.00.00:0000"}
Thanks in advance for the help!
Update: The proxy service I'm using works outside with Capybara. I test with OpenURI.

Symfony 3 : Doctrine:schema:update returns ConnexionException

on a machine with IP 178.33.13.83, i have a symfony app with the following parameters.yml :
parameters:
database_host: 178.33.13.80
database_port: null
database_name: alterxtn
database_user: alterxtn
database_password: ********************
But then when i try to doctrine:schema:update i recieve the following exception :
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [1045] Access denied
for user 'alterxtn'#'178.33.13.83' (using password: YES)
I'm wondering why it's trying to connect to the machine the app is installed on and not on the database_host
[Edit 1]:
here the exception with stacktrace, and please notice especially the Driver->connect() function that's taking the good params :
ConnectionException in AbstractMySQLDriver.php line 103:
An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'alterxtn'#'178.33.13.83' (using password: YES)
in AbstractMySQLDriver.php line 103
at AbstractMySQLDriver->convertException('An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'alterxtn'#'178.33.13.83' (using password: YES)', object(PDOException)) in DBALException.php line 145
at DBALException::driverException(object(Driver), object(PDOException)) in Driver.php line 47
at Driver->connect(array('driver' => 'pdo_mysql', 'host' => '178.33.13.80', 'port' => null, 'dbname' => 'alterxtn', 'user' => 'alterxtn', 'password' => '**********************************', 'charset' => 'UTF8', 'driverOptions' => array(), 'defaultTableOptions' => array()), 'alterxtn', '******', array()) in Connection.php line 360
[EDIT 2] :
i have the same error in shell so probably not a symfony problem
me#mymachine:$ mysql -h 178.33.13.80 -u alterxtn
ERROR 1045 (28000): Access denied for user 'alterxtn'#'178.33.13.83' (using password: YES)
It was my mistake.
The sql-user was set to server-privilege localhost
Setting it to % solved the issue.

ExAws not working on production release (Phoenix/Arc/ExAws)

I've been trying to create an uploader for avatars, but I've been facing some issues, the code works perfectly on dev, but on the production release, I get this error:
=SUPERVISOR REPORT==== 8-Jul-2016::22:35:41 ===
Supervisor: {local,'Elixir.ExAws.Supervisor'}
Context: child_terminated
Reason: {#{'__exception__' => true,
'__struct__' => 'Elixir.Poison.SyntaxError',
message => <<"Unexpected token: <">>,
token => <<"<">>},
[{'Elixir.Poison.Parser','parse!',2,
[{file,"lib/poison/parser.ex"},{line,56}]},
{'Elixir.Poison','decode!',2,
[{file,"lib/poison.ex"},{line,83}]},
{'Elixir.ExAws.InstanceMeta',security_credentials,1,
[{file,"lib/ex_aws/instance_meta.ex"},{line,16}]},
{'Elixir.ExAws.Config.AuthCache',refresh_config,2,
[{file,"lib/ex_aws/config/auth_cache.ex"},{line,37}]},
{'Elixir.ExAws.Config.AuthCache',handle_call,3,
[{file,"lib/ex_aws/config/auth_cache.ex"},{line,27}]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,615}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,647}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
Offender: [{pid,<0.2009.0>},
{id,'Elixir.ExAws.Config.AuthCache'},
{mfargs,
{'Elixir.ExAws.Config.AuthCache',start_link,
[[{name,'Elixir.ExAws.Config.AuthCache'}]]}},
{restart_type,permanent},
{shutdown,5000},
{child_type,worker}]
22:35:41.624 [error] Ranch protocol #PID<0.2011.0> (:cowboy_protocol) of listener MyApp.Endpoint.HTTP terminated
** (exit) exited in: GenServer.call(ExAws.Config.AuthCache, {:refresh_config, %ExAws.S3{config: %{access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role], host: %{"ap-northeast-1" =>
"s3-ap-northeast-1.amazonaws.com", "ap-southeast-1" => "s3-ap-southeast-1.amazonaws.com", "ap-southeast-2" => "s3-ap-southeast-2.amazonaws.com", "eu-central-1" => "s3-eu-central-1.amazonaws.c
om", "eu-west-1" => "s3-eu-west-1.amazonaws.com", "sa-east-1" => "s3-sa-east-1.amazonaws.com", "us-east-1" => "s3.amazonaws.com", "us-west-1" => "s3-us-west-1.amazonaws.com", "us-west-2" => "
s3-us-west-2.amazonaws.com"}, http_client: ExAws.Request.HTTPoison, json_codec: Poison, region: "us-east-1", scheme: "https://", secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :insta
nce_role]}, service: :s3}}, 5000)
** (EXIT) an exception was raised:
** (Poison.SyntaxError) Unexpected token: <
(poison) lib/poison/parser.ex:56: Poison.Parser.parse!/2
(poison) lib/poison.ex:83: Poison.decode!/2
(ex_aws) lib/ex_aws/instance_meta.ex:16: ExAws.InstanceMeta.security_credentials/1
(ex_aws) lib/ex_aws/config/auth_cache.ex:37: ExAws.Config.AuthCache.refresh_config/2
(ex_aws) lib/ex_aws/config/auth_cache.ex:27: ExAws.Config.AuthCache.handle_call/3
(stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:647: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Thanks.
Your stack trace says that Poison, a dep that ExAws uses, failed to decode a json. If you check the module that made that call (lib/ex_aws/instance_meta.ex, you can read it here), you'll find that it communicates with Amazon to check your credentials.
The most probable thing is that your configuration is incorrect and Amazon is sending you an error message formatted as an XML or HTML (both begin with <).
ExAws config depends on env vars, so that's also probably why it works on dev, but not on production.

Chef provisioning ssh times out when used with chef zero

I am using Chef zero on my windows machine to ssh into a red hat linux machine and execute a command that's inside of a recipe. When I run the code below, it tries to SSH for 120 secs and times out. I'm not sure why this is happening. Any idea why this is happening?
require 'chef/provisioning'
require 'chef/provisioning/ssh_driver'
with_driver 'ssh'
machine "ssh" do
attribute "short_dns", new_resource.short_dns
attribute "long_dns", load_balancer_name
recipe "mycookbook::add_short_dns"
machine_options :transport_options => {
'is_windows' => false,
'ip_address' => '10.16.99.124',
'username' => 'myusername',
'ssh_options' => {
'password' => 'mypassword'
}
}
converge true
end
here is the error
- been waiting 110/120 -- sleeping 10 seconds for ssh (10.16.99.124 on ssh:C:/Users/user/.chef/provisioning/ssh) to be connectable ...[2015-06-23T14:54:33-05:00] INFO: Executing sudo pwd on myusername#10.16.99.124
================================================================================
Error executing action `converge` on resource 'machine[ssh]'
================================================================================
RuntimeError
------------
Machine ssh (10.16.99.124 on ssh:C:/Users/user/.chef/provisioning/ssh) did not become ready within 120 seconds
I'm still fighting with Chef Provisioning myself, so this may not be as helpful as I would like. One thing is that each of these is a key/value pair, so want to declare your variables differently (see below):
require 'chef/provisioning/ssh_driver'
with_driver 'ssh'
with_machine_options :transport_options => {
:username => 'centos',
:ssh_options => {
:password => 'password'
}
}
Amir,
Does the :C/Users/user/.chef/provisioning/ssh directory exist on your workstation? If not try creating it and making sure permissions are correct then try
Try to use the snippet below, notice extra options that will help you to debug an issue.
1) DEBUG level will allow to see SSH communication.
2) If you don't overwrite prefix, it will use SUDO by default
3) Sometimes when you recreate remote server, your "known_hosts" file remembers it and the next time you try to SSH into server after recreation, you receive thie message "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED". In fact SSH session hangs, but you don't see that on the client side. So better ignore it.
:transport_options => {
:is_windows => false,
:username => 'YOURUSER',
:ssh_options => {
:password => 'YOURPASSWRD',
:verbose => Logger::DEBUG,
:user_known_hosts_file => '/dev/null'
},
:options => {
:prefix => ''
}
},

Selenium does not detect page load (Ruby)

I am currently using
- firefox 13
- selenium-server-standalone-2.23.1.jar
- selenium-client (1.2.18)
- rspec 1.2.8
Selenium stops here even if page has fully loaded
08:49:43.888 INFO - Command request: waitForPageToLoad[300000, ] on session 2718493e6d4640eea76d6cb3ab1a6fc3
require 'rubygems'
require "selenium/client"
require "selenium/rspec/spec_helper"
describe "Google Search" do
attr_reader :selenium_driver
alias :page :selenium_driver
before(:all) do
#selenium_driver = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*firefox",
:url => "http://www.google.com",
:timeout_in_second => 10
end
before(:each) do
selenium_driver.start_new_browser_session
end
# The system capture need to happen BEFORE closing the Selenium session
append_after(:each) do
#selenium_driver.close_current_browser_session
end
it "can find Selenium" do
page.open "/"
page.title.should eql("Google")
page.type "q", "Selenium seleniumhq"
page.click "btnG", :wait_for => :page
page.value("q").should eql("Selenium seleniumhq")
page.text?("seleniumhq.org").should be_true
page.title.should eql("Selenium seleniumhq - Google Search")
page.text?("seleniumhq.org").should be_true
page.element?("link=Cached").should be_true
end
end
I wonder if the google page is using AJAX which is confusing the page load event.
When I went to http://google.com I noticed that submitting the search only added #q=selenium to the url.
This could likely be confusing selenium. Maybe instead of wait for pageload you can wait for page element
Some search element xpath (for example) /html/body/div[1]/div[3]/div[3]/div[6]/div[2]/div[3]/div/div[2]/div[2]/div/div/ol/div[2]/li[1]/div (ugly I know)