APP——自动化——java——程序安装好,直接调用

Posted 小白龙白龙马

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了APP——自动化——java——程序安装好,直接调用相关的知识,希望对你有一定的参考价值。

package jkcs;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
public class jblx 
{
    public static void main(String[] args) throws MalformedURLException, InterruptedException 
    {
        DesiredCapabilities capabilities = new DesiredCapabilities();  

        capabilities.setCapability("platformName", "android");  
        capabilities.setCapability("deviceName","8DF6R17503000072");  
        capabilities.setCapability("platformVersion", "8.0.0"); 
        
        capabilities.setCapability("unicodeKeyboard","True");
        capabilities.setCapability("resetKeyboard","True");
        
        capabilities.setCapability("autoGrantPermissions", "True");  
        
     //   capabilities.setCapability("app", "C:\Users\del\Desktop\b\jsq.apk");  
        
        capabilities.setCapability("appPackage", "com.youba.calculate");  
        capabilities.setCapability("appActivity", "com.youba.calculate.MainActivity");  
        
        
        
        
        AppiumDriver driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        
        
        driver.manage().timeouts().implicitlyWait(500, TimeUnit.SECONDS);
        
        
        Thread.sleep(5000);
        
        System.out.println(driver.currentActivity());
        
        Thread.sleep(5000);
              
        System.out.println(driver.getCapabilities());
        
        Thread.sleep(5000);
        
        
        driver.findElementById("com.youba.calculate:id/btn_one").click(); 
                
        Thread.sleep(5000);
            
        driver.findElementById("com.youba.calculate:id/btn_plus").click(); 
                
        Thread.sleep(5000);
                
        driver.findElementById("com.youba.calculate:id/btn_two").click(); 
                
        Thread.sleep(5000);
        
        driver.findElementById("com.youba.calculate:id/btn_equal").click(); 
                
        Thread.sleep(5000);
                
        System.out.println(driver.findElementById("com.youba.calculate:id/tv_display").getText());
        
        
        
        
        
   
        Thread.sleep(5000);

        driver.quit();
    }
}

 

 

 

 

 

执行结果:

 

 

.MainActivity

 


Capabilities [{appPackage=com.youba.calculate, statBarHeight=84, viewportRect={top=84, left=0, width=1440, height=2344}, deviceName=8DF6R17503000072, platform=LINUX, deviceUDID=8DF6R17503000072, desired={appPackage=com.youba.calculate, appActivity=com.youba.calculate.MainActivity, platformVersion=8.0.0, autoGrantPermissions=true, unicodeKeyboard=true, platformName=Android, deviceName=8DF6R17503000072, resetKeyboard=true}, platformVersion=8.0.0, webStorageEnabled=false, takesScreenshot=true, javascriptEnabled=true, unicodeKeyboard=true, platformName=Android, deviceApiLevel=26, deviceManufacturer=HUAWEI, resetKeyboard=true, deviceScreenSize=1440x2560, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, appActivity=com.youba.calculate.MainActivity, pixelRatio=3.5, locationContextEnabled=false, autoGrantPermissions=true, deviceScreenDensity=560, deviceModel=EDI-AL10}]

 


3

 

以上是关于APP——自动化——java——程序安装好,直接调用的主要内容,如果未能解决你的问题,请参考以下文章

Android通过Apk插件调起微信支付

如何在安卓手机里运行JAVA程序?

appium---代码自动安装app

APP——java——自动化环境搭建01——个人详细搭建——真机模拟

mqtt实现自动监听服务器消息

求个电脑安卓模拟器4.4的。最好是安装好的直接解压能用的,谢谢