Integrate into Your IDE to Run Your Appium Tests

How to integrate into your IDE to run your Appium Tests:

Efficient test automation does not include execution of tests one at a time.

Parallel execution, or running of multiple tests at once, is the key, and we need to create an environment that allows for this. Such an environment must be equipped with some sort of logic for creating rules and dependencies between tests.

This tutorial is a part of our Appium Studio online video tutorials series.

Integrating Appium Studio with your IDE is the answer to this problem. Junit, TestNG, Eclipse, IntelliJ, Visual Studio, etc.  all link with Appium Studio. All tests created in the studio can be exported to these IDEs once they are completed, and from there they can be edited and run in your testing environment.

Two locally connected mobile devices can be used to run your tests in parallel with Appium Studio. You can even test on an unlimited number or more than that indirectly through the SeeTest Digital Assurance Lab.

Programming Languages

The following instructions and video tutorials will explain how you can integrate your testing environment with the Appium Studio and perform parallel execution testing with two locally connected mobile devices.

Download the free Appium Studio Community Edition

Here are few video tutorials:

1. Create a new Appium testing project in Eclipse (Gradle)

To start, create a new project in whichever IDE you prefer.

For our example, we use Eclipse. We begin with a new Java project. Then, we add the necessary libraries and dependencies to the project. We build the path to the clients\appium\java folder. Version maintenance and updates are handled by Appium Studio.

1.1. Create a new Gradle project, File->New->Other…

New Gradle Project

1.2. Select ‘Gradle Project’

Select Gradle Project

1.3. Tick the ‘Create a simple project (skip archetype selection)’ checkbox, then click “Next.”.

Create New Project

1.4. Then open the project and subsequently open the build.gradle file. The generated code will be there, which should be replaced with the following:

Build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
repositories { 
 maven { url "https://cloud.experitest.com/repo" }
 maven { url "http://repo.maven.apache.org/maven2" }
mavenCentral()
}
dependencies {
 compile group: 'com.experitest', name: 'appium', version:'4.1.2'
}

1.5. Eclipse is prepared by running clean, cleanEclipse, and Eclipse.

Clean Eclipse

2. Create a new Appium Test Class

2.1.  Select New->Class in the right-click drop-down menu of your source folder.

Create a New Appium Test Class

2.2. Name your test and click ”Finish”.

Name the Appium Class

3. Export your Appium test into Eclipse or any other IDE

Return to the Appium Studio next.

You can select a programming language from the dropdown menu in the coding area. The default language is Java, but the code can also be generated for C#, Python, and Ruby.

The code for your framework will be automatically generated by the Appium Studio.

Copy your code. In this case, we have a full Java program ready to be pasted into our IDE.

Export the Test into Eclipse

4. Edit your Appium tests according to your testing requirements

Test flow is “Before, Test, After.”

Each has the same structure even though the specific use cases differ slightly within the framework.

The before script will be explored first.

4.1 Script – Before

“Before” handles the environment setup. This includes where reports are saved, which devices to use for execution, and initialization of a webdriver object, where all the test commands will be executed from.

  • The parameters of the execution report are the sets in the first three lines of the Before script.
  • The fourth line of the script is where the device indication is.
  • The last line, driver = new AndroidDriver<AndroidElement>(new URL(“http://localhost:4723/wd/hub”), dc); is the WebDriver object initialization. This is the Appium object, where all commands and utilities for Appium are hosted.

Before Script

4.2 Test

The “Test” script contains all of the actual testing.

The Webdriver that we initialized in the “Before” script executes all the Appium commands.

  • All Appium Studio commands are now available as methods of the newly-initialized WebDriver.
  • These commands will take the form of void methods, which return no data, and value-return methods, which can be analyzed and used among the script logic.

Test Script

4.3 After

 The “After” script is the one where the instructions for post-execution actions will go. The results of the tests are not relevant, but rather the completion process is defined for a test regardless of the result is what this script considers.

Typically, the After script generates test reports, saves them to a specified location as defined in the Before script, and releases drivers.

  • The driver.quit() command creates the current test case report (as configured in the @Before block) and releases the test execution agent and allowing it to move on to a new device.

 After Script

5. Run your Appium Tests in Parallel on Two Locally Connected Device

The following details explain how to use TestNG and IntelliJ to run automation tests in parallel on multiple devices.

The following test is an extension of the XPath, tje one we have already seen.Several commands have been added, including a money transfer and a balance validation after the transfer. Another device is opened for a demonstration of parallel execution.

Export the code for use in an IDE.

As discussed earlier, this is simply copy-pasted from the code area after selecting a programming language.

Next, we move onto IntelliJ.

Run Appium on two local devices

Open and name a new test class.

New Test class

Name new test class

Name the test class.

The Before, Test, and After scripts in TestNG are different, so these must also be updated. The appropriate changes should be suggested by the IDE.

TYPE should be changed from UDID to platform, and value should be changed to iOS. This allows for parallel execution on multiple iOS devices.

change type from UDID to platform

In the XML file, define the parallel execution parameters.

If we wish to create two tests for parallel execution, we can create them and name them. Below, we see two test named Eribank10 and Eribank11. The name of the Java class that we wish to run must be added, which in this case is the same for both tests.

Then we choose to run the tests in parallel and specify the number of threads, and we’re done.

Specify the number of threads

Run the project, then return to Appium Studio, where you’ll be able to see the tests running on the Device Reflection. Appium Studio must remain open for the tests to complete.

(Note: Click on the below image for an enlarged view)

Execute the project

Once the tests are complete and the execution has finished, we can see the test and suite results in our IDEA (again Eclipse for our example).

Check our upcoming tutorial to know how to run large-scale parallel execution of Appium tests.

PREVIOUS Tutorial #8 | NEXT Tutorial #10


Further Reading