Last active
August 29, 2015 14:07
-
-
Save gunesmes/ba23b20b6daa68daad9d to your computer and use it in GitHub Desktop.
Effective Use of Cucumber with Calabash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'calabash-android/calabash_steps' | |
---------------------------------------------------------- | |
---------------------- GIVEN --------------------------- | |
---------------------------------------------------------- | |
Given(/^I open the application$/) do | |
wait_for(180) {element_exists("button id:'submit'")} | |
end | |
Given(/^I go to "(.*?)" page$/) do |page_button| | |
button_query = "android.widget.Button marked:'#{page_button}'" | |
touch(button_query) | |
end | |
---------------------------------------------------------- | |
----------------------- WHEN --------------------------- | |
---------------------------------------------------------- | |
When(/^I press "(.*?)" button$/) do |button| | |
button_query = "android.widget.Button marked:'#{button}'" | |
touch(button_query) | |
end | |
When(/^I enter "(.*?)" text field as "(.*?)"$/) do |text_field, value| | |
touch("EditText hint:'#{text_field}'") | |
keyboard_enter_text value | |
end | |
---------------------------------------------------------- | |
----------------------- THEN --------------------------- | |
---------------------------------------------------------- | |
Then(/^I should see "(.*?)" page$/) do |page| | |
query "TextView marked:'#{Messages.pages[page]}'" | |
end | |
Then(/^I should see message as "(.*?)"$/) do |message| | |
q = query("TextView id:'message'") | |
page_message = q[0]["text"] | |
page_message.should == message | |
end | |
Then(/^I should see home page$/) do | |
q = query("TextView id:'home_message'") | |
message = q[0]["text"] | |
message.should == 'Welcome to Home Page' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Login feature | |
Background: User should open the application | |
Given I open the application | |
Scenario: As a user I can see login page | |
Then I should see "login" page | |
Scenario: As a in-valid user I can see error message | |
When I enter "username" text field as "mesut-test" | |
And I enter "password" text field as "mesut" | |
And I press "login" button | |
Then I should see message as "Username or Password is incorrect!" | |
Scenario: As a valid user I can see page | |
When I enter "username" text field as "mesut-test" | |
And I enter "password" text field as "12345" | |
And I press "login" button | |
Then I should see "home page" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Messages | |
class << self; | |
attr_accessor :pages | |
end | |
# -- buttons list -- | |
@pages = { | |
"login" => "Welcome to Test Application", | |
"sign-up" => "Welcome to Sign-Up Page", | |
"home" => "Welcome to Home Page" | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Sign-up feature | |
As An anonymous user | |
I Want to be member of the application | |
So That I can register with sign-up form | |
Background: User should open the sign-up form | |
Given I open the application | |
And I go to "sign-up" page | |
Scenario: As a user I can see login page | |
Then I should see "Sign-up" page | |
Scenario: User should see form validation message for empty fields | |
When I press "sign-up" button | |
Then I should see message as "Please fill the form" | |
Scenario: User should see form validation message for empty password | |
When I enter "username" text field as "Mesut" | |
When I press "sign-up" button | |
Then I should see message as "Please fill the form" | |
Scenario: User should see form validation message for empty re-password | |
When I enter "username" text field as "Mesut" | |
When I enter "password" text field as "Mesut" | |
When I press "sign-up" button | |
Then I should see message as "Please fill the form" | |
Scenario: User should see succesfull registion message | |
When I enter "username" text field as "Mesut" | |
When I enter "password" text field as "Mesut" | |
When I enter "re-type password" text field as "Mesut" | |
When I press "sign-up" button | |
Then I should see message as "User is registered. Click login button for login page" | |
Scenario: User should see username dublication error | |
When I enter "username" text field as "Mesut" | |
When I enter "password" text field as "Mesut" | |
When I enter "re-type password" text field as "Mesut" | |
When I press "sign-up" button | |
Then I should see message as "User is exists, change user name" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You can write your global funtion to use for general uses | |
# such adding member to database, deleting comments or etc. | |
# You need to require this file in your env.rb as require "support/messafes.rb" | |
# or you can use following to require every files: | |
# Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file } | |
def add_user(username, password) | |
# since we don't have database configuration, we don't add user | |
# instead db, we will use user.txt so you need to add the following | |
# user manually: | |
username = "mesut_test" | |
password = "12345" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment