Feature Testing with Filepicker.io and Capybara - ruby

I am currently working on feature testing a Filepicker.io upload form and cannot get a the file upload to work. I am using the Poltergeist driver for Capybara and from the debugging I have been able to do, the Filepicker iframe is never loading. I have confirmed this by using the remote debugging of Poltergeist.
Here is a sample of the test code:
within_fieldset 'Photos' do
click_button 'Find Photo'
end
within_frame 'filepicker_dialog' do
attach_file '#fileUploadInput', Rails.root.join('spec', 'files', 'photo.jpg')
end
And the error being produced:
Failure/Error: within_frame '#filepicker_dialog' do
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"push_frame","args":["#filepicker_dialog"]}. It's possible that this happened because something took a very long time (for example a page load was slow). If so, setting the Poltergeist :timeout option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Poltergeist - please report it to the issue tracker.
Attempting to manually trigger Filepicker through the javascript console also yields no results.

have you tried to increase the timeout ?
Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {:timeout => 50})
end
as the default timeout is 30

The Capybara API for within_frame is a bit weird. It expects a frame name, not a CSS selector for the frame. So Poltergeist is looking for a frame named "#filepicker_dialog" - I suspect this is your problem.

Related

The test hangs for a decent amount of time and crashes with an error Net::ReadTimeout (Net::ReadTimeout)

When running tests, a Net::ReadTimeout (Net::ReadTimeout) error occurs.
The error occurs only in situations of switching to a new window.
At the same time, the problem is not even in the exception itself, but in the consequences. The fact is that when a problem occurs, the test does not fall, and a decent time (up to 10 minutes) waits before is crashed.
At the same time, there are no exceptions in the server console and browser console.
I use Capybara (selenium), chromediver 102.0.5005.61 and chrome .
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 80
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference('profile.content_settings.exceptions.automatic_downloads', {
'*': {'setting': 1}
})
Capybara::Selenium::Driver.new(app, :browser => :chrome, http_client: client, options: options)
It is code to switch to new window
window_last = page.driver.browser.window_handles.last
log window_last
page.driver.browser.switch_to.window(window_last)
There is a hook that should work, it seems to work, but for some reason it does not interrupt the test
After do |scenario|
if scenario.failed?
filename = scenario.location.file.split('/').pop.split('.').shift
path = "#{ENV['ROOTDIR']}/06_Reports/error/#{filename}#{scenario.id}.png"
p path
page.save_screenshot path
end
page.driver.browser.close
page.driver.quit()
end
Video record
It seems to me that it started after updating chrome and chromedriver - but I'm not sure. It is not possible to repeat it manually, it is possible to run the autotest, and far from the first attempt.
Any idea what it is, where to dig? How to prevent such freezes? They greatly increase the run time.
Thank you!
If it started after updating chrome/chromedriver then it's likely a bug in chromedriver. Try rolling back to a previous version of chrome and seeing if the issue goes away. One thing to note is that by switching windows directly on the driver you are preventing Capybara from knowing about the window switch which can lead to issues. You should instead use the Capybara::Session#switch_to_window or within_window methods to do window switching.

How do I resolve a readtimeout when it is the happy path?

Without a modal or alert popup. Pressing a button takes me to a page in such a way that selenium can no longer see the controls.
I have tired do reacquire the page without success.
visit([purchase page])
login
sleep(10)
find(:xpath, './/div[#class="tab-pane active"]/div/div/button[#class="btn btn-primary"]').click
Net::ReadTimeout (Net::ReadTimeout)
What I am fairly certain of is that is not not finding my element because I didn't generate a
ElementNotFound
My question is, what are the tools I want to try to get selenium to see the page I wish to manipulate?
One way I would debug this is by putting save_and_open_page before and after xpath. My guess is that it can't find the xpath to click on and its timing out.
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
save_and_open_page
find(:xpath, './/div[#class="blah active"]/div/div/button[#class="btn btn-primary"]').click
save_and_open_page
If this is not the case you can try and set the timeout to 90 seconds to see if it helps.
# https://github.com/teamcapybara/capybara/issues/1305
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 90 # instead of the default 60
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile, http_client: client)
end
Based off your Firefox error
visit https://ftp.mozilla.org/pub/utilities/profilemanager/1.0/.
download profilemanager.mac.dmg
open up profile manager
select default or create a new profile manager
click on start firefox
Error should be fixed now

Why capybara codes don't work with selenium webdriver?

I am new to Capybara. I have a question about why my Capybara doesn't work when I use it together with Selenium Webdriver.
This is my sample code:
Given(/^I am on the Youtube homepage$/) do
# visit 'http://www.youtube.com'
driver = Selenium::WebDriver.for :firefox
driver.navigate.to('http://www.youtube.com')
end
When(/^I search for "([^"]*)"$/) do |search_term|
fill_in 'search_query', :with => search_term
click_on 'search-btn'
end
Then(/^videos of large rodents are returned$/) do
expect(page).to have_content 'Making Friends with a Capybara'
end
When I run it, it just open Firefox and go to Youtube homepage. But it gets error:
Capybara::ElementNotFound: Unable to find field "search_query".
Everything works with visit 'http://www.youtube.com' command.
You're creating a driver, telling it to navigate to a page and then it's going out of scope so it's getting deleted. the visit line works because it's using the current capybara driver which stays around between test steps. Rather than creating a driver manually you should be registering a driver with Capybara and then specifying which driver to use for the specific test. See drivers
Since capybara sets up a selenium driver by default for use with firefox you can just do
Capybara.default_driver = :selenium
somewhere before running your tests to make all your tests run using selenium with firefox, or since capybara registers selenium as the default javascript driver you can tag any scenarios you want to run in firefox with #javascript as shown here
#javascript
Scenario: do something something
Given ...

