简体   繁体   中英

java.lang.ClassNotFoundException is comming when running appium script

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.TestRunne r.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$A ppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 27 more

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: launchWebsite*/

您需要添加此Dependendcy jar https://code.google.com/p/guava-libraries/

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");
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM