April 2, 2020

Appium Testing Tutorial: From Beginners to Advanced

Mobile Application Testing
Automation

Welcome to the only Appium tutorial you need to excel with your mobile testing — regardless of your skillset.

Whether you're just getting started with Appium testing or you're an Appium automation expert, consider this your ultimate guide to mastering Appium mobile testing.

Read along or jump ahead to the section of the Appium testing tutorial that interests you most. 

Back to top

What Is Appium?

Appium is a popular open-source cross-platform testing framework that enables testing teams to write scripts across platforms, including iOS, Windows, and Android using a single API.

Back to top

How Appium Automation Works

One of the best things about Appium automation is that you can use it to test the full system of an app. You can use Appium for:

1. Cross-platform iOS and Android test automation.

2. Mobile native and hybrid applications.

Appium is a mature framework. It has a lively open source community. It’s easy to find answers to Appium questions, especially as Appium releases happen very often. And the quality of the tool is quite good.

Back to top

Is Appium Easy to Learn?

Appium itself is fairly straightforward and easy to learn.

It’s based on the remote WebDriver protocol. It supports almost all the common development languages. If you have skills in writing tests in JavaScript, in Java, in Python, Perl, C#, and so on, you can easily use Appium for mobile testing.

[Related Content: The Complete Guide to Appium Basics]

What’s Making Appium More Complicated

But digital transformation has made Appium testing more complicated.

This includes things like:

  • Complex scenarios that involves mobile device sensors.
  • Maintaining scripts and element locators over time, product releases, and across platforms.
  • Mobile market fragmentation (constant releases of mobile OS and devices).
  • Appium dependency on core OS frameworks (Espresso and XCUITest).
  • 5G networks and changing network conditions.
  • Foldable phones.
  • Mobile environment events (incoming call, system, and security alerts).
  • Transitions from native to progressive web apps.
  • Growth of artificial intelligence (AI) and virtual reality.
  • Even more digital changes and innovations (e.g., AR/VR within mobile apps).

Let’s say you’re testing the UI and functionality of an app today. You’ve taken the factors above into account. But even if you figure it out today, it’s going to change in the future. So, you’ll need to bring Appium to a new level to address future advancements in technology.

The Complete Guide to Mobile Automation Testing >>

That’s why we’ve put together this Appium tutorial with recommendations for beginners and more advanced users.

Get the most out of Appium with Perfecto's unrivaled web and mobile app testing platform. Get started FREE today with our 14-day trial.

Start Trial

Back to top

3 Things You Need to Be Successful With This Appium Tutorial

Before you get started with Appium mobile testing, there are three things you need to consider.

1. Define Your Framework and Scripts

Appium isn’t the only aspect of test automation. You’ll have other tools and frameworks in the mix. So, it’s important to define your framework and scripts.

For example, there are a lot of requirements from multiple frameworks that you might want to include:

  • Executing scripts in parallel.
  • Picking the right iOS and Android devices for testing.
  • Reporting to one reporting system.
  • Controlling the objects you’re working on.
  • Writing good code.

Before you get started with Appium, you’ll need to make sure you have the right framework and scripts to do this.

2. Plan Your Orchestration

You’ll also need to plan your orchestration — especially for mobile testing with Appium.

Orchestration isn’t always easy to maintain. Devices can get disconnected. They might be in use by other scripts or other users. Or you don’t have enough of them available to execute in parallel.

Let’s say you run some tests on iPhone 11, which is the latest iPhone. And then you want to run another test on this same device in parallel. Now, you'll have a problem. And there are only 2 ways to solve it in your own on-premises lab:

  • Adding more devices, which will be costly.
  • Handling it in your framework, which will impact execution time.

Using a cloud-based digital lab — such as Perfecto — is a better way to plan your orchestration.

3. Keep Your Test Data and Test Environment Up-to-Date

It’s critical in mobile testing with Appium — and beyond — to keep your test data up-to-date.

Make sure that all of your environments — QA, staging, production — are always up-to-date with the latest and greatest test data.

You might be basing your tests on data-driven methodology that “reads” from an Excel or CSV file. If so, you also must keep the values up to date. And, as a recommended practice, change values over time (covering positive, negative, and illegal inputs).

You need to have the ability at any given time to address the following questions:

  • What's wrong with my script?
  • What’s wrong with my backend?
  • What’s wrong with my executions and my lab?

Even if you have a very good and successful regression cycle one week, things may change the following week. So, you need an automated system that can always give you visibility — and keep your lab and executions stable. (Perfecto can do this.)

✅ Try Appium With Perfecto

Back to top

Appium Tutorial for Beginners

Here’s an Appium tutorial for beginners:

  1. Install Appium.
  2. Get the Remote WebDriver.
  3. Run tests and validations.
  4. Set up your test flow.
  5. Use Appium Studio to execute tests.

Watch the video below or keep reading for a full recap.

 

 

1. Install Appium

First, you’ll need to install Appium.

You can download Appium to get started.

2. Get the RemoteWebDriver

Next, you’ll need to set up a RemoteWebDriver. This allows you to connect remotely to a cloud or to a lab that has 1 or more devices. In your RemoteWebDriver, you’ll define capabilities and requirements.

Here’s an example (and you can find even more Appium tutorials here):

DesiredCapabilities capabilities = new DesiredCapabilities("mobileChrome", "", Platform.ANY);
String host = "mymobilecloud.perfectomobile.com";
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("user", "myUser");
capabilities.setCapability("securityToken", "myToken");
URL url = new URL("https://" + host + "/nexperience/perfectomobile/wd/hub");
RemoteWebDriver driver = new RemoteWebDriver(url, capabilities);

 

3. Run Tests and Validations

