Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在android项目中包含selenium库?_Java_Android_Selenium - Fatal编程技术网

Java 如何在android项目中包含selenium库?

Java 如何在android项目中包含selenium库?,java,android,selenium,Java,Android,Selenium,我尝试为我的android应用程序创建第一个自动测试。我已经找到了一个有用的库,并一步一步地执行相同的操作,但在包含库和重建项目后,仍然找不到一些库: 导入org.openqa.selenium.由;进口 org.openqa.selenium.远程.CapabilityType;进口 org.openqa.selenium.远程。所需功能;进口 org.openqa.selenium.remote.RemoteWebDriver 我的代码: import org.junit.After;

我尝试为我的android应用程序创建第一个自动测试。我已经找到了一个有用的库,并一步一步地执行相同的操作,但在包含库和重建项目后,仍然找不到一些库:

  • 导入org.openqa.selenium.;进口
  • org.openqa.selenium.远程.CapabilityType;进口
  • org.openqa.selenium.远程。所需功能;进口
  • org.openqa.selenium.remote.RemoteWebDriver
我的代码:

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;



public class FirstTest {

 WebDriver driver;

 @Before
 public void setUp() throws MalformedURLException {
     // Created object of DesiredCapabilities class.
     DesiredCapabilities capabilities = new DesiredCapabilities();

     // Set android deviceName desired capability. Set your device name.
     capabilities.setCapability("deviceName", "XT1562");

     // Set BROWSER_NAME desired capability. It's Android in our case here.
     capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

     // Set android VERSION desired capability. Set your mobile device's OS version.
     capabilities.setCapability(CapabilityType.VERSION, "6.0.1");

     // Set android platformName desired capability. It's Android in our case here.
     capabilities.setCapability("platformName", "Android");

     // Set android appPackage desired capability. It is
     // com.android.calculator2 for calculator application.
     // Set your application's appPackage if you are using any other app.
     capabilities.setCapability("appPackage", "com.android.calculator2");

     // Set android appActivity desired capability. It is
     // com.android.calculator2.Calculator for calculator application.
     // Set your application's appPackage if you are using any other app.
     capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

     // Created object of RemoteWebDriver will all set capabilities.
     // Set appium server address and port number in URL string.
     // It will launch calculator app in android device.
     driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
     driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


 }


 @Test
 public void testFirstCalculator() {


     // Click on DELETE/CLR button to clear result text box before running test.
     driver.findElements(By.xpath("//android.widget.Button")).get(0).click();

     // Click on number 2 button.
     driver.findElement(By.name("7")).click();

     driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
 }

 @After
 public void End() {
     driver.quit();
 }
}
我使用:

  • io.appium java客户端v7.0。()
  • Selenium独立服务器v3.141.59()

运行我的应用程序后,我有错误列表:


  Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
我的build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

谢谢大家!

我认为您需要更新构建工具。试一试

classpath 'com.android.tools.build:gradle:3.0.0'

如果这不起作用,您可能需要修改android模块特定的build.gradle。

我认为您需要更新构建工具。试一试

classpath 'com.android.tools.build:gradle:3.0.0'

如果这不起作用,您可能需要处理特定于android模块的build.gradle。

那么,问题出在哪里?您是否在尝试运行代码时收到错误消息,如果是,您是否可以共享它?编辑:你能详细介绍一下“重建项目仍然找不到一些库”吗?什么图书馆?您是否可以分享错误消息?@C.Peck我已经完成了。你可以从我的应用程序中看到我的屏幕截图。你用什么来构建你的项目?如果是Gradle,你能分享你的Gradle.build文件吗?同样,如果您使用Maven上传pom.xml?@C.Peck have doneSo,有什么问题?您是否在尝试运行代码时收到错误消息,如果是,您是否可以共享它?编辑:你能详细介绍一下“重建项目仍然找不到一些库”吗?什么图书馆?您是否可以分享错误消息?@C.Peck我已经完成了。你可以从我的应用程序中看到我的屏幕截图。你用什么来构建你的项目?如果是Gradle,你能分享你的Gradle.build文件吗?同样,如果您使用Maven,请在尝试更改后上载pom.xml?@C.Peck have donea:
错误:找不到com.android.tools.build:gradle:3.0.0。在以下位置搜索:文件:/D:/Android Studio/gradle/m2repository/com/Android/tools/build/gradle/3.0.0/gradle-3.0.0.pom文件:/D:/Android Studio/gradle/m2repository/com/Android/tools/build/gradle/3.0.0.jarhttps://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom     https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar 所需者:project:
在尝试运行项目之前是否下载了gradle版本?尝试更改后:
错误:找不到com.android.tools。生成:gradle:3.0.0。在以下位置搜索:文件:/D:/Android Studio/gradle/m2repository/com/Android/tools/build/gradle/3.0.0/gradle-3.0.0.pom文件:/D:/Android Studio/gradle/m2repository/com/Android/tools/build/gradle/3.0.0.jarhttps://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom     https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar 所需人员:project:
在尝试运行项目之前,是否下载了gradle版本?