新手区 #AppiumDriver 升级版本引发的问题,刚刚学习 java+appium

Amber · 2017年03月29日 · 最后由 zhangshan 回复于 2018年05月09日 · 2331 次阅读

把代码修改如下,使用AndroidDriver而非原来的AppiumDriver
参考修改的文章:http://blog.csdn.net/zhubaitian/article/details/39717889
修改以后还是有错误,麻烦大家帮忙看一下代码,谢谢各位

public class MyClass {
private AndroidDriver driver;
@Before
public void setUp() throws Exception {
//设置apk的路径
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps");
File app = new File(appDir, "ContactManager.apk");
//设置自动化相关参数
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android");
//设置安卓系统版本
//capabilities.setCapability("platformVersion", "4.3");
//设置apk路径
//capabilities.setCapability("app", app.getAbsolutePath());
//设置app的主包名和主类名
capabilities.setCapability("appPackage", "com.example.android.ContactManager");
capabilities.setCapability("appActivity", ".ContactManager");
//初始化
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub,capabilities"));
}
@Test
public void addContact(){
WebElement el =driver.findElement(By.name("Add Contact"));
el.click();
List textFieldsList =driver.findElementsByName("android");
textFieldsList.get(0).sendKeys("Some Name");
textFieldsList.get(2).sendKeys("Some@example.com");
driver.swipe(100, 500, 100, 100, 2);
driver.findElementByName("Save").click();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
共收到 9 条回复 时间 点赞

不知道这个格式对不对了,不过这个格式比我第一次发的好看了😂

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub,capabilities")); 明显错了

小胖。 回复

不好意思哈,那个代码本身是我自己粘贴错误了,我的代码是
//初始化
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

贴错误日志

> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: D:\Android\platform-tools\adb.exe -s emulator-5554 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> warn: UiAutomator did not shut down fast enough, calling it gone
> error: Failed to start an Appium session, err was: Error: Command failed: Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
> 
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Error: Command failed: Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
> 
>     at ChildProcess.exithandler (child_process.js:637:15)
>     at ChildProcess.EventEmitter.emit (events.js:98:17)
>     at maybeClose (child_process.js:743:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: Failed to install C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"origValue":"Command failed: Failed to install C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n"},"sessionId":null}

安装这个包的时候失败了

@hxbjava @shixue33 谢谢!!!

Amber 回复

😃 有问题,多看看错误日志

Amber 回复

你好,这个问题最后解决了吗

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册