Created
March 29, 2015 10:02
-
-
Save sjmach/b1b530a693de647773a2 to your computer and use it in GitHub Desktop.
Sample fiile to test whatsapp installation on android device via Appium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sundeepmachado; | |
import java.io.File; | |
import java.net.URL; | |
import junit.framework.Assert; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.annotations.AfterMethod; | |
import org.testng.annotations.BeforeMethod; | |
import org.testng.annotations.Test; | |
public class WhatsApp { | |
private WebDriver driver; | |
@BeforeMethod | |
public void setUp() throws Exception { | |
// set up appium and tell from where it can install the apk file from | |
// computer to device | |
File appDir = new File("E:\\AppiumDemo-master\\AppiumDemo-master\\apps"); | |
File app = new File(appDir, "com.whatsapp.apk"); | |
// Very important properties you need for Appium to work, change as per | |
// SDK and device name | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("device", "Android"); | |
capabilities.setCapability("deviceName", "Huawei MediaPad T1"); | |
capabilities.setCapability("platformName", "Android"); | |
// You need to have this sdk installed for Appium to work | |
capabilities.setCapability("platformVersion", "4.3.1"); | |
capabilities.setCapability("app", app.getAbsolutePath()); | |
// The URL where the hub will start | |
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), | |
capabilities); | |
} | |
@AfterMethod | |
public void tearDown() throws Exception { | |
driver.quit(); | |
} | |
@Test | |
public void whatsAppinstall() { | |
// Find and click the accept button | |
WebElement accept = driver.findElement(By | |
.id("com.whatsapp:id/eula_accept")); | |
accept.click(); | |
// Verify nect page title after you click accept button | |
Assert.assertEquals("Verify your phone number", | |
driver.findElement(By.id("android:id/action_bar_title")) | |
.getText()); | |
} | |
} |
You need to tell Appium that apk is already present. You should set --full-reset as false
Can you help me how to test already installed mobile applications?
See above answer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's very nice. But how do I execute a Whatsapp that is already installed on the phone. If I try this code on a phone that already has Whatsapp installed, it does a fresh setup of the app as if it didn't exist in the first place.