运行appium脚本

时间:2015-12-01 17:45:12

标签: java appium

我对appium很新:

我想运行一个代码,在我的设备中我打开chrome并打开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");
  }

但收到以下错误:

  

?* FAILED CONFIGURATION:@BeforeMethod setUp           java.lang.NoClassDefFoundError:com / google / common / base / Function             在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)             在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)             在org.testng.internal.Invoker.invokeMethod(Invoker.java:589)             在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)             在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)             在org.testng.TestRunner.privateRun(TestRunner.java:782)             在org.testng.TestRunner.run(TestRunner.java:632)             在org.testng.SuiteRunner.runTest(SuiteRunner.java:366)             at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)             在org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)             在org.testng.SuiteRunner.run(SuiteRunner.java:268)             在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)             在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)             at org.testng.TestNG.runSuitesSequentially(TestNG.java:1246)             在org.testng.TestNG.runSuitesLocally(TestNG.java:1171)             在org.testng.TestNG.run(TestNG.java:1066)             在org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)             在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)             在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)           引起: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个

     

SKIPPED CONFIGURATION:@AfterMethod tearDown
  SKIPPED:launchWebsite * /

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

必须创建任何测试类吗?错误表示未找到类定义。您必须首先在测试类上创建并在类中定义函数。我没有试过Android浏览器,但我使用appium自动化了android混合和本机应用程序。

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