Running Capybara tests against Internet Explorer via Browserstack - ruby-on-rails

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.

Related

Ruby Watir: Avoid the "Im not a robot" check

I'm using watir to load a page the following way:
Watir.default_timeout = Rails.cache.read(:wati_timeout) || 5
options = Selenium::WebDriver::Chrome::Options.new
options.headless!
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
browser = Watir::Browser.new :chrome, options: options
browser.goto(url)
This loads a captcha page with "Please wait... we are checking your browser. and contains a "I am human" checkbox.
I there a way to prevent the website from triggering the captcha?
The Captchas were invented in order to prevent bots and crawlers(like selenium). They are made to be done manually.
You might work around this by automating everything except the Captcha.
You might also want to pause the selenium program if it detects a captcha, so you can solve it and then continue manually.
"I there a way to prevent the website from triggering the captcha?"
You can make it more unlikely to appear by not using a VPN and allowing selenium to use and keep cookies(don't know if this is on by default).

js: true - how to keep the browser running

When I do js: true test (rspec+capybara+selenium) it runs the browser and all steps are visible. I wish to be able to stop in some point and look around the page. Is there a way to do that? For non js: true tests save_and_open_page from gem launchy works well but here it's useless.
Nothing is better than putting a sleep or a debugger breakpoint where you want to stop, then you can look around the page.
Also note that your browser will be loaded by capybara without extensions, so you cannot use firebug or other tools (but perhaps the native developer tools of firefox remain available I'm not sure)

Timeout error while using watir webdriver with Ruby

I am new to watir webdriver with ruby and I am trying out a few examples. I am getting a timeout error "Net::ReadTimeout: Net::ReadTimeout" for the following code -
b = Watir::Browser.new
b.goto "http://www.quora.com"
b.text_field(:name => 'email').set 'someone#gmail.com'
b.text_field(:name => 'password').set 'somepassword'
b.button(:class => 'submit_button').click
When I run the above code in console, firefox gets launched and quora main page comes up. But after that it doesn't do anything until it times out. I inspected the elements for username and password and they are right.
I ran the same code for gmail.com with the corresponding fields and it runs just fine.
Can someone please help?
Ameya
This is a known issue with quora.com.
Currently I'm not aware of any solutions, one possibility is to disable JavaScript when you login, but in this case you can't do much else after login. Maybe you can create a ticket in Selenium issue tracker.
See similar questions asked before.
Selenium code doesn't terminate
Why am I not able to login to Quora using an automation package like Selenium or Watir?
How to add JS on a page when it has been turned off initially by Selenium?
Is Selenium slow, or is my code wrong?

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.

What are the differences between these two ways of setting Selenium driver?

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.

Resources