[マック+ Appium + Java1.8ラーニング(II)]のAndroidエミュレータ自動テストスクリプトの開発と簡単な例の

直接コードに:

輸入io.appium.java_client.AppiumDriver;
輸入org.junit.After;
輸入org.junit.Before;
輸入org.junit.Test;
輸入org.openqa.selenium.WebElement;
輸入org.openqa.selenium.remote.DesiredCapabilities。

輸入java.net.MalformedURLException;
インポートのjava.net.URL; 

インポート 静的java.lang.Thread.sleepを。


パブリック クラスTestXueqiuDemo {
     プライベート AppiumDriver <WebElement> ドライバー。

    @Before 
    公共 ボイドセットアップ()スローでMalformedURLExceptionを{
        // 設定appiumの 
        DesiredCapabilities能力= 新しいDesiredCapabilities(); 
        capabilities.setCapability( "platformName"、 "アンドロイド" ); 
        capabilities.setCapability( "DEVICENAME"、 "192.168.56.101:5555" ); 
        capabilities.setCapability( "appPackage"、 "com.xueqiu.android" ); 
        capabilities.setCapability( "appActivity"、 "view.WelcomeActivityAlias。" ); 

        ドライバ = 新しい AppiumDriver <WebElement>( URL( "http://127.0.0.1:4723/wd/hub" )、能力);

     ボイドティアダウン()はスロー例外{
 //         )(driver.quitします。
        System.out.println( "测试结束!" ); 
    } 

    @Test 
    公共 ボイド testDemo01()スロー例外{ 
        driver.findElementById( "com.xueqiu.android:id/open" ).clickを();
        int型私= 0 ;
        以下のために(私は= 0; iは<2; I ++ ){ 
            driver.findElementById( "com.android.packageinstaller:ID / permission_allow_button" ).click(); 
        } 
//        driver.findElementById( "com.android.packageinstaller:ID / permission_allow_button")。()をクリックします。
        スリープ(5000 );
//       隐式等待
 //         。driver.manage()タイムアウト()implicitlyWait(10、TimeUnit.SECONDS)。
        System.out.println( "暂停10S" ); 
        driver.findElementById( "com.xueqiu.android:id/agree" ).click(); 
        driver.findElementById( "com.android.packageinstaller:ID / permission_allow_button" ).click(); 
        スリープ( 2000 ); 
        driver.findElementByXPath( "// * [テキスト@ = '自选']" ).click(); 
    } 

}

 

おすすめ

転載: www.cnblogs.com/Owen-ET/p/10021353.html