Calabash for iPhone apps

32
CALABASH For iPhone Apps By Chathura Palihakkara.

description

Understand and start work with calabash automated testing for iPhone apps

Transcript of Calabash for iPhone apps

Page 1: Calabash for iPhone apps

CALABASH

For iPhone Apps

By Chathura Palihakkara.

Page 2: Calabash for iPhone apps

ROAD MAP

• What is calabash

• Main Components

• Simple demo

• Q & A

• Getting started

Page 3: Calabash for iPhone apps

WHAT IS CALABASH• Framework that enables you to write and execute

automated acceptance tests for mobile apps.

• Supporting cross-platform, Android and iOS native apps.

• Free and open source.

• Behavior-driven developing(BDD) with natural language.

• Supports continuous integration.

• By Karl Krukow and Joshua Moody

Page 4: Calabash for iPhone apps

CALABASH ARCHITECTURE

Calabash iOS Client

Calabash HTTP server

Device / SimulatorDev PC / Build server

Ruby Gems

Ste

p D

efin

ition

sF

eatu

re F

iles

Fea

ture

File

sF

eatu

re F

iles

Ste

p D

efin

ition

sS

tep

Def

initi

ons JVM

HTTP

Page 5: Calabash for iPhone apps

MAIN COMPONENTS• Feature files

• Contains the sequential actions for the test.• Step definitions

• Contains the steps definitions written in Ruby.• Support files

• Contains project configurations (Build path).

Page 6: Calabash for iPhone apps

FEATURE FILES

• Abstract Description of the Test Case <name of feature>• In order to <meet some goal>• As a <type of role>• I want <a feature>

SCENARIO • Gestures

Touches or gestures (e.g., tap, swipe and rotate).• Assertions

There should be a "Login" button or I should see a Alert message.• Screenshots

Screen dump the current view on the current device model

FEATURE

Note: There is no place like HOME. Always start from HOME and come back to it.

Page 7: Calabash for iPhone apps

FEATURE FILESFeature: Validate user login

As a registered userIn order to see user detailsI want be able to sign in to the App with correct credentials

Scenario: User logged in and see user detailsGiven I go to the Home Screen

When I touch “My account” buttonThen I wait to see Login ScreenThen I enter "my_username" into text field number 1Then I waitThen I enter "my_password" into text field number 2Then I waitwhen I touch "Sign In" buttonThen I wait to see My account screen

Then I should see "my_username” labelThen I should see ”072-3354020” labelwhen I touch "Sign Out" button

Then I wait to see Home ScreenThen I finish the test

Page 8: Calabash for iPhone apps

STEP DEFINITIONS

Then /^I touch the "([^\"]*)" button$/ do |name|

