A corda.

Eu tenho medo que você morra. Eu muitas vezes quero morrer. Fico aqui pensando se talvez a minha vontade de morrer seja proporcional ao medo que eu tenho que você morra. Melhor morrer do que passar…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Getting started with Automated mobile testing

Hello, readers!

I am going to tell you about creating tests using Cucumber, Appium, and Java in IntelliJ Idea. Next, we will learn how to write a sample feature and automate testing. Let’s get started!

Appium is a powerful tool for testing, but it is not straightforward and easy to install. The documentation does not provide a good tutorial to get things working fast. In this post, I am going to provide everything you need to set up Appium for running a basic test scenario written in Java.

First of all, we need to setup all the components:

Check the installation of the components using the command in the terminal:

If everything is ok, you will see the following screen:

Verify Appium installation

Launch the Appium GUI application ☝️️. Click Android icon and enter these details:

Once the preceding settings are done, click on the General Settings icon and choose the following settings:

Appium settings

Also, you need to install your application on the emulator. You can use the emulator from Android Studio. When it is done — launch the Appium server.

Launched Appium Server

When you start the Appium app, you will see icons at the top. I highlighted the Appium Inspector in red.

Appium

When you click on the highlighted icon (Appium Inspector), it will open a new window with the application UI state capture.

Appium Inspector

Click on any element on the right panel to find the details about it. After clicking Details you will see a group of attributes listed for the selected element:

Details about element

You might notice the attribute “resource-id” and the value of id attribute. It can be used as an identifier for the element in your tests.

To use automation on mobile devices, we will create a simple test for login with correct credentials. The test is written using Page Object Pattern.

Step 2: Add Cucumber plugin and create “.feature” file.

Step 3: Create steps definition. Press Alt+Enter to show the Create Step Definition intention action. Select the target step definition file from the pop-up list.

Step definition

Step 4: Every testing scenario should be executed on some specific testing environment. The desired capabilities for the mobile emulator for Android and iOS:

Step 5: Now we need to add the page with elements and methods using Page Object Pattern:

Step 6: Cucumber has a very interesting feature called hooks. They help us execute a block of code before or/and after each scenario. Add them:

Example of a successful test for Login with valid credentials:

Step 9: Since we want to use the JUnit framework to run Cucumber, we need to create the following class:

You are done 💪

With this, we can run the tests in the same way as we run typical JUnit tests. There is a myriad of different ways you can set up, build and run your Appium tests as well.

In the article, I described how to create tests for a native app. We also learned how to set up Appium. In most cases, Appium is the best choice out of all the available options because it is a ”cross-platform” automation tool and you can write software automation tests against iOS and Android platforms using the same API. By adding a Cucumber framework you integrate a BDD approach into your project. Since BDD is a part of test-driven development (TDD) you also get a shared view and process for all collaborators as a bonus 😃.

Let us know if you have any questions or would like to share your experience with Appium test!

Add a comment

Related posts:

Tre Cannoni

In the Ortler Alps in northern Italy is a minor summit called the Dreisprechenspitze: the ‘three-language peak’. For hundreds of years this tiny mountain was a tripoint — where Switzerland, Italy and…

drawers

My first thought wasn’t so much about the person, as one might have thought. No, I was wondering where the heck all those drawers came from. Dressers are just so plebeian, you know? I use an armoire…

Tears in rain

He lifted his umbrella slightly, through the haze he saw her long graceful strides. Ghostly white, she looked about ready to catch her death. The rain beat down as she walked towards him. He…