I want to upload a file from remote url in ruby using selenium
My tools:-
watir-webdriver
selenium-webdriver
Upload a file:-
browser.file_field(:id, 'file').set("https://www.google.co.in/logos/doodles/2015/holi-festival-2015-5124794139803648-hp.gif")
Error:-
Errno::ENOENT: No such file or directory - https://www.google.co.in/logos/doodles/2015/holi-festival-2015-5124794139803648-hp.gif
The value of an upload input field should be an absolute path to the file on your local machine, not a URL. Download the image first.
Related
I'm reading a lot of zip file with rubyzip.
However this error message is always showing in only specific file even it is zip file.
/app/vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/lib/zip/central_directory.rb:143:in `get_e_o_c_d': Zip end of central directory signature not found (Zip::Error)
I guess this error occures in rubyzip.
How can I manage this error?
Here is my code.
url = 'http://example.zip'
zipfilename = open(url)
Zip::File.open(zipfilename, :allow_redirections => :all) do |zip_file|
entry = zip_file.glob("*ixbrl.htm").first
stream = entry.get_input_stream.read
puts stream
end
Thank you!
I faced this error when I try to extract data from a uploaded .xlsx file in my application. On my context, the .xlsx file was corrupted, so my solution was save the content (I usually handle the buffer file after the upload) as a csv file (in my application I dont need to worry about the file extension), fixing the content by force it to encode as utf-8, and extract it's data after it. here is a example of the code, I'm using roo-xls gem to handle .xls files and roo gem to handle .csv and .xlsx files.
I ran into the same error. Also only reproducible on Heroku. The error was fixed after I added an unzip buildpack (second, after Ruby).
https://github.com/davidlibrera/heroku-buildpack-unzip
If you're using a google docs xlsx file try checking if the access of the sheet link is public.
I have writen a Ruby script to lookup for documents with a given date and upload them to Google Drive by using the google-drive-ruby gem. I have a folder inside of the gdrive root path where I want to place the files, and I access it using collection_by_title and then uploading the file by using the .add method.
The problem is that the files are being uploaded each one two times, one to the folder I want and another one to the root path of my GDrive. Any thoughts?
This is the method where the file gets uploaded:
def upload_document(file, folder_code)
folder = #session.collection_by_title("#{folder_code}")
path = "#{#basedir}/#{folder_code}/#{file}"
folder.add(#session.upload_from_file(path, file, convert: false))
end
EDIT: Methods and variables translated to english.
Each time the method upload_document is triggered, one copy of the file gets uploaded to the folder and another copy gets uploaded to the root path of gdrive.
Example: Method upload_document gets called providing the file (454327.pdf) and the code of the folder where it has to be uploaded in gdrive ("1"). I build the folder object by using collection_by_title, I build the path where the file is located in my local network, and finally the file gets uploaded using upload_from_file. At this point, two copies of the file had been uploaded, one to the root path of gdrive (which I don't want) and another one to the right folder in gdrive.
I received an answer from the gem creator explaining what is happening and my script is finally working as I expected.
https://github.com/gimite/google-drive-ruby/issues/260
The thing is that the file is firstly uploaded to the root by default and then .add just moves the file to the selected collection, so the file needs to be removed from root after the move operation is completed.
#session.root_collection.remove(file)
I have a cucumber test that uploads a directory by entering the directory path into the file field. It works perfectly fine when I run the test on my machine but I'm getting the following error when I try to run it against my selenium grid setup:
you may only upload files: "/cucumber_tests/temp/uploads/Cuke1477494492767281" (Selenium::WebDriver::Error::WebDriverError)
(eval):1:in 'process_watir_call'
Full backtrace:
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'instance_eval'
/.rvm/gems/ruby-2.2.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/remote/bridge.rb:432:in 'send_keys_to_element'
/.rvm/gems/ruby-2.2.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/common/element.rb:146:in 'send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:319:in 'block in send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:621:in 'element_call'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:319:in 'send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/file_field.rb:24:in 'value='
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/file_field.rb:13:in 'set'
(eval):1:in 'process_watir_call'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'instance_eval'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'process_watir_call'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:846:in 'file_field_value_set'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/accessors.rb:1021:in 'block in file_field'
My code pretty much looks like this:
#browser.file_field(id: "assets").send_keys "/cucumber_tests/temp/uploads/Cuke1477494492767281"
Again, I'd like to emphasize that this works perfectly fine on my machine but not on the remote node. Also, single file uploads are fine for me on both my machine and on the grid. I'm wondering if any of you have had luck uploading directories on remote nodes or know if it's even possible (even if I have to install more gems). Thanks in advance!
Try passing in the absolute path to the file:
File.expand_path("/cucumber_tests/temp/uploads/Cuke1477494492767281")
Unless you are trying to upload something from your local computer to a remote computer via Watir. That you can't do.
No, Selenium & Watir are not designed to upload directories. You could loop through files, but they wouldn't be in a subdirectory.
Dir["/path/to/files/*"].each do |file|
#browser.file_field(id: "assets").set File.expand_path(file)
#browser.form.button.click
end
i am able to zip all required files(using ruby gems of AWS SDK) & upload them to the S3 bucket. when i tried to download the zip files from S3 to local server & unzip them , i am geeting following error...
[2013-05-06T07:19:37+00:00] FATAL: TypeError: aws_unzip[db_unzip] (aws::unzip line 14) had an error: TypeError: can't dup NilClass
Even when i try to unzip manually, i can see "zip files is corrupted"...But the zip file which is present in S3 location is not corrupted(i tested to extract them manually by downloading them, it extracted well)....
Can any one help where i am doing mistake in reading zip files from bucket to local server?????
When downloading it is getting corrupted...
My code is
File.open(dd, 'w') {|f| f.write(obj.read.force_encoding('utf-8'))}
Try 'wb' mode - zip is a binary file. Also that force_encoding is very suspicious.
This question is related to Rails - Where I have to store data file (.dat) in my rails project - GeoIp City database . I have a rails 3.2 app. I am trying to run:
#geoip = GeoIP.new('GeoLiteCity.dat')
In one of my app's controllers. I unzipped the 'GeoLiteCity.dat' file into the /public folder. I am getting the error "No such file or directory - GeoLiteCity.dat".
I've experimented with putting it in the images assets pipeline folder and some random other places. I continue to get the same error. Not sure how to access this file. Any ideas on what I'm doing wrong or how to access it best with the assets pipeline?
Try referencing it via the full path:
#geoip = GeoIP.new("#{Rails.root}/public/GeoLiteCity.dat")
On a side note, it's probably not a big deal, but I wouldn't put the file in your public directory.