ies4linux with selenium and rspec - ruby

I use selenium, usually with firefox, to test my rails apps and it's all fine. I want to run my tests in IE6 as well. I'm in ubuntu, using the ruby selenium-client gem. For IE6 i use ies4linux, this is an executable which is at /home/max/.ies4linux/bin/ie6
I'm editing my selenium conf to try to get it to use the above, but can't get it working. Here's what i have at the moment:
SELENIUM_CONF = {
:client_options => {
:url => "http://awebsite.com",
:host => "localhost",
:port => 4444,
:browser => "*iexplore /home/max/.ies4linux/bin/ie6",
:javascript_framework => :jquery
}
}
Then when i make a browser in my scripts i call
Selenium::Client::Driver.new(SELENIUM_CONF[:client_options])
It's not happy with what i have in the :browser field at the moment - i get this error:
"Failed to start new browser session: Error while launching browser"
I also tried
:browser => "/home/max/.ies4linux/bin/ie6",
But got a "Browser not supported" error as it expects one from list, *iexplore in this case.
Can anyone tell me how i can get this working?
thanks, max

I don't think there's a way to do that. Selenium uses iehta, and some not-so-used parts of ie that could not be bundled in ie4linux, and even if there were, I wouldn't trust on a test that runs IE under linux.
Why not creating a VM using VirtualBox and pointing your tests to an RC server inside the VM?

Related

Headless operations don't work inside Sinatra route

