Hướng dẫn cách tổ chức và viết test chung cho ứng dụng chạy trên cả iOS và Android ======================== TỔ CHỨC THƯ MỤC: ======================== - Thư mục ngoài cùng, chẳng hạn Sales_2.0, gọi đây là TEST_HOME - TEST_HOME/features sẽ chứa test, còn TEST_HOME/config sẽ chứa cấu hình test. - Project Sales cho iOS đặt tại một thư mục, chẳng hạn Sales_ios, gọi đây là IOS_APP_HOME - Project Sales cho Android đặt tại một thư mục, chẳng hạn Sales_android, gọi đây là ANDROID_APP_HOME ======================== CẤU HÌNH TEST ======================== 1. Chú ý nội dung TEST_HOME/features/step_definitions/calabash_steps.rb if ENV["PLATFORM"] == "android" require 'calabash-android/calabash_steps' elsif ENV["PLATFORM"] == "ios" require 'calabash-cucumber/calabash_steps' end TEST_HOME/features/support/env.rb if ENV['PLATFORM'] == 'ios' require 'calabash-cucumber/cucumber' elsif ENV['PLATFORM'] == 'android' require 'calabash-android/cucumber' end 2. Chú ý 01.lauch và 02.pre-stop nằm trong TEST_HOME/features/ios/support/ 3. Đường dẫn - Sửa cấu hình tại TEST_HOME/config/cucumber.yml để APP_BUNDLE_PATH chứa đường dẫn /build/Applications/???.app hoặc /path_to_apk_file 4. iOS setup: - Vào IOS_APP_HOME, chạy lệnh calabash-ios setup, ấn Enter để thực hiện quy trình mặc định 4. Android setup: TBA ================== BUILD ================== iOS: - build từ dòng lệnh tại IOS_APP_HOME (có thể phải làm gì đó trước để giải quyết dependency với Pods ??). Sau khi di chuyển thư mục project thì phải build lại. xcodebuild clean build -workspace ".xcworkspace" -scheme "-cal" -configuration Debug -sdk iphonesimulator6.1 DEPLOYMENT_LOCATION=YES DSTROOT=build TARGETED_DEVICE_FAMILY=2 Nếu build cho iPhone thì thay TARGETED_DEVICE_FAMILY=1. Bỏ hoàn toàn tham số này thì dùng option mặc định của scheme. Nếu báo lỗi không tìm thấy scheme thì phải chạy XCode để tạo scheme "-cal" với target "-cal". Thêm i386 vào trong project (nếu có báo lỗi arch i386 khi build tại PC hoặc MacMini) Android: - build từ dòng lệnh tại ANDROID_APP_HOME ant debug ...TBA ================== CHẠY TEST ================== iOS: Tại TEST_HOME/ chạy lệnh cucumber -p ios features/ABC.feature android: Tại TEST_HOME/ chạy lệnh calabash-android run -p android features/ABC.feature ================= Nội dung test ================= (A) TEST_HOME/features/ABC.feature : kịch bản test viết bằng gherkin. (B) TEST_HOME/features/steps_definitions/ABC_steps.rb : định nghĩa từng bước trong kịch bản ABC, viết bằng ruby. Khung của các file Ruby này được Cucumber dựng khi chạy cucumber với kịch bản. Nội dung các file steps chỉ chứa các lệnh sử dụng các lớp screen (C) hoặc gọi các hàm utils (D). Không chứa các nội dung đặc thù iOS hay Android. (C) Định nghĩa các class đại diện cho từng screen. TEST_HOME/features/ios/pages/*_ios.rb TEST_HOME/features/android/pages/*_android.rb Quy ước đặt tên: customer_list_screen_ios.rb và customer_list_screen_android.rb chứa class CustomerListScreen (D) Định nghĩa các hàm tiện ích mà các screen dùng đến: TEST_HOME/features/ios/helpers/utils_ios.rb TEST_HOME/features/android/helpers/utils_android.rb ========================= TÀI LIỆU THAM KHẢO ========================= LessPainful’s sample and guide https://github.com/calabash/x-platform-example Android query language http://blog.lesspainful.com/2012/12/18/Android-Query/ iOS document http://blog.lesspainful.com/2012/07/10/Calabash-iOS-Documentation/