Appium Test Setup in Java

Burak Dönmez
Mobile Application Testing
3 min readJul 10, 2020

Appium supports Java language for writing test codes. To write Java codes, i am using Intellij Idea and i will give information about how to write Java codes for Appium in Intellij.

Try RobotQA cloud based device farm for debugging and testing:

Link: RobotQA

Firstly, when creating a project, we will select maven type.

The main purpose of maven type selection is that it provides managing dependencies easily. Open maven.xml and add this dependency in dependencies tag:

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

After adding this dependency, we are now ready to write test. Create a java file in test folder. Right click src/test/java folder and add new java file.

This file is under test folder because intellij uses java files in test folder when running test cases. We have to add junit based annotations because intellij needs them to recognize files as test files. The basic annotations that we use:

@Before

This annotation specifies the startup method. This has to be used just one time. You can think like this is the startup point of our tests.

@After

This is used when test is finishing. This has to be used once like before annotation.

@Test

This annotions implies our test codes. We will write this annotation at top of all methods that have our test codes. You can think that every method corresponds a test case in our sheetbook.

This is screen shot of basic java file.

Method names are not important. The important part is correlation of methods and annotations. The method that has before tag will run first. After that, test methods will run and finally the method that has after anotation will run.

Let’s imagine we have lots of test cases and they has to have priority when running. So that, we have to give priorities the test class. To achieve this, we will use new annotion:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)

This will runs test methods in ascending order as the name implies. Screenshot after last modification is:

Now it is time to configure project in Intellij Idea. To add new configuration, click “Add Configuration” button the left top. Click plus button and select JUnit type. This will open JUnit configuration , click and set“use classpath of module” and class as “Test Kind” option. The java file will be found automatically by Intellij Idea. The configuration screen is:

This is the end of appium junit test setup in Intellij for Java implementation. Finding objects and clicking them will be a subject of next tutorial.

--

--

Burak Dönmez
Mobile Application Testing

Sharing experiences about mobile test automation. cofounder @roboticmobi