What are the differences between these two ways of setting Selenium driver? - ruby-on-rails

In a Ruby on Rails project, I found this method whose goal is to retrieve Selenium driver depending the environment. (development, test or production)
def driver
#driver ||= begin
if Rails.env.production?
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub'
else
driver = Selenium::WebDriver.for :firefox
end
driver.manage.timeouts.implicit_wait = 1
driver
end
end
Of course, I read the official documentation but it still not appears very clear:
http://code.google.com/p/selenium/wiki/RemoteWebDriver - http://code.google.com/p/selenium/wiki/FirefoxDriver
What are the differences between these two ways (remote and firefox) ?
And especially, for the removed way, why set the pointed host to localhost... indeed, if localhost is chosen, why not choose the firefox driver instead ?

:remote means that you're going to use a remote server running Selenium Server at the :url. In this case selenium server's running on localhost. Because no browser is identified, it will use whatever default browser the server is set to.
:firefox means it's going to try to use firefox on the same box the script is running on.
You can see these two examples on the intro page to rubybindings.
http://code.google.com/p/selenium/wiki/RubyBindings
For more general documentation stuff this might be a good place...
http://selenium.googlecode.com/svn/trunk/docs/api/rb/index.html
As to why someone would this is? Maybe in a prod environment someone else aside from the guy who developed this code controls the selenium server depending on the platform it's on (chrome, ie, ff, etc) (like some prod guy who can't access code?). I'm just guessing here.

Related

Running Capybara tests against Internet Explorer via Browserstack

I have a Rails app with a suite of Cucumber tests that run via Capybara on a headless Chrome browser. I'd like to find a way of running these tests (or at least a subset of them) on IE11, and have turned to Browserstack as it seems they offer the means to do this.
I've successfully configured Browserstack to tunnel into my machine and run my tests but they fail on the one browser I care about - IE11.
My suite is currently falling over at the login page. I'm able to do a screenshot and establish that the page is in fact rendered. I'm able to execute:
fill_in 'Email', with: 'mr.jones#example.com'
without error, although a screenshot then shows nothing to have been filled in. Executing
click_on 'Sign in'
yields:
'Selenium::WebDriver::Error::ElementNotInteractableError: Received a JavaScript error
attempting to click on the element using synthetic events. We are assuming this is
because the element isn't displayed, but it may be due to other problems with executing
JavaScript.'
I briefly experimented with send_keys to try and fill in the form, but to no avail. In short, it seems I can navigate to pages and find elements, but I can't interact with them.
Does anyone know of a way to achieve what I'm attempting here? I'm hoping there's e.g. some setting on the driver that will make it work.
I only need to be able to test a few key workflows against IE, so even if a radically different approach is needed in my testing, I won't need to rewrite the entire suite.
Here is my current Capybara configuration:
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browser'] = 'IE'
caps['browser_version'] = '11.0'
caps['os'] = 'Windows'
caps['os_version'] = '10'
caps['resolution'] = '1024x768'
caps['browserstack.local'] = 'true'
Capybara.register_driver :browserstack_ie do |app|
Capybara::Selenium::Driver.new(
app,
:browser => :remote,
:url => "http://#{ENV['BROWSERSTACK_USER']}:#{ENV['BROWSERSTACK_KEY']}#hub-cloud.browserstack.com/wd/hub",
:desired_capabilities => caps
)
end
Capybara.javascript_driver = :browserstack_ie
UPDATE:
I found some useful information here
It sounds like the issue may be that Selenium is clicking in the wrong place, and that it can be fixed by changing the zoom settings in IE. Not clear to me how I would do this on a browser running in Browserstack though.
I also discovered my Browserstack subscription doesn't support more than 100 minutes of automated testing time per month, which was a bit of a blow, so I can't immediately do anything further with this.
I think I may end up running my own IE instance on a Windows machine on my local network and hook my tests up to that instead. I will update this card if/when I discover anything useful.
Finally, I'd invite anyone who reads this to consider how many hours of their life they have wasted on supporting the many incarnations of IE. It is a blight upon the industry and Microsoft should be ashamed of it.

Is there a reason that Selenium tests would act differently on Ubuntu vs Mac OSX?

