Reputation: 515
I am writing a script with Capybara and Ruby and I am trying to change the default_max_wait_time from 2 sec to 200 sec. I read through the documentation but it seems like it still doesn't work for me when I am uploading the file to the be site. Could you advise what I am doing wrong, please?
require 'kimurai'
require 'pry'
require 'capybara/config'
# $app_path = 'path_to_the_file'
class Uploader < Kimurai::Base
@name = "new_google_play_console_app"
@engine = :selenium_chrome
@start_urls = ["link_to_the_web_page"]
def parse(response, url:, data: {})
Capybara.configure do |config|
config.default_max_wait_time = 200
puts config.default_max_wait_time
end
browser.click_button('I’m sure, opt out', wait: 100)
browser.attach_file($app_path) do
browser.click_button('Browse files')
end
sleep 200
browser.click_on('Save')
The problem is the script doesn't wait for the file to be uploaded and tries to click 'Save'. And not only here - sometimes, when I click the button the website loads results. But my script doesn't wait for it and continue to execute. So, that's why I put ```sleep`` for now. But I want to avoid it
This table appears after upload process completion:
Thomas, here is a code and an error. After the upload is completed, I need to click ``Save``` button which is not active until you are done with uploading.
CODE
app_releases = browser.find_link(title: 'App releases')
app_releases.click
manage_btn = browser.all(:button, text: 'Manage')
manage_btn[0].click
sleep 1
create_release_btn = browser.all(:button, text: 'Create release')
create_release_btn[1].click
browser.click_button('Opt out', wait: 100)
browser.click_button('I’m sure, opt out', wait: 100)
browser.attach_file($app_path) do
browser.click_button('Browse files')
browser.assert_text('App download size', wait: 200)
end
# browser.assert_text('App download size', wait: 200) - tried to put it inside the upload process and outside. Didn't work.
# sleep 200
browser.click_on('Save')
ERROR:
WARN: Unresolved specs during Gem::Specification.reset:
selenium-webdriver (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
I, [2020-06-10 19:10:54 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Spider: started: new_google_play_console_app
D, [2020-06-10 19:10:56 +0300#37958] [M: 70296153575020] DEBUG -- new_google_play_console_app: BrowserBuilder (selenium_chrome): created browser instance
I, [2020-06-10 19:10:56 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: started get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppDashboardPlace:p=net.cityhive.store.martinbrothers&appid=4975449495408659761
2020-06-10 19:10:56 WARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: finished get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppDashboardPlace:p=net.cityhive.store.martinbrothers&appid=4975449495408659761
I, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Info: visits: requests: 1, responses: 1
D, [2020-06-10 19:11:00 +0300#37958] [M: 70296153575020] DEBUG -- new_google_play_console_app: Browser: driver.current_memory: 501740
I, [2020-06-10 19:11:37 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Browser: driver selenium_chrome has been destroyed
I, [2020-06-10 19:11:37 +0300#37958] [M: 70296153575020] INFO -- new_google_play_console_app: Spider: stopped: {:spider_name=>"new_google_play_console_app", :status=>:completed, :error=>nil, :environment=>"development", :start_time=>2020-06-10 19:10:54 +0300, :stop_time=>2020-06-10 19:11:37 +0300, :running_time=>"42s", :visits=>{:requests=>1, :responses=>1}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
MacBook-Air-Nikita:spiders nikita$ ruby new_google_play_console_app.rb Liquor\ Super\ Store liquorsuper
WARN: Unresolved specs during Gem::Specification.reset:
selenium-webdriver (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
I, [2020-06-11 13:37:28 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Spider: started: new_google_play_console_app
D, [2020-06-11 13:37:29 +0300#38739] [M: 70329536056940] DEBUG -- new_google_play_console_app: BrowserBuilder (selenium_chrome): created browser instance
I, [2020-06-11 13:37:29 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: started get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppListPlace
2020-06-11 13:37:29 WARN Selenium [DEPRECATION] :driver_path is deprecated. Use :service with an instance of Selenium::WebDriver::Service instead.
I, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: finished get request to: https://play.google.com/apps/publish/?account=5899250864637200353#AppListPlace
I, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Info: visits: requests: 1, responses: 1
D, [2020-06-11 13:37:36 +0300#38739] [M: 70329536056940] DEBUG -- new_google_play_console_app: Browser: driver.current_memory: 500852
I, [2020-06-11 13:38:10 +0300#38739] [M: 70329536056940] INFO -- new_google_play_console_app: Browser: driver selenium_chrome has been destroyed
F, [2020-06-11 13:38:10 +0300#38739] [M: 70329536056940] FATAL -- new_google_play_console_app: Spider: stopped: {:spider_name=>"new_google_play_console_app", :status=>:failed, :error=>"#<Capybara::ElementNotFound: Unable to find link or button \"Save\">", :environment=>"development", :start_time=>2020-06-11 13:37:28 +0300, :stop_time=>2020-06-11 13:38:10 +0300, :running_time=>"42s", :visits=>{:requests=>1, :responses=>1}, :items=>{:sent=>0, :processed=>0}, :events=>{:requests_errors=>{}, :drop_items_errors=>{}, :custom=>{}}}
Traceback (most recent call last):
13: from new_google_play_console_app.rb:196:in `<main>'
12: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:124:in `crawl!'
11: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:124:in `each'
10: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:128:in `block in crawl!'
9: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:204:in `request_to'
8: from /usr/local/lib/ruby/gems/2.5.0/gems/kimurai-1.4.0/lib/kimurai/base.rb:204:in `public_send'
7: from new_google_play_console_app.rb:187:in `parse'
6: from new_google_play_console_app.rb:55:in `appReleases'
5: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'
4: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/actions.rb:26:in `click_link_or_button'
3: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:52:in `find'
2: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:291:in `synced_resolve'
1: from /usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/base.rb:83:in `synchronize'
/usr/local/lib/ruby/gems/2.5.0/gems/capybara-3.32.2/lib/capybara/node/finders.rb:302:in `block in synced_resolve': Unable to find link or button "Save" (Capybara::ElementNotFound)
Upvotes: 0
Views: 1524
Reputation: 515
Solved with browser.has_button?('Save', wait: 200)
. There is a Save button that appears after the successful upload.
Upvotes: 2
Reputation: 49890
Capybara.default_max_wait_time
is the amount of time Capybara will wait for a matching element to appear on, or disappear from the page. In your case, that means in your script you need to determine what change on the page indicates the file has finished uploading and wait for that
browser.attach_file($app_path) do
browser.click_button('Browse files')
end
# Have this look for whatever indicates the file upload has completed
browser.assert_text('Your file has uploaded', wait: 200)
browser.click_on('Save')
Upvotes: 1