0

I am very new to appium:

i wanted to run a code where in my device i open chrome and open a google.com:

  @BeforeMethod
  public void setUp() throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName", "Browser");
    capabilities.setCapability("device", "Android");
    capabilities.setCapability("deviceName", "TA9330416L");
    capabilities.setCapability("platformVersion", "5.1");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("appPackage", "com.android.chrome");
    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 launchWebsite()throws InterruptedException {
    driver.get("http://www.google.com");
  }

but getting the following error:

?* FAILED CONFIGURATION: @BeforeMethod setUp java.lang.NoClassDefFoundError: com/google/common/base/Function at WhatsApp.setUp(WhatsApp.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215) at org.testng.internal.Invoker.invokeMethod(Invoker.java:589) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112) at org.testng.TestRunner.privateRun(TestRunner.java:782) at org.testng.TestRunner.run(TestRunner.java:632) at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) at org.testng.SuiteRunner.run(SuiteRunner.java:268) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1246) at org.testng.TestNG.runSuitesLocally(TestNG.java:1171) at org.testng.TestNG.run(TestNG.java:1066) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177) Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 27 more

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: launchWebsite*/

1
  • Check if This solves your issue. Commented Dec 2, 2015 at 4:41

2 Answers 2

3

You need to add this dependendcy jar https://code.google.com/p/guava-libraries/

Sign up to request clarification or add additional context in comments.

3 Comments

Added the jar, getting this error now: @BeforeMethod setUp java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:88) at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:62) at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:57) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153) at WhatsApp.setUp(WhatsApp.java:36)
Now this jar httpclient-4.0.jar is missing. Please search with the class name that is missing in google you will find which jar has it. For example - java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials this class is present in the jar which i specified above.
Thanks yes all the problems were with missing jars. It was a lot of them.Added them all now its working fine.
0

Have to created any test class? Error says no class definition found. You have to create on test class first and define functions in the class. I have not tried on the android browser but I have automated android hybrid and native apps using appium.

package test;

import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;

public class TestBrowser {

public AndroidDriver driver;

public TestBrowser() {
        //To do
}

@BeforeMethod
  public void setUp() throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.0");
    capabilities.setCapability("browserName", "Browser");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "TA9330416L");
    capabilities.setCapability("platformVersion", "5.1");
    capabilities.setCapability("appPackage", "com.android.chrome");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

  }

@AfterMethod
public void tearDown() throws Exception {
        if(driver!=null)
        driver.quit();
 }

  @Test
  public void launchWebsite()throws InterruptedException {
    driver.get("http://www.google.com");
  }
}

2 Comments

He definitely must have added a class. I believe he has posted only Error prone area. The issue is that it is not able to find class com.google.common.base.Functionwhich is not end user defined class.
Yes I have added the test class and I was just showing the error prone areas....I definitely think i have some issue with configurations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.