Google+ Followers

Friday, 24 January 2014

how calabash cross platform example loads platform specific commands

If you are looking to share test code between ios and android - this is the best example https://github.com/calabash/x-platform-example


Download the project from github using client like source tree or tower  or as zip (https://github.com/calabash/x-platform-example/archive/master.zip)


When you run the test using this command there are lots of background stuff happening 
calabash-android -p android app.apk


  • Cucumber profile

cucumber.yml file is scanned for profile mentioned above
based on configuration specified there (https://github.com/calabash/x-platform-example/blob/master/config/cucumber.yml)

features, step definitions, support,helpers and step definition files are loaded.
only directories that are shared between IOS and android ( like step definitions / features / support files) and android specific directories are loaded

yml file can be organised  little better by separating common (common_path)and android (android_common_path) files  
    <% common_path = "-r features/support -r features/step_definitions -r features/BasePages" %>
    <% android_common_path = "-r features/android/support -r features/android/helpers  -r features/android/pages/" %>
    android: RESET_BETWEEN_SCENARIOS=1 PLATFORM=android <%= common_path %> <%= android_common_path %>  --tags @test1 -v

Below files are loaded before tests are run 

features/android/support/app_installation_hooks.rb
features/android/support/hooks.rb
features/support/env.rb

    based on profile enviroment variables are set, based on enviroment variables calabash test setup will be done
    check here for RESET_BETWEEN_SCENARIOS example

    • Calabash libraries

    take a look at this file features/step_definitions/calabash_steps.rb
    based on PLATFORM variable set in profile ios or android libraries are loaded


      if ENV["PLATFORM"] == "android"
        require 'calabash-android/calabash_steps'
      elsif ENV["PLATFORM"] == "ios"
        require 'calabash-cucumber/calabash_steps'
      end


    All page classes must include calabash like shown below in order to include calabash libraries 

    MainPage < Calabash::ABase

    IOS 
    MainPage < Calabash::IBase


    some more good practices to share code

    1. create base classe for ios and android and inherit the class into ios or android as required, place common methods in base class
    2. share queries between ios and android - www.mobiletestworld.com/2014/01/how-to-share-calabash-commands-between.html
    3. create common method to share between ios and android ( helper classes to read files / read excel etc and place them in  one of the shared folders (mentioned at beginning of topic)


    1 comment:

    1. Selenium is a Web UI based tool and it helps to control web driver and it is also used for Web UI related testing. Start your career in selenium field.
      Selenium Training in Chennai | Selenium Course in Chennai

      ReplyDelete