2015-05-29 57 views
1

我用SauceLabs example如何正確添加應用程序文件到appium Desired Capabilities?

DesiredCapabilities capabilities = new DesiredCapabilities(); 
    capabilities.setCapability("BROWSER_NAME", "Android"); 
    capabilities.setCapability("VERSION", "4.4.2"); 
    capabilities.setCapability("deviceName", "Android Emulator"); 
    capabilities.setCapability("platformName", "Android"); 

    //zip file containing your app to be tested 
    capabilities.setCapability("app", "http://appium.s3.amazonaws.com/TestApp6.0.app.zip"); 

    driver = new RemoteWebDriver 
    (new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", 
    sauceUserName, sauceAccessKey)), capabilities); 

這是完全正常工作。 但是當我下載的壓縮與應用程序和切換到當地的環境

capabilities.setCapability("app", app.getAbsolutePath());  
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); 

我從appium控制檯遇到錯誤:

error: Failed to start an Appium session, err was: Error: Bad app: /home/.../appium/assets/TestApp6.0.app.zip. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: App zip unzipped OK, but we couldn't find a .app bundle in it. Make sure your archive contains the .app package and nothing else

+0

請您顯示,其中可變的應用(從app.getAbsolutePath())被定義的代碼? – Eugene

+0

**請解壓縮.app文件,並提供完全限定的.app文件路徑到應用程序路徑功能。** – Rohith

回答

1

試試這個,而不是RemoteWebDriver:使用AndroidDriver。 此外,如果您從localhost運行提及IP地址或只輸入"localhost"

capabilities.setCapability("app", app.getAbsolutePath());  
driver = new AndroidDriver (new URL("http://localhost:4723/wd/hub"), capabilities); 

創建一個名爲"app"的文件夾,並將您的測試Android應用程序放置在那裏。

示例代碼:

File filePath = new File(System.getProperty("user.dir")); 
File appDir = new File(filePath, "/app"); 
File app = new File(appDir, "yourapkfile.apk"); 
0

您的應用程序和腳本需要在同一目錄下,或者你應該指定完整路徑到.apk文件以便它工作

0
File app= new File("‪D:\\com.boondoggle.mortcalc-1.apk"); 
DesiredCapabilities capabilities= new DesiredCapabilities(); 
capabilities.setCapability("deviceName", "Redmi Note 3"); 
capabilities.setCapability("platformName", "Android"); 
capabilities.setCapability("platformVersion", "6.0.1"); 
capabilities.setCapability("app", app.getAbsolutePath()); 
AndroidDriver driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
+0

請添加英文解釋代碼的作用。謝謝。 –

相關問題