Android 使用Appium测试我的应用程序

Android 使用Appium测试我的应用程序,android,webview,appium,Android,Webview,Appium,基本上,我正在尝试测试我的应用程序,它在android studio中使用WebView。我刚刚开始使用appium。我看了一些视频并设置了依赖项 这是我的格拉德尔 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.example.ac046137.my

基本上,我正在尝试测试我的应用程序,它在android studio中使用WebView。我刚刚开始使用appium。我看了一些视频并设置了依赖项

这是我的格拉德尔

         apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.ac046137.myappium"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions
        {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/LGPL2.1'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/notice.txt'
        }
}

 //apply plugin: 'java'

repositories {
mavenCentral()
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile files('libs/commons-logging-1.1.3.jar')
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/httpmime-4.4.1.jar')
compile files('libs/httpclient-4.4.1.jar')
compile files('libs/hamcrest-core-1.3.jar')
compile files('libs/hamcrest-library-1.3.jar')
compile files('libs/commons-collections-3.2.1.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/commons-exec-1.3.jar')
compile files('libs/gson-2.3.1.jar')
compile files('libs/apache-mime4j-0.6.jar')
compile files('libs/commons-codec-1.10.jar')
compile files('libs/java-client-3.2.0.jar')
compile files('libs/httpcore-4.4.1.jar')
compile files('libs/guava-18.0.jar')
compile files('libs/commons-validator-1.4.1.jar')
compile files('libs/junit-4.12.jar')
compile files('libs/selenium-java-2.47.1 (1).jar')
compile files('libs/selenium-java-2.47.1-srcs.jar')
 }
我还包括了所有的jar文件

这是我的测试脚本

   public class TestMe
 {

AppiumDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{


    //Set up desired capabilities and pass the Android app-activity and app-package to Appium
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("BROWSER_NAME", "");
    capabilities.setCapability("VERSION", "4.4.2");
    capabilities.setCapability("deviceName","MyTester");
    capabilities.setCapability("platformName","Android");


    capabilities.setCapability("appPackage", "com.example.schoolhealthprogram");
    // This package name of your app (you can get it from apk info app)
    capabilities.setCapability("appActivity","com.example.schoolhealthprogram.MainActivity"); // This is Launcher activity of your app (you can get it from apk info app)
    //Create RemoteWebDriver instance and connect to the Appium server
    //It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
    driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) {
        @Override
        public WebElement scrollTo(String s) {
            return null;
        }

        @Override
        public WebElement scrollToExact(String s) {
            return null;
        }
    };
}

@AfterClass
public void teardown(){
    //close the app
    driver.quit();
}

@Test
public void testme() throws Exception {
    // Switch to WebView
    Set<String> contextNames;
    contextNames = driver.getContextHandles();
    System.out.println(contextNames.size());
    for (String contextName : contextNames)
    {
        System.out.println(contextName);
        if (contextName.contains("WEBVIEW"))
        {
            driver.context(contextName);
        }
    }

    // check WELCOME text is present
    //  Assert.assertEquals("School Health Program", driver.findElement(By.id("welcome_text")).getText());

    // enter
    driver.findElementById("AWC_SchoolNo").sendKeys("123");
    driver.findElementById("AWC_SchoolName").sendKeys("St Johns");


    // /click on submit button
    //  driver.findElementById("LoadImage").click();

    //  driver.findElementByName("Choose File").click();

    //  driver.findElementByName("LoadImage").click();


}


}
公共类TestMe
{
AppiumDriver司机;
@课前
public void setUp()引发畸形的DurException{
//设置所需功能,并将Android应用程序活动和应用程序包传递给Appium
DesiredCapabilities=新的DesiredCapabilities();
setCapability(“浏览器名称”,“浏览器名称”);
能力。设置能力(“版本”,“4.4.2”);
能力。设置能力(“deviceName”、“MyTester”);
能力。设置能力(“平台名”、“安卓”);
setCapability(“appPackage”、“com.example.schoolhealthprogram”);
//此应用程序包名称(您可以从apk info应用程序获取)
capabilities.setCapability(“appActivity”、“com.example.schoolhealthprogram.MainActivity”);//这是应用程序的启动程序活动(您可以从apk info应用程序获取)
//创建RemoteWebDriver实例并连接到Appium服务器
//它将使用所需功能中指定的配置在Android设备中启动计算器应用程序
驱动程序=新的AppiumDriver(新的URL(“http://127.0.0.1:4723/wd/hub(技术、能力){
@凌驾
公共WebElement scrollTo(字符串s){
返回null;
}
@凌驾
公共Web元素scrollToExact(字符串s){
返回null;
}
};
}
@下课
公共无效拆卸(){
//关闭应用程序
driver.quit();
}
@试验
public void testme()引发异常{
//切换到WebView
设置上下文名称;
contextNames=driver.getContextHandles();
System.out.println(contextNames.size());
for(字符串contextName:contextName)
{
System.out.println(contextName);
if(contextName.contains(“WEBVIEW”))
{
驱动程序上下文(contextName);
}
}
//检查欢迎文本是否存在
//Assert.assertEquals(“学校健康计划”,driver.findElement(By.id(“欢迎文本”)).getText();
//进入
驱动程序。findElementById(“AWC_学号”)。发送键(“123”);
driver.findElementById(“AWC_学名”).sendKeys(“圣约翰”);
///点击提交按钮
//driver.findElementById(“LoadImage”)。单击();
//driver.findElementByName(“选择文件”)。单击();
//driver.findElementByName(“LoadImage”)。单击();
}
}

当测试脚本运行时,它不会打开我希望它打开的应用程序。logcat中没有错误。

您的appium服务器日志读取了什么?还假设,您粘贴的gradle文件来自应用程序代码,因为它没有“io.appium:java client:3.4.0”依赖关系。当我在设备中执行此代码时,我安装了appium设置应用程序,并且在运行它时崩溃。我确信我在配置时犯了一些错误,或者我可能没有使用所有依赖项。我将使用上述依赖项并再次运行它。谢谢您还要检查deviceName——它应该是设备id,如adb设备所示!!我希望应用程序构建足够稳定,可以进行测试