Calabash for iPhone apps

Post on 12-Nov-2014

1.142 views 1 download

Tags:

description

Understand and start work with calabash automated testing for iPhone apps

Transcript of Calabash for iPhone apps

CALABASH

For iPhone Apps

By Chathura Palihakkara.

ROAD MAP

• What is calabash

• Main Components

• Simple demo

• Q & A

• Getting started

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

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

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).

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.

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

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

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

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

REPORTS

Several types of detailed calabash repots

DEMO

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 "calabash@leapset.com" pass "chathura123"

And I wait until UIActivityIndicator is gone

Then I should see myAccount screen

Then I see the text "calabash@leapset.com"

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

DIRECTORY STRUCTURE

Project root

Features folder

Step_definition folder

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

RESULT

Q & A

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

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.

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)

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).

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

Configure iPhone App

You should see like this.

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

Configure iPhone App

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

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

(i)-lxml2 $(inherited)

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

(iii)-lstdc++

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.

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

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

Q & A