2016-07-18 66 views
3

前提條件:已經通過谷歌播放安裝在設備中的應用程序。如何使用appium處理已安裝的應用程序?

當我試圖自動化設備中已安裝的應用程序時,每次打開google瀏覽器而不是打開應用程序。

任何人都可以讓我知道如何打開應用程序,我是一個新的appium。

下面是代碼:

public class appium { 
private static AndroidDriver driver; 
    public static void main(String[] args) throws InterruptedException, IOException { 

     File appDir = new File("D:/setup/android-sdk_r24.4.1-windows/android-sdk-windows"); 
     File app = new File(appDir, "ab.java.programming-1.apk"); 
     System.out.println("app Dir.--->"+app);  

     DesiredCapabilities capabilities = new DesiredCapabilities(); 

     // Name of mobile web browser to automate. It should be an empty string, as we are automation an app 
     capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); 
     // Name of the OS: Android, iOS or FirefoxOS 
     capabilities.setCapability("platformName", "Android"); 
     // Device name: – I am using Galaxy 
     capabilities.setCapability("deviceName", "Galaxy"); 
     // Mobile OS version – My device is running Android 4.4.4 
     capabilities.setCapability("platformVersion", "4.4.4"); 
     // An absolute local path to the APK file 
     //capabilities.setCapability("app", app.getCanonicalPath()); 

     // Java package of the tested Android app 
     capabilities.setCapability("appPackage", "ab.java.programming"); 

     // An activity name for the Android activity you want to run from your package. 
     capabilities.setCapability("appActivity", ".MainActivity"); 

//  Constructor to initialize driver object with new Url and Capabilities 
     driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 

     driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); 
     Thread.sleep(10000); 
     driver.quit(); 

    } 

    } 

回答

0

您需要設置指向哪個或在APK是能力。

capabilities.setCapability("app", app.getAbsolutePath()); 

而且一定要在CHECK窗口appium的NO RESET選項,以便它不會重新安裝APK。

編輯:

這是我如何運行位於我的桌面的應用程序。

 File app = new File("app location which is in the desktop"); //install 
     DesiredCapabilities capabilities = new DesiredCapabilities(); 

     capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); 
     capabilities.setCapability("deviceName", "LenovoB6000-HV"); 
     capabilities.setCapability("platformVersion", "5.0.2"); 
     capabilities.setCapability("platformName", "Android"); 
     capabilities.setCapability("app", app.getAbsolutePath()); 
     capabilities.setCapability("appPackage", "package name"); 
     capabilities.setCapability("appActivity", "Activity name"); 
     driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
     Thread.sleep(10000);//wait before closing the app 
      driver.quit(); 
+0

我已經安裝了從谷歌.apk文件播放和保存在SD卡,還有你說我曾創下「getAbsolutePath()」的能力,並檢查從appium窗口中的「不得安寧」選項。但是,無論何時我首先運行該項目,它都會安裝一個構建名稱「解鎖」,然後打開Chrome瀏覽器。但我需要做的是「打開已安裝在設備中的應用程序」。 – SelenyanC2

+0

等待它完成。解鎖是appium在您的設備上運行的必要條件。由於沒有新的命令,您是否等待appium日誌關閉? – Daniel

+0

是的,在appium窗口上完成執行後,它也會生成日誌。另外,完成後退出驅動程序。但申請不開放。 – SelenyanC2

相關問題