Appium is an open-source tool for automating native, mobile web and hybrid applications on iOS and Android platforms. Appium is a server written in Node js. Through Appium you can test automatically your mobile application either on emulator or on real device.
Features:
Appium server reads the command coming in from test Java code and executes that command on real device as well as on emulator.
Basic configurations before switching on app automation on a windows machine
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class AndroidTest {
static WebDriver driver;
public static void main(String arr[]) throws MalformedURLException, InterruptedException
{
File app= new File("apk-file-path");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability("deviceName", "your-device-name");
capabilities.setCapability("platformVersion", "platform-version");
capabilities.setCapability("platformName", "platform-name");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.findElement(By.id("username-element")).sendKeys("username");
driver.findElement(By.id("password-element")).sendKeys("password");
driver.findElement(By.id("password-element ")).click();
driver.quit();
}
}
So let’s try to get an understanding of what we are trying to achieve in the above code snippet.
Features:
- Appium is “cross-platform”: It facilitates cross platform testing for both iOS and Android using the same API.
- Appium is open source.
- You don’t need source code of app to automate it.
Appium server reads the command coming in from test Java code and executes that command on real device as well as on emulator.
Basic configurations before switching on app automation on a windows machine
- At least Java 8 should be installed on your machine for running Appium server. Make sure environment variable and path are set properly.
- Microsoft .NET framework 4.5 should be installed on your machine.
- Download Android SDK and set the path in environment variable for ‘tools’ and ‘platform-tools’ folder.
Note: Each version of android supports some API level. Appium supports above or equal API level 17 of Android. - Developer mode should be ‘ON’ on your device and inside developer mode ‘USB debugging’ option should be set to ON.
Note:
• If Developer mode is not ON then you have to click 6 times on ‘About phone’ option in settings.
• ‘RSA key accept’ popup must come when above setting is on and you connect you device to PC. Please accept it.
• I faced a driver installation issue. If you face same issue then please install ‘PDANet’ software on your machine.
• To verify your phone is connected properly, you have to open Eclipse IDE available with Android SDK and launch DDMS mode. If your device is appearing it means your phone is connected properly. - Download & install Appium on your machine.
- Selenium server/Selenium Java client JAR file should be added in your project. Get best selenium training by experts. https://coursedrill.com/manual-testing-course/
- Appium Java client should be added in your project.
- gson-2.2.4.jar file.
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class AndroidTest {
static WebDriver driver;
public static void main(String arr[]) throws MalformedURLException, InterruptedException
{
File app= new File("apk-file-path");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability("deviceName", "your-device-name");
capabilities.setCapability("platformVersion", "platform-version");
capabilities.setCapability("platformName", "platform-name");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
driver.findElement(By.id("username-element")).sendKeys("username");
driver.findElement(By.id("password-element")).sendKeys("password");
driver.findElement(By.id("password-element ")).click();
driver.quit();
}
}
So let’s try to get an understanding of what we are trying to achieve in the above code snippet.
- We created a new Java project in Eclipse and added/build above mentioned JAR files in your project.
- Add the Android apk file path in our code.
- Set the above mentioned device capabilities.
- Initialize WebDriver instance with AndroidDriver as the path for Appium server through which they can connect to each other.
- Now find elements and perform action on those elements. You can find an element’s id by launching the uiautomationviewertool available in Android SDK tools folder. You need to take a screenshot of the device and hover mouse on that particular element.
- Quit your driver.
- Launch Appium server.
- Execute the above java code from Eclipse.
- Now it will start executing script on real device or on emulator.
Last edited: