Hello Guys,
Hope you are doing well !. Today we will learn to launch an installed Android Application like calculator, phone book, etc. I believe you have done your appium setup already. Let's directly jump to code which will launch Calculator application on our mobile.
Hope you are doing well !. Today we will learn to launch an installed Android Application like calculator, phone book, etc. I believe you have done your appium setup already. Let's directly jump to code which will launch Calculator application on our mobile.
import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; public class OpenAppTest { AndroidDriver driver; @Before public void setUp() throws MalformedURLException { // Created object of DesiredCapabilities class. DesiredCapabilities capabilities = new DesiredCapabilities(); // Set android deviceName desired capability. Set your device name. capabilities.setCapability("deviceName", "Intex Aqua_Ring"); // Set BROWSER_NAME desired capability. It's Android in our case here. capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android"); // Set android VERSION desired capability. Set your mobile device's OS version. capabilities.setCapability(CapabilityType.VERSION, "6.0.1"); // Set android platformName desired capability. It's Android in our case here. capabilities.setCapability("platformName", "Android"); // Set android appPackage desired capability. It is // com.android.calculator2 for calculator application. // Set your application's appPackage if you are using any other app. capabilities.setCapability("appPackage", "com.android.calculator2"); // Set android appActivity desired capability. It is // com.android.calculator2.Calculator for calculator application. // Set your application's appPackage if you are using any other app. capabilities.setCapability("appActivity", "com.android.calculator2.Calculator"); // Created object of AndroidDriver will all set capabilities. // Set appium server address and port number in URL string. // It will launch calculator app in android device. driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); } @Test public void openCalculator() { driver.findElement(By.id("com.android.calculator2:id/digit_9")).click(); driver.findElement(By.id("com.android.calculator2:id/op_add")).click(); driver.findElement(By.id("com.android.calculator2:id/digit_7")).click(); driver.findElement(By.id("com.android.calculator2:id/eq")).click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @After public void End() { driver.quit(); } }
Copy and paste the above code with some relevant changes as per your device name and it's
version number. Don't forget to include the appium and selenium JAR files (which you had
downloaded in order to setup the appium) as a library to your IDE(In my case, it's Android Studio).
In order to run this test case, you need to start your appium server as well. You can start appium
server by just typing the “appium” at your terminal. I will not explain anything related to the code in
this blog but in my upcoming blogs. I will share every details as per my knowledge. If you fail to
launch the Calculator application on your mobile using this code. Please let me know about this
by commenting below.
No comments:
Post a Comment