APP——自动化——java——程序后台运行,关闭、启动、是否安装第三方app、删除第三方app

package csgc;

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 ces 
{

    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);
        
        driver.runAppInBackground(2);        //只针对当前测试的app,后台运行2秒
        
        Thread.sleep(5000);
        
        
        driver.closeApp();   //只针对当前测试的app,关闭app
        
        
        Thread.sleep(5000);
        
        
        driver.launchApp();   //只针对当前测试的app,再次运行app
        
   
        Thread.sleep(5000);
        
        driver.closeApp();   //只针对当前测试的app,关闭app
        
        Thread.sleep(5000);
        
        System.out.println(driver.isAppInstalled("com.baidu.searchbox"));    //判断第三方app是否安装
        
        Thread.sleep(5000);
        
        
        driver.removeApp("com.baidu.searchbox");              //删除第三方app
        
        
        Thread.sleep(5000);
        
        System.out.println(driver.isAppInstalled("com.baidu.searchbox"));    //判断第三方app是否安装
        
        Thread.sleep(5000);
        

        driver.quit();
        
        

    }

}

 

 

执行结果:

 

true
false

 

上一篇:postgres 9.6.5 重建控制文件


下一篇:STM32W108无线射频模块通用IO接口应用实例