FAILED CONFIGURATION: @BeforeMethod setUP

Friends,

See the logs below: Guys help me in resolve this.
Am trying to launch an calculator app on Android Device on My Mac Machine

Error at :
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

======================================
[TestNG] Running:
/private/var/folders/p6/byhmv43s75j890jzr6kd3xph0000gp/T/testng-eclipse–1484498208/testng-customsuite.xml

App launched1
App launched2
FAILED CONFIGURATION: @BeforeMethod setUP
java.lang.NoClassDefFoundError: com/google/common/base/Function
at Demo.Example.setUP(Example.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:590)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:834)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1142)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:771)
at org.testng.TestRunner.run(TestRunner.java:621)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1176)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1101)
at org.testng.TestNG.run(TestNG.java:1009)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
… 27 more

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: testCases

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@95adf3c: 12 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@75115dab: 24 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@18ff8acd: 5 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 3 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1a7811df: 9 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@4ee42af2: 5 ms

My code:

package Demo;

import java.io.File;
import java.net.URL;
//import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
//import org.openqa.selenium.*;
//import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class Example {

public WebDriver driver = null;

@BeforeMethod
public void setUP() throws Exception {

     /* Step 2: Capabilities for Android Driver to Connect to the Android Device */
    
    System.out.println("App launched1");

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "Android");
    capabilities.setCapability("deviceName", "Lokesh Gangaiah");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.4.2");
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");

/* Step 3": Package and Activity Information of a APP To be Tested /
/
Go to AppInformation project and execute the code to get the appPackage and appActivity Information*/

    capabilities.setCapability("appPackage", "com.sec.android.app");
    capabilities.setCapability("appActivity", "com.sec.android.app.popupcalculator");
 //   driver.get("http://m.facebook.com");

/* Step 4 : Appium Server Details to connect the Appium Server */
// driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
System.out.println(“App launched2”);
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    System.out.println("App launched");
}

  @AfterMethod
  public void tearDown() throws Exception {
    driver.quit();
  }
  
  @Test
  public void testCases() throws InterruptedException {
    String myname = "Smriti";
    driver.findElement(By.name("Add")).click();
    driver.findElement(By.xpath("//textfield[1]")).sendKeys(myname);
    driver.findElement(By.name("Save")).click();
    Thread.sleep(5000);
    // write all your tests here
  }

}

Couple of things you may want to update -

Since you are using native app [using app package and activity], you don’t need to pass browser capability. So comment out that line [CapabilityType.BROWSER_NAME]. This is needed only when you are testing on browser.

When I tried same code on my device [Samsung Galaxy S4 with Android version 5.0.1], I had to make following changes for two capabilities :

capabilities.setCapability(“appPackage”, “com.sec.android.app.popupcalculator”);
capabilities.setCapability(“appActivity”, “com.sec.android.app.popupcalculator.Calculator”);

I am able to launch the calculator using these settings, but it will fail as my calculator application does NOT have a element with text “Add”

I did not hit issue - java.lang.NoClassDefFoundError: com/google/common/base/Function …

Thanks Rams. It worked after i comment out Browser_Name.
Thanks again