如何在功能中添加URL?

时间:2015-09-10 21:47:05

标签: appium remotewebdriver

我正在尝试从url引用apk但不成功。这是我正在尝试的 -

capabilities.setCapability("app", new URL("http://jenkinsserverurl:8181/job/projectname/apk/apkname.apk"));
.
.
.
driver = new RemoteWebDriver(new URL("http://remote test url:4723/wd/hub"),capabilities);

Appium server throws following error :-
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":{"userInfo":null,"query":null,"hCode":1439549959,"defaultPort":80,"path":"//.apk","protocol":"http","ref":null,"file":"//.apk","port":8181,"authority":":8181","host":"","class":"java.net.URL"},"appPackage":"","appActivity":".MainActivity","browserName":"","platformName":"Android","version":"4.4","deviceName":"emulator-5554","platform":"ANDROID"}}
error: Using local app, but didn't end in .zip, .ipa or .apk

建议???

2 个答案:

答案 0 :(得分:0)

试试这个:

File appDir = new File("/home/user/..."); //only path to apk file directory
File app = new File(appDir, "app.apk");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.packageName");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

<强>其中:

app

.ipa或.apk文件的绝对本地路径或远程http URL,或包含其中一个的.zip。 Appium将首先尝试在相应的设备上安装此应用程序二进制文件。请注意,如果您指定appPackage和appActivity功能,则Android不需要此功能。与browserName不兼容。

此外,如果您只想使用远程驱动程序,可以使用Android驱动程序进行投射 -

driver = (AndroidDriver) new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
            capabilities);

否则使用AndroidDriver。

答案 1 :(得分:0)

我认为错误是因为您没有使用“MobileCapabilityType”

从 url 安装 apk :

String url = "http://example.com/myapp.apk";  
 
cap.setCapability(MobileCapabilityType.APP, url);

从文件安装:

FileUtils.copyURLToFile(URL, File) //download file

File appDir = new File(userDir, fileName); //set file

capabilities.setCapability(MobileCapabilityType.APP, appDir.getAbsolutePath());