Hello readers, welcome back. In this blog, we will do some hands-on with Appium and we will write our first Program. As we have already discussed what is Appium how it helps in application automation testing, what all other features of the Appium. But in this blog, we will only focus on how to start with our first program.
In our first program, we will try to install an apk and open that application on the emulator.
you can refer below code snippet as a reference for installing and opening an application on an android device.
import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; import java.net.MalformedURLException; import java.net.URL; public class AppiumBasic { AndroidDriver driver; public void testAppium() throws MalformedURLException, InterruptedException { File file = new File("/home/knoldus/Desktop/appium/apk/ApiDemos-debug.apk"); DesiredCapabilities capability = new DesiredCapabilities(); capability.setCapability("deviceName","appiumEmulator"); capability.setCapability("platformVersion","9"); capability.setCapability("platformName","Android"); capability.setCapability("app", file.getAbsolutePath()); driver = new AndroidDriver(new URL("http://127.0.1.1:4723/wd/hub"), capability); Thread.sleep(10000); driver.quit(); } }
We can divide this code into two parts.
- Desired Capabilities.
As we have already discussed that desired capabilities are required to set up the desired environment on the emulator like what app we want to test, on which device we want to test and all. - Android Driver.
The android driver helps us to connect with the server. Once we are invoking the android driver we need to pass two arguments with it.
a. server link where Appium is running (here it is “http://127.0.1.1:4723/wd/hub”)
b. Desired capability object.
apart from this, these are some prerequisites before running this code.
- Make sure that the Appium server is started and running.
- There should exist an emulator or real device on which we will test our application.
- There should exist an app that we want to install and run on an emulator.
References:
https://blog.knoldus.com/nuts-and-bolts-of-appium
https://blog.knoldus.com/sessions-in-appium/
https://www.udemy.com/course/mobile-automation-using-appiumselenium-3/learn/lecture/15052540
