Appium up and running (working example)

1. Introduction

A few weeks ago I introduced you to multiple Android testing tools. One of them ( Appium) was listed on top of the pyramid as the most powerful one. You can do almost everything with Appium, which makes it the perfect choice for automating your E2E test regression.

In this article, I’d like to introduce you to the Appium setup and show a few examples which were just shared on my GitHub project.

2. Basic setup

Mobile tests are difficult mostly because of complicated setup. Assuming you would use Java I recommend those tutorials:

After completing tutorials you should have all of those installed and working:

  • Android Studio
  • XCode
  • Android Emulator* iPhone Simulator
  • Appium server

3. Applications

So here is another hurdle. What do we test? I prepared my code examples for the following applications:

  • iOS (tested with iOS 13.5)
  • Android (testing with API level 28)

4. Example project

Having all of that up&running you can start the fun part: testing. You need to do the following steps:

  • Download my GitHub project (requires Java 11)
  • Run Appium server, Android Emulator, and iPhone Simulator
  • Change paths to applications in config.properties
  • For iOS tests you need to change spring.active.profiles value to iphone
  • Run tests

5. Android tests overview

For Android I have covered:

  • Basic clicking via multiple activities
  • Text input via classic API and adb
  • Screenshot taking example
public class AndroidSwiftNotesApp extends ExampleFluentTest {

    private static final String SAMPLE_TITLE = "SampleTitle";
    private static final String SAMPLE_BODY = "SampleBody";

    @Page
    private SwiftNoteHomePage noteApp;

    @Test
    public void shouldCorrectlyAddNote() {
        noteApp
                .verifyIfIsLoaded()
                .verifyNoteCount(0)
                .clickAddNote()
                .addNote(SAMPLE_TITLE, SAMPLE_BODY)
                .verifyIfIsLoaded()
                .verifyNoteCount(1)
                .clickAddNote()
                .addNoteUsingAdb(SAMPLE_TITLE, SAMPLE_BODY, appiumDriver)
                .verifyIfIsLoaded()
                .verifyNoteCount(2);
    }

    @Test
    public void searchTest() {
        noteApp.search("FluentLenium");
    }

    @Test
    public void screenshotTest() throws IOException {
        File file  = ((TakesScreenshot)appiumDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(file, new File("Screenshot.jpg"));
    }

}

6. iOS tests overview

For iOS I have covered:

  • Basic clicking via multiple screens
  • Text input via classic API
  • Screenshot taking example
public class IosUITestDemo extends ExampleFluentTest {

    @Page
    private HomePage homePage;

    @Test
    public void shouldCorrectlySwitchView() {
        homePage.clickAboutLink().verifyIfIsLoaded();
    }

    @Test
    public void shouldCorrectlyAddNote() {
        String noteName = "Sample Note";
        String noteDescription = "SampleNoteDescription";

        homePage
                .clickAddButton()
                .addName(noteName, noteDescription)
                .clickAboutLink()
                .verifyIfIsLoaded();
    }

    @Test
    public void screenshotTest() throws IOException {
        File file  = ((TakesScreenshot)appiumDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(file, new File("Screenshot.jpg"));
    }
}

Enjoy and have fun :)

Tags:

Categories:

Updated: