Native apps are basically developed for a particular platform, and they can take an advantage of the device's features. They can work offline. You can install a native app directly on to the device or through an application store, such as Google Play or Apple App Store.
Here, we are going to take an example of the Android calculator app, and in this section, we will take a look at the addition of two numbers.
Perform the following steps to automate the calculator app:
setup()
method to launch the calculator app:caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name caps.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2"); caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
name
:WebElement five=driver.findElement(By.name("5")); WebElement four=driver.findElement(By.name("4"));
name
and AccessabilityID
, respectively:WebElement plus=driver.findElement(By.name("+")); WebElement equalTo=driver.findElementByAccessibilityId("equals"));
click
on the element:five.click(); plus.click(); four.click(); equalTo.click();
public class TestAppIication { AndroidDriver driver; @BeforeClass public void setUp() throws MalformedURLException{ DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4"); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android emulator"); caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name caps.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2"); caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); } @Test public void testExample(){ WebElement five=driver.findElement(By.name("5")); five.click(); WebElement plus=driver.findElement(By.name("+")); plus.click(); WebElement four=driver.findElement(By.name("4")); four.click(); WebElement equalTo=driver.findElementByAccessibilityId("equals")); equalTo.click(); } @AfterClass public void tearDown(){ driver.closeApp(); } }
Here, we are going to take an example of an iOS TestApp; you can get it from https://github.com/manojhans/Appium/blob/master/Application/iOS/Native/TestApp7.1.app.zip?raw=true. After downloading it, extract it to a local folder (for example, /Users/mhans/appium/ios/TestApp.app
). The downloaded app will look like the following screenshot:
In this section, we will take a look at the addition of two numbers. To do this, perform the following steps:
setup()
method to launch the TestApp
:File app=new File("/Users/mhans/appium/ios/TestApp.app");//You can change it with your app address caps.setCapability(MobileCapabilityType.APP,app);
name
:WebElement editBox1=driver.findElement(By.name("TextField1")); WebElement editBox2=driver.findElement(By.name("TextField2"));
AccessibilityID
:WebElement computeSumBtn=driver.findElementByAccessibilityId("Compute Sum"));
editBox1.sendKeys("10");
editBox2.sendKeys("20");
computeSumBtn.click();
public class TestAppIication { IOSDriver driver; @BeforeClass public void setUp() throws MalformedURLException{ File app=new File("/Users/mhans/appium/ios/TestApp.app");//You can change it with your app address DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.APP,app); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1"); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS"); caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 5"); driver = new IOSDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); } @Test public void testExample(){ WebElement editBox1=driver.findElement(By.name("TextField1")); editBox1.sendKeys("10"); WebElement editBox2=driver.findElement(By.name("TextField2")); editBox2.sendKeys("20"); WebElement computeSumBtn=driver.findElementByAccessibilityId("Compute Sum")); computeSumBtn.click(); } @AfterClass public void tearDown(){ driver.closeApp(); } }
3.15.4.52