Android Studio+Appium+TestNG数据驱动框架搭建

Eclipse+Appium+TestNG项目迁移到Android Studio

1,文件迁移

Eclipse中完整的Maven Project数据驱动框架结构:

Android Studio+Appium+TestNG数据驱动框架搭建_第1张图片Android Studio+Appium+TestNG数据驱动框架搭建_第2张图片

  • 在Android Studio中建立Project后,新建同名的Module,这里Eclipse的Project名是appiumcombat,因此,Android Studio中Module名称也为appiumcombat。(Android Studio和Eclipse目录结构差异请自行了解)。
  • 将Eclipse下的文件逐一复制到Android Studio的Module下方,复制过程中对应关系需要修改的检查一下。复制好之后目录结构如下:
Android Studio+Appium+TestNG数据驱动框架搭建_第3张图片

2, maven -->gradle(pom.xml文件转换成build.gradle文件)

参考:http://www.cnblogs.com/softidea/p/5631341.html

将Eclipse中的pom.xml中的配置内容转换到build.gradle文件中。

方法:

下载gradle 2.0并安装,配置环境变量(类似JDK环境变量的配置)

然后在maven根目录下运行

gradle init --type pom

Android Studio+Appium+TestNG数据驱动框架搭建_第4张图片

打开生成的build.gradle文件,查看里面的dependencies内容,已经转换成Android Studio可用的依赖配置。可以直接复制需要的部分到Android Studio中的build.gradle文件中。

以下是转换后整理修改好的build.gradle代码:(sync之后就会自动下载依赖的jar包

apply plugin: 'java'
apply plugin: 'eclipse'
version = '1.0'

jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
    }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

test {
    useTestNG()
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile group: 'commons-configuration', name: 'commons-configuration', version:'1.9'
    compile(group: 'io.appium', name: 'java-client', version:'3.4.1') {
        exclude(module: 'selenium-java')
    }
    compile group: 'com.google.code.gson', name: 'gson', version:'2.2.4'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:'2.53.0'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version:'3.10-FINAL'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version:'2.53.0'
    compile group: 'com.thoughtworks.qdox', name: 'qdox', version:'1.12.1'
    testCompile group: 'org.testng', name: 'testng', version:'6.9.6'
    testCompile group: 'com.googlecode.json-simple', name: 'json-simple', version:'1.1'
    testCompile group: 'commons-lang', name: 'commons-lang', version:'2.6'
    testCompile group: 'com.saucelabs', name: 'sauce_junit', version:'2.1.21'
    compile(group: 'net.sourceforge.jexcelapi', name: 'jxl', version:'2.6.12') {
        /* This dependency was originally in the Maven provided scope, but the project was not of type war.
        This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
        Please review and delete this closure when resolved. */
    }
    compile(group: 'log4j', name: 'log4j', version:'1.2.16') {
        /* This dependency was originally in the Maven provided scope, but the project was not of type war.
        This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
        Please review and delete this closure when resolved. */
    }
}

3,运行testng测试

这时,可能会报很多Gradle: 错误: 编码GBK的不可映射字符

解决方法:

修改File--setting中的默认编码为UTF-8,Apply后重启Android Studio,并且在gradle配置文件中添加如下内容。亲测有效:

Android Studio+Appium+TestNG数据驱动框架搭建_第5张图片

Android Studio+Appium+TestNG数据驱动框架搭建_第6张图片

参考:https://www.douban.com/note/507175402/

4,数据驱动问题

本来这个用例是通过读取data文件夹里的excel文件数据来传递测试参数,但是运行一直提示Test ignored,找不到原因,后来删除dataProvider相关的代码后,运行,即可测试通过。数据驱动的问题仍在摸索中。

Android Studio+Appium+TestNG数据驱动框架搭建_第7张图片

你可能感兴趣的:(Appium)