使用Appium测试我的应用程序

时间:2016-03-09 06:34:38

标签: android webview appium

基本上,我正在尝试测试在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();


}


}

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

0 个答案:

没有答案