Using Capybara and Selenium test suite fail switching from Firefox to Chrome

Using capybara (2.4.4) to test a non Rails application. I have write some tests, I run the tests using selenium with default firefox web browser and all tests are green.
Today I have tried to run same tests against chrome with this configuration:
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.javascript_driver = :selenium
Capybara.default_driver= :selenium
Capybara.app_host = ENV['WEB_SERVER_URL']
When I start the tests they fail becouse Chrome it seems too quick, infact with Firefox to complete the form it took several seconds, instead with Chrome is very very quick but then the tests fails with random errors:
"email" field not found (??)
current_url is not the expected url (?? in the browser I see the correct url!! )
ect ect..
Errors in my opinion have no sense and is very strange because with Firefox all tests are green.
Have you ever noticed this problem?
Chromedriver with Chrome 44 returns from actions much faster than before (incorrectly apparently) so visit is basically fully asynchronous. There have been numerous issues filed against Chromedriver for this such as https://code.google.com/p/chromedriver/issues/detail?id=1158&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
What this means for test stability is potentially needing to specify a longer wait on finds for the first element you're looking for after a visit, and checking for content that should be on the page before checking the current url (because content checks will use capybaras waiting behavior while capybara doesn't provide a waiting url matcher currently). You could also revert to Chrome 43 which will probably fix your issues
In accordance with the link provided by Tom Walpole I have switch from Chrome 44 to Chromium 43. I prefer use Chromium becouse I use chrome during my working day and I want to always have the latest version.
In my Ubuntu 14.04:
$sudo apt-get install chromium-browser
Then:
#spec/spec_helper.rb
require 'selenium/webdriver'
if ENV["USE_CHROME_BROWSER"]
Capybara.register_driver :selenium do |app|
Selenium::WebDriver::Chrome.path = ENV["CHROME_PATH"] if ENV["CHROME_PATH"]
Capybara::Selenium::Driver.new app, browser: :chrome
end
end
Capybara.default_driver = Capybara.javascript_driver = :selenium
Capybara.app_host = ENV['WEB_SERVER_URL']
With this configuration I can easily switch from Firefox (default) to Chromium.
I use dotenv gem to manage the configurations:
#./.env
...
USE_CHROME_BROWSER = true
CHROME_PATH = "/usr/bin/chromium-browser"
...
Based on what you have provided, I cannot tell if Chrome actually does load faster than Firefox. However, the following may be of some help. Wherever you define your Capybara conditions, I suggest replacing them with the following:
Capybara.configure do |config|
config.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
config.default_wait_time = 5 # default is 2 seconds
end
config.javascript_driver = :selenium
config.default_driver= :selenium
config.app_host = ENV['WEB_SERVER_URL']
end
Not only can you change the default wait time for Capybara to search for an element, but your code will be a little DRYer!
You may want to test other JavaScript drivers, like Capybara-Webkit. If this works for Chrome, I would suggest editing the config above, so capybara-webkit is set only when using a Chrome browser.

Selenium can't find fields with type number

I'm having a problem getting Cucumber to find fields with the HTML5 type="number". I'm not a big fan of the way they look in the browser, but I have a few fields that need the number keyboard on mobile, and this seems to be the easiest way to get it. I'm using SimpleForm to build forms and when I set :as => :text everything works, but if I set :as => :number, the fields don't get filled out. I don't get any error, the field just doesn't get filled.
To be specific, when I have a step like this:
And I fill in "application_form_age" with "52"
then this tag won't get filled in:
<input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">​
but this one works:
<input class=​"string required" id=​"application_form_age" name=​"application_form[age]​" size=​"50" type=​"text">​
Also, it only happens in #javascript scenarios. In situations where #javascript isn't necessary and the scenario doesn't launch a browser, that works fine too.
Versions of things:
capybara (2.2.1)
cucumber (1.3.14)
selenium-webdriver (2.41.0)
simple_form (2.1.1)
webrat (0.7.3)
Firefox 29.0
I'm stumped. I tried yanking out a bunch of my application JS and CSS to see if something I'm doing is breaking it, but no luck with that. I'm just patching it out by forcing those fields not to have HTML5 type number in my test environment, but I don't want to live like that. Is anyone else seeing this? I haven't been able to find any references to it, which makes it seem like it's something I'm doing. But I haven't been able to figure it out.
Ok, I have found firefox has an option to disable number input field support: 'dom.forms.number'.
So if you add the following lines in your env.rb, number input gets disabled and tests work again.
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile["dom.forms.number"] = false
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
First off, I think you have some confusion regarding those frameworks. Cucumber is a BDD framework, which doesn't automate browsers in any way, so this question has nothing to do with it (This is why I removed it from your question title).
Looks like you are using Capybara, which is an ATDD framework. You might probably consider showing us the Capybara code you use in order diagnose your problem.
Under the hood, I assume you use Selenium WebDriver, I can confirm that Selenium works fine with <input type="number"> (Tested with Firefox 28, which is the one selenium-webdriver (2.41.0) supports to).
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
DEMO_PAGE = <<-eos
data:text/html,
<input class=​"numeric integer required" id=​"application_form_age" min=​"0" name=​"application_form[age]​" size=​"50" step=​"1" type=​"number">
eos
driver.get(DEMO_PAGE)
driver.find_element(:tag_name, 'input').send_keys('25')
So you might want to create a similar demo using Capybara to test this functionality.
If the demo works, then we need take a closer look at your application.
Othwewise, please raise a ticket for Capybara developers.

Resources