Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber step definition for "Given that I'm logged in"

I've got a cucumber step: Given that I'm logged in

I don't understand how I should implement it as a step definition.

Could someone point me into right direction, tutorials, blogs etc.

like image 299
never_had_a_name Avatar asked Aug 16 '10 19:08

never_had_a_name


People also ask

How do you get step definitions in Cucumber?

Add a Step Definition file 1) Create a new Class file in the 'stepDefinition' package and name it as 'Test_Steps', by right click on the Package and select New > Class. Do not check the option for 'public static void main' and click on Finish button. Take a look at the message in the console window.

Why step definition is not recognized in Cucumber?

If Cucumber is telling you that your steps are undefined, when you have defined step definitions, this means that Cucumber cannot find your step definitions. You'll need to make sure to specify the path to your step definitions (glue path) correctly.

Which Cucumber option can be used to give path for step definition files?

Try using glue = {"stepDefinition.


1 Answers

here is how I do it.

Given /^I have one\s+user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
  @user = User.new(:email => email,
                   :username=>username,
                   :password => password,
                   :password_confirmation => password)
   @user.save!
end

Given /^I am an authenticated user$/ do
  name = 'exmample'
  email = '[email protected]'
  password = 'secret!'

  Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
  And %{I go to the user login page}
  And %{I fill in "user_username" with "#{name}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

The reason I do it this way, is that I run through the entire stack and set the environment up the way a normal user would...

like image 63
Doon Avatar answered Sep 24 '22 04:09

Doon