I am working on a project with a partner and we both are using different Operating Systems. All of our files, including the Gemfileare under version control. Previously, I had written tests in Rspec with Capybara and selenium-webdriver. These tests opened Firefox and performed simple actions, passed, and closed the browser.
A few unrelated changes to the layout concerning flash[:success] and now, with both of us updated to the HEAD, the tests pass on my machine, but fail on his.
His browser is not loading the modal box from the before block click_link "Edit" therefore when the test tries to fill in a form, the fields are still hidden and not accessible.
I attempted to wait for the box, thinking it may be filling in the fields too soon :
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { page.driver.browser.find_element(:css, "div#edit_news_container").displayed? == true }
Instead I get a timeout, and the tests still fail.
However, they work beautifully on my machine... what's going on here?
In light of the layout changes, it's likely you're having a browser issue rather than an operating system issue. Are the two of you using the same version of Firefox? If not, changing his version to yours may allow him to load the modal again.

Chrome browser doesn't like *.loc domain without http://?

For web development on localhost I'm using domains with .loc extension at the end of a domain name.
For example: if I work on a site roses.com, the local development domain would be roses.loc
(defined in hosts file and IIS as a host-header in binding)
My preferred browser (the main browser I use for development is Chrome) but unfortunately
it does not recognize a domain name with .loc extension as http://rose.loc - it throws me onto a google search page each time I would type in rose.loc (without http://) in the beginning..
Have you experienced this in a similar way ? Is there some solution to that ?
Because during intensive development testing with clearing browser cache and restarting the browser for various reasons, it's getting pretty annoying to be thrown at a google search page instead of the development page where I expect to notice some changes, each time I forget to type in http:// before the url (and Chrome is the one who hides it by default, anyway..)
Google Chrome is pretty "smart" with this. It uses a list of known-good TLDs and assumes everything else is just a search term that happens to end in a dot followed with some characters.
99% of the time that's perfectly fine. It's "only" us developers and a few people with strange network setups that have to suffer for the good of the majority ;-)
You can try using .local as your TLD, as that's a defined domain for referencing local domain names (at least it's used in some mDNS systems).
The issue has been entered as #30636 in the Chromium bug tracker. One workaround that often (but not always) seems to work is to append / to your hostname. So try roses.loc/.
I've created a search engine with a keyword of 'l' (my local TLD is .l). The URL for the search engine is http://%s.l. Then, I simply type "l mysite" in the address bar and it takes me to mysite.l.
Here is a workaround I came up with for this bug: http://code.google.com/p/chromium/issues/detail?id=30636#c38
I have Chromium installed on Linux Mint, and have a few localhost websites here. (I use Firefox for all of my work, so I have just discovered something here with Chromium.) My local sites are called morse and a.z. I had to enter http://morse/ and a.z/ respectively to get these sites to load the first time. They produced quick links on the new tab's otherwise blank page.
After closing Chromium, I reopened it and I could enter just morse/ and a.z to visit these sites. Since I've never seriously used this browser, I have not tailored any settings in it. (I did not use the quick link icons, but instead typed in the address bar.)
My findings confirm the localhost example.TLD/ entry does work when entered for the first time.
About Chromium: I am using Version 106.0.5249.119 (Official Build) for Linux Mint (64-bit).

How do I access remote machine that runs on Pow (rails web server)

I've recently installed Pow on my Mac. It's great.
It's convenient for my own dev machine. But I wonder if I can set it up to be shared by my colleagues. The problem is DNS resolution part.
For example, if I have a dev site on my machine like "http://myapp.dev". How do I let my colleague access to the site on my machine from his machine?
The hacky way to do this is to make them edit their DNS and insert a record in /etc/hosts that maps to your machine. An easier way to do this is Localghost which doesn't require editing files by hand.
I've been using https://showoff.io and it works a treat. Also allows others not on local network to view it as well (if that's something you need).

How can I get the pretty error messages when developing on localhost?

I'm developing a rails app and running the server in the development environment on my local host. I'd like to see the error page that I would see when the app is on the production server, and I go to myapp.com/should_show_error_page so that I can style it. Currently, when I go to a page that should display this kind of error, I get the full exception description and stack traces. Starting the server with RAILS_ENV=production isn't enough unless I go to the page from a different machine. I'd appreciate any help.
Update
Setting config.consider_all_requests_local = true in config/environments/development.rb doesn't do it either
another update
I'm using goalie to generate the error pages, so they're not static.
The easiest way to do this would be to access this through the hostname of your computer. For example, I would test it using http://ryanbigg.local:3000/. To get the hostname, type hostname in your prompt.
Just mirror your production server's configuration. Without knowing what that is, I could not comment further.
Edit public/500.html. Browse to http://localhost:3000/500.html to see what it looks like.

Resources