After you set up your RemoteWebDriver, run a test.

@Test(description = "demo", groups = {"@basic"})
public void about(){

    before();
    getDriver().findElement(By.id("com.perfectomobile.calr:id/percentage")).sendKeys("2");
    getDriver().findElement(By.id("com.perfectomobile.calr:id/number")).sendKeys("20");
    getDriver().findElement(By.id("com.perfectomobile.calr:id/CalcBT")).click();
    getDriver().findElement(By.id("com.perfectomobile.calr:id/more")).click();

    String val = getDriver().findElement(By.id("com.perfectomobile.calr:id/extraData")).getText();
    getReportiumClient().reportiumAssert("verify    ",val.equals("10.0"));
}

In this example, you get the driver, which is an object. The driver already got the capability and connected to the device. And then you can identify what you want to do.

In this case, ask to find specific element by ID. You can do different actions on each element. If it's a field, you can just send a key. If it’s a button, you can actually press on the button.

So, you have to remember that when you run tests, you have a form. You enter a lot of data into the form, but the other things are very important. Get the results from the form itself or from Appium. Then run some specific validations to validate that the expected results actually appear in Appium.

4. Set Up Your Test Flow

Appium will just be one part of your test flow. You might also be doing CI with Jenkins and Perfecto. Here’s an illustration of how that test flow might be set up. 

In Appium, this means you’ll execute a command, get a response, and move on to the next command.

5. Use Appium Studio to Execute Tests

Appium Desktop is a beginner-friendly way to execute tests.

This is an application that enables you to connect with a specific device and record a script. For example, you can connect this to the Perfecto Mobile Cloud.

Once connected, you can use Appium to execute full tests on all elements on a real device in the Perfecto Mobile Cloud.

See a quick demo starting at 24:15 of this Appium tutorial webinar >>

 

Back to top

Advanced Appium Testing Tutorial

Have more advanced coding skills? Take the tutorial up a notch with these advanced steps.

1. Follow Steps 1–4 in the Beginner Tutorial

Steps 1–4 in the beginner Appium tutorial also apply (if you haven’t already set these things up).

2. Use Behavior-Driven Development to Execute Tests

To execute tests, you’ll use behavior-driven development (BDD). When you work in BDD, you’ll need a different workflow to develop, write, test, and execute.

Here’s what you’ll need to do to get started.

Get Strong Coders

You’ll need 1–2 strong coders. They’ll create heavy code with a lot of custom step-definition functions in Java. This will be like building blocks. Your coders will need to be able to make it very robust, so it can support different devices and scenarios that later on will serve as base for Gherkin style tests.

Use a BDD Framework

For BDD, Perfecto developed a framework called Quantum. It’s open source. And it allows for mobile and web app testing using the Appium framework in Java and JavaScript.

Everything here can connect with the local devices, browsers, and the cloud. In this case, it connects to the Perfecto cloud. It supports full execution and scale to leverage data providers like testNG and Maven, as well as continuous integration servers like Jenkins.

You can also develop custom functions to be (re)used by test engineers in Java. And then, on top of that, simply run and develop your Cucumber code to get your test coverage.

To scale the test execution across platforms and browsers, data providers like testNG allows developers to specify using annotations within the XML file, which test scenarios will run against which platforms.

In the below example:

  • All of the scenarios under “SKO” annotation will run on any available iPhones in the Perfecto cloud.
  • All scenarios under “Sanity” annotation will run on any available Samsung devices in the Perfecto cloud.
<!DOCTYPE suite SYSTEM "http://testng.org/testing-1.0.dtd">
<suite name="Web Demo Suite" verbose="0" parallel="tests"
         thread-count="100">
    <listeners>
          <listener class-name="com.quantum.listeners.QuantumReportiumListener" />
     </listeners>

    <test name="Web Scenarios Android Test" enabled="true"
        thread-count="10">
    <parameter name="driver.capabilities.model" value="iPhone"></parameter>
    <groups>
          <run>
               <include name="@sko" />
          </run>
    </groups>
    <classes>
          <class
                    name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
    </classes>
    </test>
    <test name="Web Scenarios iOS Test" enabled="true"
        thread-count="10">
    <parameter name="driver.capabilities.model" value="Samsung"></parameter>
    <groups>
          <run>
               <include name="@Sanity" />
          </run>
    </groups>
    <classes>
          <class
                    name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
    </classes>
    </test>
</suite>

 

Use Advanced Perfecto and Appium Capabilities

Now, you’ll use Perfecto Cloud and Appium to run a very advanced test scenario.

Here’s an example. You have an expense application. You want to test taking a picture of a receipt for an expense report. On the device in the cloud, you can test injecting the amount and the image of the receipt in the application.

And you can use Perfecto execute this test on multiple operating systems and devices in parallel.

See a quick demo starting at 54:18 of this Appium tutorial webinar >>

 

Back to top

Do Appium Mobile App Testing the Right Way

Appium is a great framework to have as part of your test automation strategy. But it’s important to do Appium mobile app testing the right way. And that means leveraging a mobile device cloud like Perfecto.

Perfecto and Appium are seamlessly integrated. That means you can create, run, and analyze your test automation with Appium on real devices in Perfecto’s cloud.

With Perfecto and Appium for testing mobile applications, you’ll be able to:

  • Scale your existing testing on multiple platforms.
  • Ensure security for the enterprise.
  • Support advanced automation scenarios (image injection, biometrics, audio validation, etc.).
  • Find and fix bugs faster through advanced reporting.
  • Integrate test automation into your CI/CD stack.

See for yourself why Perfecto makes Appium mobile testing so much better. You can get started with a free 14-day trial of Perfecto today.

Try Perfecto + Appium

 

Related Content

Back to top