How to include selenium library in the android project?

问题: I try to create my first autotest for my android application. I've found a useful video and do the same step by step, but after including librarys and rebuilding the projec...

问题:

I try to create my first autotest for my android application. I've found a useful video and do the same step by step, but after including librarys and rebuilding the projeck still cannot find some libs:

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

My code:

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

I use:

  • io.appium java-client v7.0. (link)
  • Selenium Standalone Server v3.141.59 (link)

pick from my app

After running my app I have error list:


  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

My build.gradle file:

// 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
}

Thank you!


回答1:

I think you need to update your build tools. Try

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

If this does not work you may need to mess with an android-module-specific build.gradle.

  • 发表于 2019-02-26 00:52
  • 阅读 ( 259 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除