File uploads using the selenium-client gem - ruby

I am using the selenium-client gem with Webrat and Cucumber to test a rails project. I have Cucumber set up pretty much as described here: https://github.com/cucumber/cucumber/wiki/Setting-up-Selenium
My problem is that Selenium is prevented from performing file uploads. Ideally I'd like to be able to replicate webrat's 'attach_file' method. I tried dodging the issue by using selenium-client's 'type' method to type the path to the required file, but this seems to fail.
Does anyone have a sugestion for a workaround using selenium-client (i.e. not the regular Selenium gem)?

The normal selenium can't do this because browser security prevents javascript from writing to input=file elements. This is a security feature so that your password file doesnt get uploaded to hackers if you go to a site thats been hacked.
http://jira.openqa.org/browse/SEL-63 has the details

I finally figured this out.
You need to be using firefox with the chrome backend, and you need to specifiy an absolute filepath.
I ended up creating a helper module to specify the filepath, and a "fixtures" folder containing test content. Here is a gist of the solution I came up with: http://gist.github.com/214185
Therefore it is totally possible to replicate Webrat's attach_file method!

Related

Moodle with Ruby On Rails

Currently, I am working on a rails application which requires the user to be registered automatically in the moodle. I searched for it and found these gems,
moodle-api: https://github.com/getsmarter/moodle-api
moodle_rb: https://github.com/jobready/moodle-rb/
moodle: https://github.com/robertboloc/moodle
But, nothing seems to work for me. I even searched on youtube but found nothing with the rails.
However, using the moodle_rb gem I was able to create an object which returned me the sites info using the sites_info function. Other than that I am unable to use any of the web services of the moodle. I have created an external service and added some functions like auth_email_get_signup_settings and auth_email_signup_user which accepts none parameters.
May anyone guides me through this? or even a minor help would also be great.
I am using a token to create the object.
Thanks in advance.
Can you show us how you tried to configure your gems? For example, according to the docs the moddle-api gem requires a configuration like:
Moodle::Api.configure do|c|
c.host = 'http://my_moodle_instance.com'
c.token = 'mytoken'
end
If you did configure the gem like the above, can you show some of the code that you tried to call once the gem was installed and configured?

Changing the base URL for Capybara Acceptance Tests

I am developing a sinatra based web application and I extensively use tests to make sure that everything is working before deployment. As testing frameworks I use minitest::specs and capybara with webkit.
My problem is that after deployment my application runs with a base url like this:
http://cool.server.net/to-the-application/
But during tests capybara assumes a clean base-url with a path to / not to to-the-application/. This means I can't test to find bugs which relate to forgetting to set the base-url within links and actions.
For dry testing I followed Changing the base URL for Rails 3 development and modified my config.ru, but I haven't found any way to get capybara to use a different base.
Any ideas how to solve this?
If using the rack_test driver the hostname is completely ignored so changing it isn't going to do anything. If using a different driver you can specify
Capybara.app_host = "http://cool.server.net"
Note that cool.server.net would generally need to resolve to 127.0.0.1 since thats where Capybara binds the app being tested.
Update: After thinking about this I'm not sure that is what you wanted. If what you want is for Capybara to mount your app under /to-the-application then you're going to have to create your own app object which you assign to Capybara.app - see https://github.com/teamcapybara/capybara/blob/2.13_stable/lib/capybara/rails.rb#L4 for how Capybara currently mounts the app.

Use of link-Checker (ruby)

Has anyone used the link-checker gem?
I don't want to use it in a project I want to write a small script to test links on a web app.
I cant seem to figure out how to use it. Trying to require it doesn't work but saying gem 'link-checker' does result in true.
I'm getting nowhere trying to play with it in IRB. Can someone let me know what I am missing?
Did you read the documentation? Link-checker is a small script designed to check links already.
That page shows examples of it running from the command-line, not from inside IRB or Ruby code. In other words, it is a command-line app, not code you require:
Usage:
Just give it the target that you want it to scan. For example, if you have an Octopress site then your output HTML is in the public directory, so call it with:
check-links 'public'
Or if you want to check the links on a live site, then give it a URL instead:
check-links 'http://www.ryanalynporter.com'
If you don’t pass any target, then the default is to scan the “./” directory. If you have a Jekyll site that you deploy to GitHub Pages, then you can check the links with just:
check-links

What methods exist to auto-generate ruby client stubs from WSDL files?

I'm using Ruby and the Savon gem to interact with SOAP/WS and would like to auto-generate the client request methods from the WSDL in Ruby.
Before I do this, I'd like to know if there's any other Ruby/SOAP library that does this?
Edit: Please note, I already know this isn't available in Savon out the box, in fact my intention is to add in the feature, I'm in the process checking if this exists somewhere else written in Ruby.
Since it's only few days since you asked this question, and I've run into same problem I've decided to create small script to do that.
Download - save as objects.rb for example and run with _bunde exec objects.rb path_to.wsdl_
https://gist.github.com/4622792
Let me know if it works ^^
Take a look at Savon's spec, it has pretty rich testing environment
I think ads_common by Google is relevant to you.
google-api-ads-ruby/ads_common at master · googleads/google-api-ads-ruby
rake generate can create the client libraries automatically from WSDL.
It is specialized for Google Ads, but this notion would be helpful to create a versatile client library automatically from WSDL in Ruby.

PDFkit rails3.1 and development env

My Rails 3.1 app is using PDFkit to render specific pages, and I'm running into (what seems like) a common problem with where trying to generate the pdf is causing the process to hang.
I found this solution here on stackoverflow: rails 3 and PDFkit. Where I add a config.threadsafe! entry in my development.rb file and this works BUT it requires that for every change anywhere in the app I have to stop and restart my server to see my changes. NOT acceptable from a workflow - I'm currently setting up the styling for the PDF pages, and it's painfully slow process having to do this.
I also found the same issue reported here: https://github.com/jdpace/PDFKit/issues/110, and the issue points to this workaround: http://jguimont.com/post/2627758108/pdfkit-and-its-middleware-on-heroku.
ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}
This removes the need to restart the change, BUT now when I load the pdf it's without the styles rendered from the asset pipeline because it's taking the assets from the public directory. I think I could work with this solution if I could know how to create the stylesheets for the pdf templates in the public folder. IS anyone developing with PDFKit and Rails3.1 where this is all working in sync?
Any help would be greatly appreciated!
Thanks!
Tony
Here is the setup I am using:
I run a second instance of rails server with rails server -p 3001 -e test which will handle my assets for the PDF. The server will print the assets requests as they come in, so I can check that everything works as expected.
I use the following asset_host in my config/environments/development file:
config.action_controller.asset_host = ->(source, request = nil){
"http://localhost:3001" if request && request.env['REQUEST_PATH'].include?(".pdf")
}
If you are using Pow, you can use multiple workers. Add this to your ~/.powconfig
export POW_WORKERS=3
(taken from Pow manual)
There's a problem with pdfkit in Rails 3.1. See my answer to this related question:
pdfkit does not style pdfs

Resources