Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automated UI Testing with Appium + Cucumber

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Automated UI Testing with Appium + Cucumber

Avatar for Marcio Klepacz

Marcio Klepacz

February 17, 2016

Other Decks in Programming

Transcript

  1. Automated UI Testing with Appium + Cucumber Marcio Klepacz iOS

    Engineering @ GetYourGuide CocoaHeads, Feb. 2016
  2. Agenda • Problem • Solution • Appium • Fetching elements

    on screen • Creating a test case using Cucumber • Conclusion
  3. Crashes & Bugs • We want to provide an amazing

    experience to our customers, crashes and bugs will not let that happen • If your app is a marketplace, or selling some product, each crash means loss of money
  4. –Compuware, 2013 “Users Have Low Tolerance For Buggy Apps –

    Only 16% Will Try A Failing App More Than Twice”
  5. UI Automated Tests • Keep track of regressions • Detect

    different behaviours between OS versions • End-to-end
  6. UI Automated Tests Solutions for iOS Multi Platform Work with

    iOS7 Big community Easy to record Xcode UI Tests Calabash Appium UIAutomation
  7. Appium • Appium is an open source test automation framework

    for use with native, hybrid and mobile web apps. It drives iOS and Android apps using the WebDriver protocol. • Language agnostic • No need to modify the app • Easy to setup
  8. Setting up Appium 1. Install Appium by cloning the repo,

    using npm or just download on the website $ git clone https://github.com/appium/appium 2. Generate .app or .ipa from a project $ xcodebuild build -workspace ‘Project.xcworkspace' DEPLOYMENT_LOCATION=YES DSTROOT=where/i/want/the/.app 3. Create a file with the desired capabilities $ echo ‘[caps] platformName = “ios" deviceName = "iPhone 6” platformVersion = “9.2” app = “Path/to/.app“‘ > appium.txt
  9. Fetching Elements on Screen 1. Start Appium server $ node

    path/to/appium 2. Start a new session using the Appium Ruby Console (arc) $ arc
  10. Fetching elements on the screen > page UIASearchBar name, label,

    value: Search GetYourGuide UIATableCell name, label: Main city UIAStaticText name, label, value: Rome … > find(‘Main City’) <Selenium::WebDriver::Element: 0x42d3a id="2">
  11. Interacting with elements > find("Main City").click > find("Back").click > swipe(start_x:

    100,start_y: 350, end_x: 200,end_y: 100,duration: 500) > find_elements(:xpath, '//UIATableView/ UIATableCell').first.click
  12. Cucumber • Cucumber is an open source framework for writing

    and executing high level descriptions of your software's functionality. • You define user story, not specifications. + Appium Ruby Client Cucumber Appium Server
  13. Cucumber test scenario Feature: User is greeted upon login Scenario:

    User sign in Given the user “[email protected]” has an account When he logs in Then should be able to see "Welcome CocoaHeads"
  14. Cucumber / Defining Steps # ./step_definitions/steps.rb Given /^ the user

    "(.*?)" has an account$/ do |el_value| # Execute a command to setup our scenario end When /^he logs in$/ do # Execute command to tap the log in button end Then /^ should be able to see "(.*?)"$/ do |el_name| # Execute command that asserts that the element exists end
  15. Cucumber + Appium # ./step_definitions/steps.rb Given /^ the user "(.*?)"

    has an account$/ do |el_value| wait { find(“Profile”).click } wait { button(“Log in or Sign up”).click } … end When /^he logs in$/ do wait { button(“Log in”).click } end Then /^ should be able to see "(.*?)"$/ do |el_name| wait do text_exists = exists { find(el_name) } expect(text_exists).to be true end end
  16. Cucumber + Appium # ./env.rb require 'rspec/expectations' require 'appium_lib' require

    'cucumber/ast' # Create a custom World class so we don't pollute `Object` with Appium methods class AppiumWorld end # Load the desired configuration from appium.txt, create a driver then # Add the methods to the world caps = Appium.load_appium_txt(file: File.expand_path('./', __FILE__), verbose: true) Appium::Driver.new(caps) Appium.promote_appium_methods(AppiumWorld) World { AppiumWorld.new } Before { $driver.start_driver } After { $driver.driver_quit }
  17. Conclusion • Appium is easy to setup. You don’t have

    to modify your project and is language agnostic. • Cucumber gives you the possibility to write tests in a user stories form, with natural language • Combining Appium with Cucumber helps you keep track of regression, catch crashes & bugs, before going to production