ThoughtWorks
  • Contact
  • Español
  • Português
  • Deutsch
  • 中文
Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

    Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

    Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

    Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
Go to overview

Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
  • Español
  • Português
  • Deutsch
  • 中文
ThoughtWorksMenu
  • Close   ✕
  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact
  • Back
  • Close   ✕
  • Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

  • Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

  • Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Back
  • Close   ✕
  • Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
  • Back
  • Close   ✕
  • Go to overview
  • Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

  • Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

  • All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

  • Back
  • Close   ✕
  • Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

  • Back
  • Close   ✕
  • Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
Blogs
Select a topic
View all topicsClose
Technology 
Agile Project Management Cloud Continuous Delivery  Data Science & Engineering Defending the Free Internet Evolutionary Architecture Experience Design IoT Languages, Tools & Frameworks Legacy Modernization Machine Learning & Artificial Intelligence Microservices Platforms Security Software Testing Technology Strategy 
Business 
Financial Services Global Health Innovation Retail  Transformation 
Careers 
Career Hacks Diversity & Inclusion Social Change 
Blogs

Topics

Choose a topic
  • Technology
    Technology
  • Technology Overview
  • Agile Project Management
  • Cloud
  • Continuous Delivery
  • Data Science & Engineering
  • Defending the Free Internet
  • Evolutionary Architecture
  • Experience Design
  • IoT
  • Languages, Tools & Frameworks
  • Legacy Modernization
  • Machine Learning & Artificial Intelligence
  • Microservices
  • Platforms
  • Security
  • Software Testing
  • Technology Strategy
  • Business
    Business
  • Business Overview
  • Financial Services
  • Global Health
  • Innovation
  • Retail
  • Transformation
  • Careers
    Careers
  • Careers Overview
  • Career Hacks
  • Diversity & Inclusion
  • Social Change
Software TestingTechnology

Testing native iOS applications with Twist

ThoughtWorks ThoughtWorks

Published: Nov 18, 2013

Twist supports native iOS application testing since version 13.3. Twist uses an open-source project called calabash to enable native iOS testing. calabash has support for both native and hybrid applications.

 

 

 

Getting started

Create a new Twist project with calabash driver.

create a twist project with calabash driver

While creating a project, you have to specify the XCode project location. Clicking Finish will create a Twist project with calabash driver. Twist modifies the project's project.pbxproj file and adds a calabash.framework to the link path. This will be added to a new target with -cal suffix. Eg: For an existing target named sample, Twist will add a new target called sample-cal. sample-cal will have calabash.framework linked to it. You need to build this target before running the tests.

calabashworks by altering your iOS application and embedding a HTTP server to it. This server will be started when the application is launched. The server component takes care of doing the actions specified by the Twist client.

Writing your first test

Twist has a fairly simple API for testing native iOS applications. An application is represented by the class IOSApplication. Twist launches the application under test and provide an instance of IOSApplication to the test implementation code. A typical Twist fixture would like the following.

twist scenario for native ios testing twist fixture for native ios testing

Elements in the iOS application are represented by the class UIElement. You can query using IOSApplication to get a UIElement. To query for a label with text foo, you would write the code like:

UIElements uiElements = iosApplication.query("label marked:'foo'");

Above code returns a collection of UIElement. Given a UIElement, you can perform various actions on it. To perform a touch on the label:

UIElement label = iosApplication.query("label marked:'foo'").first();
label.touch();

Let us assume touching on label foo, opens up a keyboard. Let us enter something to the current edit field.

UIElement label = iosApplication.query("label marked:'foo'").first();
label.touch();
iosApplication.awaitKeyboard();
iosApplication.getKeyboard().enterText("text entered using Twist");
iosApplication.getKeyboard().done();

Let us verify the text got entered correctly into the editable field.

assertTrue(iosApplication.elementExists("label marked:'text entered using Twist'"));

Now let us swipe the view and wait for the next screen to come up.

iosApplication.query("view").swipe(Direction.LEFT);
iosApplication.waitFor(new ICondition() {
    @Override
    public boolean test() throws CalabashException {
        return iosApplication.elementExists("label marked:'in second screen'");
    }
});

Same set of commands will work with UIElement and UIElements. When using UIElements, Twist will act upon the first element available in the collection.

calabashsupports powerful query syntax. To learn more about all types of queries that you can perform, visit the calabash wiki.

Testing interactively

Most of the time, your application will have many elements and element hierarchies. It will be bit difficult to get an idea about how elements are laid out in the application. You need to know how elements are laid out and what are the accessibility properties it has to write efficient queries. Twist makes this process easier by introducing Application Spy. Application spy helps you to get started with the API easily.

In the Twist IDE, select the iOS Twist project, click on the Spy icon to launch application spy. Application spy can also be launched by right clicking on the scenario editor and choosing Application spy.

launching application spy using toolbar launching application spy using context menu

Spy looks like the following.

twist native ios testing - application spy twist native ios testing - application spy with simulator

When you start application spy, it launches the application in a simulator/device (depending on the configuration), inspects the elements in that application and displays a hierarchical view of the entire application. Now it is very easy to understand how an application is laid out. With application spy, you can try out different commands interactively.

  • You can enter a calabash query and get a hierarchical representation of the elements.
  • You can click on the elements which are shown in the left pane of application spy and Twist will flash the respective element in the simulator/device.
  • You can right click on an element and perform actions like, touch, swipe etc on it. Twist will generate sample code for the action that you have performed. This code can be copied to the scenario implementation if required.
  • You can inspect element's default properties. New properties can be added if required.

Restarting application between scenarios

Twist won't restart the application after the scenario execution. If you need to restart the application after each scenario, you can write a context which does this.

twist native ios testing - context twist native ios testing - context

Caveats

  • No recorder available. You can use the code generated by application spy, but that is not a first class recording option.
  • Application's source code should be available to perform testing. This is required for embedding the calabash.framework.
  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact

WeChat

×
QR code to ThoughtWorks China WeChat subscription account

Media and analyst relations | Privacy policy | Modern Slavery statement ThoughtWorks| Accessibility | © 2021 ThoughtWorks, Inc.