I recently upgraded cucumber to version 0.8.5, but I'm getting some unexpected errors with Authlogic. As a precursor to many of my user interface tests I have a default 'Given I am logged in' method that logs a user in through the standard login interface and asserts that they were redirected to the home page. Prior to upgrading cucumber I had no issue with this method, but when I run my tests now I get a NoMethodError on my the current_user helper provided by Authlogic. The user seems to log in fine (as there is no issue asserting that they are on the homepage after login), but as soon as 'current_user' method is called on the homepage it returns a false symbol. The current_user helper is simple
enough. All it does is validate that the current session matches up with a user, and if it doesn't then it returns false.
def current_user
#current_user ||= (session[:user] && User.find(session[:user])) || :false
end
This makes me think that Cucumber 0.8.5 is logging me in, but not storing my session data. Am I missing something? I've heard that recent versions of Cucumber have had issues with storing session data, but I can't figure this one out. Anyone else had a similar problem?
Related
I'm trying to verify the response code of a page by using capybara. I used the expect statement as -
expect(page.status_code).to eq(404)
I'm getting the error as -
Capybara::NotSupportedByDriverError:
Capybara::Driver::Base#status_code
Might be status_code is not supported by Capybara. Is there any other way to verify the status/response code or I'm doing something wrong in the expect statement.
The Selenium driver doesn’t support status_code because it’s not really something you should be testing in a feature/system test. The idea of feature/system tests (which Capybara is aimed at) is to test from a users perspective. Since a user cares about what is shown in the browser thatts what should be tested for rather than the status code. If you still want to test for the status code it should be done in a request spec rather than a feature/system spec
If you don't need JavaScript you can try to fall back on the default rack_test driver:
it "responds with status code 404", js: false do
expect(page.status_code).to eq(404)
end
I am using Cucumber to perform automated tests. I am running two features during a run where in I enter my credentials to perform an action in the website. When second feature is executed I will have to re-enter the same credentials but the browser had already stored my credential previously making the script to actually skip/fail at this step. I have shared my script below. Please advice what can be the solution.
I tried deleting cookies but still the problem persists.
When /^I clear cookies$/ do
browser = Capybara.current_session.driver.browser
browser.manage.delete_all_cookies
end
In this case, You need to reset your sessions which will allow you to re login again with out any issues!
in your code:
When /^I clear cookies$/ do
Capybara.reset_sessions!
end
Accept my answer if it works for you!
Starting a new browser session guarantees a clean environment. However, depending on your setup and test suite, it slow tests down too much, but you might want to try that.
Deleting cookies does not drop credentials if you logged in using HTTP basic auth. If that is the case, there's no other generally applicable way than to restart browser.
I'm using Sinatra 1.2.6 in Ruby 1.8.7 and I have something like a Twitter client that I'm writing. I am using the Twitter gem version 1.7.2 written by John Nunemaker. For database ORM I'm using Sequel 3.29.0.
Overall, things are working great. I've got a good Oauth sequence working and any user who goes through the Oauth process can post Tweets to my application.
I cannot however for the life of me get media upload working using update_with_media. I'm trying to upload a multi-part octet-stream image file, keep it in memory and then give it to Twitter.
post '/file_upload' do
user_name = params[:user]
if params[:action] == "FILE-UPLOAD"
unless params[:name].match(/\.jpg|png|jpeg/).nil?
#Assume these 3 lines work, and properly authorize to Twitter
current_user = User[:user_name => user_name, :current_account => "1"]
client = current_user.authorize_to_twitter #Handles the Oauth keys/process
client.update("Text status updates work properly")
#Something incorrect is happening in the next two lines.
#I'm either handling the file upload wrong, or posting wrong to Twitter
datafile = params[:file]
client.update_with_media("File upload from Skype: ", datafile)
return "File uploaded ok"
end
end
end
Yet, when I try this, I'm getting:
Twitter::Unauthorized - POST https://upload.twitter.com/1/statuses/update_with_media.json: 401: Could not authenticate with OAuth.
Its saying the line causing this error is the client.update_with_media line.
I am trying to use Rack::RawUpload, but I don't know if I'm using it incorrectly. If I don't need to use it I won't, but I'm just currently stuck. The only thing outside of this code snippet that's using it is this at the top of my code:
require 'rack/raw_upload'
use Rack::RawUpload
Any help on this would be massively appreciated. I've tried messing around with Tempfile.new() as well, but that didn't seem to help much, and I was either getting 401 or 403 errors. I'm fairly new to Ruby, so being as explicit as possible about changes needed would be really helpful.
I should note that I'd like to avoid putting the file on the filesystem if possible. I'm really just passing along the upload here, and I never need access in my scenario to the file on-disk afterward. Keeping the files in-memory is much preferred.
You need to check how your library HTTP headers are setup and logically connected to the POST method you have written here. The thing is that for upload_with_media, twitter api in this gem version requires you to use http://upload.twitter.com upload endpoint instead of the default api endpoint.
The gem may be forcing the api site so while the OAuth based status update works fine, it crashes when you try it with an image. You will need to check the gem documentation to figure out how to force the upload twitter site into the HTTP headers for this method.
Alternatively, consider updating to the latest twitter gem. This is what I got from http://rdoc.info/gems/twitter
The Twitter::API#update_with_media method no longer uses the custom upload.twitter.com endpoint, so media_endpoint configuration has been removed. Likewise, the Twitter::API#search method no longer uses the custom search.twitter.com endpoint, so search_endpoint configuration has also been removed.
I am designing an automation framework for a web based application. I have used 'Exist' method to check if the user has correctly logged into the application. Something like this:
If Browser("XXX").Page("YYY").WebElement("Either you have entered").Exist(0)
Then
Browser("XXX").Page("YYY").Image("btnok").Click
fnReset = false
Else
If Browser("XXX").Page("YYY").WebElement("Account Search").Exist(0) Then
fnReset = true
End If
Browser("XXX").Page("YYY").Sync
End If
This code works fine , if an invalid username/password is entered as it hits the IF part first.
However, when I try with a valid username/password, the IF condition step keeps running for a long time and the ELSE part is not getting executed at all.
Is there an issue with the timing for which the test waits or is there any other problem?
Could it be that the "Either you have entered" exists even when the login succeeds but isn't visible to the user? Perhaps it has hidden=true. Try to login successfully manually and then highlight that WebElement from the Object Repository. If it doesn't complain that the object does not exist the condition you're using for detecting successful login isn't correct.
first, sorry for the bad english.
I have a test that submit a login form.
after redirect, when I test for a message 'successfully logged...'
then my page.body is
'<h1>Not Found</h1>'
but this works perfectly on browser manual test.
what should I'm doing wrong?
Sounds likely that one of your steps is redirecting in a way that you do not expect.
Check your before filters on the controller and application_controller to determine whether a login/I18n filter is redirecting your page.
If you have the launchy gem installed, you can also add the following to your steps:
And show me the page
Which will fire-up a browser with what capybara is actually looking at, which is useful for sanity checking your steps.
Good luck!
Tests run under their own clean copy of the database. Make sure you've set it up first using rake db:test:prepare, and that you're creating all the data you need for your tests as part of the feature. (I.e. Given there is a user named "Joe"...)