If elements_exist( ["button marked:'#{name}'”])

touch("button marked:'#{name}'")

sleep(STEP_PAUSE)

else

screenshot_and_raise "'#{name}' Button isnt exsist.”

end

end

Then I touch the ”Sign In" button

Page 9: Calabash for iPhone apps

UI QUERY • How you can find the current visible components in the iPhone/

simulator screen.

• Open ruby console to write UI Query

• In mac terminal type “calabash-ios console”

Ex:

1. query("view:'UIButton'",:accessibilityLabel)

[

[0] "icon rewards new",

[1] "icon my receipts new",

[2] "icon my account",

[3] "icon order@2x",

[4] "icon check in"

]

2. element_exists("button marked:'Delivery'”)

false

Page 10: Calabash for iPhone apps

STEP DEFINITIONSCOMBINED STEPS

Then /^I delete order from checkout screen$/ do

steps %{

Then I should see a "Delete" button

Then I touch the "Delete" button after it appears

Then I wait for 1 seconds

Then I see an alert with "Are you sure you want to delete this order?" text

Then I touch the "YES" button

Then I wait for 1 seconds

Then I go Home Screen

}

end

Page 11: Calabash for iPhone apps

REPORTS

Several types of detailed calabash repots

Page 12: Calabash for iPhone apps

DEMO

Page 13: Calabash for iPhone apps

USER LOG-IN WITH CORRECT CREDENTIALS

Feature: User log-in with correct credentials

In order to use LeapsetApp

As a Registerd user

I want to be able to successfully log-in

file_name: demo_login.feature

Test Case: IPA-21

Scenario: User log-in with correct credentials

Given I start from the Home Screen

When I touch MyAccount button

Then I should see login screen

Then I sign In with name "[email protected]" pass "chathura123"

And I wait until UIActivityIndicator is gone

Then I should see myAccount screen

Then I see the text "[email protected]"

Then I see the text "Take rode, My Street, Owk city, AL, 55555”

When I touch Sign Out button

Then I should see home screen

Page 14: Calabash for iPhone apps

DIRECTORY STRUCTURE

Project root

Features folder

Step_definition folder

Page 15: Calabash for iPhone apps

RUNUse Terminal and go to Project directory

Launch the app in the simulator and come to the home page

Then run the command

Now it runs the test on the simulator

Create a result as a HTML page in side the root directory

Page 16: Calabash for iPhone apps

RESULT

Page 17: Calabash for iPhone apps

Q & A

Page 18: Calabash for iPhone apps

GETTING STARTED• Setup calabash environment

• Set up iOS project and configure it for calabash

• Run calabash tests for iPhone app

• Start writing test features

Set up https://github.com/calabash/calabash-ios

Page 19: Calabash for iPhone apps

PREREQUISITES

1. Macintosh PC.

2. Xcode 4.x.x or above Installed.

3. Xcode command line tools Installed.

4. iPhone SDK 6.0 and iPhone simulator 6.0 installed.

5. JAVA JRE 1.6 or above installed

6. Ruby v1.9 or above installed

7. Stable Internet connection.

Page 20: Calabash for iPhone apps

CONFIGURE LEAPSET iPhone CONSUMER APP

• Checkout project source using terminal

$ svn co svn+ssh://checkout url

• Open project using Xcode make sure the app run on the iPhone simulator

• Install calabash-cucumber ruby gem using terminal

$ sudo gem install calabash-cucumber

• Select Leapset project in XCode and select your product target for your app.

• Right click (or two-finger tap) your target and select "Duplicate target” Select "Duplicate only" (not transition to iPad)

Page 21: Calabash for iPhone apps

Configure iPhone App

• Rename your new target from ”ProjectName" to "ProjectName-cal”.

• From the menu select Scheme and select manage schemes Rename the new scheme from "ProjectName copy" to "ProjectName-cal”.

• From the menu select Scheme and select Edit schemes set build configurations to Staging on ProjectName-cal target.(if you have “Staging” scheme else select your scheme correctly).

Page 22: Calabash for iPhone apps
Page 23: Calabash for iPhone apps

Configure iPhone App• Download the latest version of calabash-ios at

https://s3.amazonaws.com/calabashapp/Calabash.zip

• Unzip the file and Drag calabash.framework folder into you project's Frameworks folder in xcode navigation pane.

• Make sure that

(i)Copy items into destination group's folder (if needed) is checked

(ii) only your "-cal " target is checked in Add to targets

Page 24: Calabash for iPhone apps
Page 25: Calabash for iPhone apps

Configure iPhone App

You should see like this.

Page 26: Calabash for iPhone apps

Configure iPhone App• Target Build Settings

• Click on your project and select your new ”ProjectName-cal" target. Select "Build Settings"

• Ensure that "All" and not "Basic" settings are selected in "build settings”.

• Find "Product name" (you can type "Product name" in the search field). Set the Product name to Productname-cal

Page 27: Calabash for iPhone apps

Configure iPhone App

• Find "Valid Architectures" in Build Settings and Add "i386" for the new target.

Page 28: Calabash for iPhone apps

Configure iPhone AppFind "Other Linker Flags" in Build Settings and set flags

(i)-lxml2 $(inherited)

(ii)-force_load "$(SRCROOT)/calabash.framework/calabash"

(iii)-lstdc++

Page 29: Calabash for iPhone apps

Configure iPhone App

• In Xcode select your ”ProjectName-cal" scheme and then run you app on 6.0 simulator once.

• Allow location services by pressing "OK" for the location services alert if present.

Page 30: Calabash for iPhone apps

Configure iPhone App

• Open Terminal and direct it to the project root

$ cd /User/Desktop/release-1.081/ProjectName

• Generate features folder in side the project root using terminal Type

• $ calabash-ios gen• Press "Return(Enter)" again to confirm the action • This will create the default folder structure for

calabash

Features directory created

Page 31: Calabash for iPhone apps

ADD CURRENT TEST TO THE PROJECT

• In the project root add a new calabash feature file in to “features" folder and Launch the app in simulator

• Run the tests using command (since app is already launch in the simulator and running)

• NO_LAUNCH=1 cucumber --format html --out result.html features/<file name>.feature

• You can get help form type cucumber –help

• Open the result.html To see the results.

• Remember feature files ended with extinction “.feature”

• Install eclipse and import and open “features” folder as a project to write new test cases or Net beans have more support with a plugin. https://github.com/QuBiT/cucumber-netbeans-plugin/wiki/Install

Page 32: Calabash for iPhone apps

Q & A