I am using the headless and selenium-webdriver gems to launch a headless Firefox browser:
headless = Headless.new(
video: {
frame_rate: 12,
codec: 'libx264'
}
)
headless.start
driver = Selenium::WebDriver.for(:firefox)
With this code I can write the following:
driver.navigate.to("http://google.com")
Yet the following raises an error after I visit '/' in the browser:
get '/' do
driver.navigate.to("http://google.com")
erb :root
end
The error is as follows:
*** Errno::ECONNREFUSED Exception: Failed to open TCP connection to 127.0.0.1:7055 (Connection refused - connect(2) for "127.0.0.1" port 7055)
I'm pretty sure this is because the driver.navigate is not being called in the headless scope, therefore it can't connect to the Firefox instance.
I have also tried using the modular sinatra style, but the same error occurred.
workaround
What I ended up doing is separating the headless server in a separate script. This script has loop and gets input, printing the output of running the command in the headless scope. Then from the sinatra server, i use PTY.spawn to instantiate the server and pass around its stdin and stdout so I can use it in my Sinatra app. This way the headless script is only run once (therefore multiple headless servers aren't started) and I can connect to it from my Sinatra routes. I can't interact with the headless script's variables or methods directly - I need to just use i/o.
I am hoping for an answer which hows how to make the original code work, though (when the sinatra app's routes are called in headless scope)
One possible trick that can help:
this = self
get '/' do
this.driver.navigate.to("http://google.com")
erb :root
end
I ended up getting this working.
At first I thought that what fixed it was doing the headless environment initialization in the scope of a sinatra route, i.e.
get '/' { do_initialization_here }
The real fix may have been in the way I was calling Headless.new (I originally had a bunch of options tacked on and I removed all them).

Bypassing certificate error with Watir-WebDriver in Selenium Grid environment

I have setup a Grid Environment with 4 Windows ( IE8, IE9, IE10, IE11 ) VMs and an Ubuntu 12.04 VM with Chrome and Firefox.
Selenium Grid and Nodes are version 2.41.0
as for ruby , i am using rvm, and using ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
I am driving the tests from a CentOs VM. Now when i try to run IE8 Tests, i see the remote windows machine bring up IE8, but first get a message in browser:
"This is the initial start page for the WebDriver server."
and later i get another page with cert warning.
Certificate Error: Navigation Blocked
error:
The security certificate presented by this website was not issued by a trusted certificate authority.
Security certificate problems may indicate an attempt to fool you or intercept any data you send to the server
I tried to do the registry hack making all 4 security levels in the IE8 equal , by
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
and equalize values for 0x2500 position in all zones.
But does not seem to work.
Any ideas here what a working solution is for ruby / watir-webdriver
Here is the base class
#!/usr/bin/env ruby -W0
require "rubygems"
require "test/unit"
require 'rspec'
require 'watir-webdriver'
require 'headless'
require 'mysql2'
require_relative 'lib/basic_ops'
require_relative 'data/data'
require_relative 'main_class'
include GC
caps = Selenium::WebDriver::Remote::Capabilities.ie
caps.version = "8"
caps[:name] = "IE 8 on win7 , port 5560"
BROWSER = Watir::Browser.new(
:remote,
:url => "http://selenium-hub-vm:4444/wd/hub",
:desired_capabilities => caps)
URL = "https://target-vm/"
BROWSER.window.resize_to(950, 750)
BROWSER.window.move_to(0, 0)
main_class
so main_class.rb is where all the browser interactions are.
You can use javascript to get passed the Security Certificate issue. I've never coded in Ruby before, so the syntax may be a bit off.
Python code:
driver.get("javascript:document.getElementById('overridelink').click()")
Ruby attempts:
driver.execute_script("document.getElementById('overridelink').click()")
driver.get "javascript:document.getElementById('overridelink').click()"
driver.get("javascript:document.getElementById('overridelink').click()");
You may want this in an if statement too so as to check for the condition you need.
i.e. if "Certificate Error" in driver.find_element_by_xpath("//title").text
There are similar solutions on the following thread if none of my suggestions work.
Hope this is helpful or close to what you need.
What i did was to add the cert , that did not remove the cert error, so i used:
#browser.link(:id, "overridelink").click
right after
#browser.goto("https://<URL>/")

Unable to automate (AutoIT) in Ruby because of Watir error

I've tried a few times now to run a Watir browser and then use the AutoIt ruby library (au3) to access a right click context menu but it wasn't working, turns out the au3 library is disappearing for some reason (I'm a little new to Ruby but when I require it again after the browser opens it comes back false for some reason:
irb(main):001:0> require "au3"
=> true
irb(main):002:0> require "watir-webdriver"
=> true
irb(main):003:0> browser = Watir::Browser.new :chrome
Starting ChromeDriver (v2.3) on port 9515
[4868:5640:1025/104947:ERROR:textfield.h(176)] NOT IMPLEMENTED
=> #<Watir::Browser:0x449008c8 url="about:blank" title="about:blank">
<to "https://github.com/lmmx/watir-paper-scanner/blob/master/bookworm.rb"
[WARNING:..\..\..\..\flash\platform\pepper\pep_module.cpp(63)] SANDBOXED
=> "https://github.com/lmmx/watir-paper-scanner/blob/master/bookworm.rb"
irb(main):005:0> require "au3"
=> false
irb(main):006:0>
I'm guessing that whatever's SANDBOXED is crucial to running au3? The browser still works fine... Will try and update the watir-related things, but I only installed it a week or 2 so it shouldn't be out of date already - anyone help me fix it?
The reason it's returning false is because you have already used
require "au3"
on the top line of your code, so when you require it again it's already there.

Why am I unable to launch a URL via Ruby script?

I am a Selenium (Ruby) newbie.
I am trying to launch Google homepage as below:
#selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*firefox", "http://www.google.com", 10000);
#selenium.start
However, after the script runs, it launches Firefox with below URL:
http://localhost:4444/selenium-server/core/Blank.html?start=true
I am unable to figure out the reason.
i think you need the keys for your hash, eg
Selenium::Client::Driver.new(:host => 'localhost', :port => 4444, etc)

Open Firefox browser with Ruby automation script

How is it possible to open FireFox browser by Ruby(for automation script)?
I use
#browser = RSpecSeleniumHelper.connect_browser('/admin/', '*firefox')
but it doesn't work.
You can start any program in ruby with:
`firefox http://www.google.com`
or
system("firefox http://www.google.com")
You can use Watir, as it supports Firefox also:
http://wtr.rubyforge.org/platforms.html
You may have to check if the Selenium Remote Control is start or not, normally it is running at port 4444.
java -jar selenium-server-xxx.jar
then you can use
#browser = Selenium::Client::Driver.new(
:host => "localhost",
:port => 4444,
:browser => "*firefox", #*iexplore, *firefox3, *safari...
:url => "http://www.google.com/",
:timeout_in_second => 60)
#browser.start_new_browser_session
Hope this helps, you can find more demo by download Selenium RC
I encountered two issues while getting this running:
If you are running your Ruby app from MacOS, the command firefox may not be properly aliased by default and so may fail without errors printed to your Ruby console.
If you already have an instance of Firefox open, you will get a message saying "Close Firefox - A copy of Firefox is already open. Only one copy of Firefox can be open at a time."
This code fixes both problems:
system("open -a /Applications/Firefox.app/Contents/MacOS/firefox-bin http://www.google.com http://www.cpap.com")
open's -a option Opens with the specified application.
The file path list works for me. If it won't load for you, first drop it and try plain "firefox" and failing that try "/Applications/Firefox.app/Contents/MacOS/firefox"
The example above shows two URLs separated by a space. You can use just one URL or as many as you care to following this pattern.

Resources