无法执行Appium脚本

时间:2018-02-08 17:34:02

标签: appium

我写了一个简单的脚本,它在Android N(7.0)上启动了一个chrome应用程序,但无法运行,收到错误

详情环境

Appium version (or git revision) that exhibits the issue: 1.4.16.1
Last Appium version that did not exhibit the issue (if applicable): N/A
Desktop OS/version used to run Appium: window 7/32 bit
Node.js version (unless using Appium.app|exe): node-v8.9.4-x86
Mobile platform/version under test: chrome browser /64.0.3282.123
Real device or emulator/simulator:Android 7.0.0:MotoG(4)/Build/NPJS25.93-14-10
Appium CLI or Appium.app|exe: Appium Desktop exe

错误日志

  

info:[debug]响应客户并出现错误:{" status":33," value":{" message":" A无法创建新会话。 (原始错误:命令失败:C:\ Windows \ system32 \ cmd.exe / s / c" D:\ android-sdk \ platform-tools \ adb.exe -s ZY2239HZB2安装" C:\程序文件(x86)\ Appium \ node_modules \ appium \ build \ unlock_apk \ unlock_apk-debug.apk"" \ nadb:无法安装C:\ Program Files(x86)\ Appium \ node_modules \ appium \ build \ unlock_apk \ unlock_apk-debug.apk:失败[INSTALL_FAILED_ALREADY_EXISTS:尝试在没先卸载的情况下重新安装io.appium.unlock。] \ r \ n)"," kill":false,& #34;代码":1,"信号":null," cmd":" C:\ Windows \ system32 \ cmd.exe / s / c&# 34; D:\ android-sdk \ platform-tools \ adb.exe -s ZY2239HZB2安装" C:\ Program Files(x86)\ Appium \ node_modules \ appium \ build \ unlock_apk \ unlock_apk-debug.apk&#34 ;""," origValue":"命令失败:C:\ Windows \ system32 \ cmd.exe / s / c" D:\ android-sdk \ platform-tools \ adb.exe -s ZY2239HZB2安装" C:\ Program Files(x86)\ Appium \ node_modules \ appium \ build \ unlock_apk \ unlock_apk-debug.apk"" \ nad b:无法安装C:\ Program Files(x86)\ Appium \ node_modules \ appium \ build \ unlock_apk \ unlock_apk-debug.apk:失败[INSTALL_FAILED_ALREADY_EXISTS:尝试在未先卸载的情况下重新安装io.appium.unlock。] \ r \ N'#34;}"的sessionId":空}

代码:

import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
//import org.testng.annotations.Test;

public class StartChrome
{

public static void main(String[] args) throws MalformedURLException{

DesiredCapabilities cd=DesiredCapabilities.android();

cd.setCapability(MobileCapabilityType.BROWSER_NAME,BrowserType.CHROME);

cd.setCapability(MobileCapabilityType.PLATFORM,Platform.ANDROID);

// we need to define platform name
cd.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");

// Set the device name as well (you can give any name)
cd.setCapability(MobileCapabilityType.DEVICE_NAME,"my phone");

// set the android version as well
cd.setCapability(MobileCapabilityType.VERSION,"7.0");

// Create object of URL class and specify the appium server address
URL url= new URL("http://127.0.0.1:4723/wd/hub");

// Create object of AndroidDriver class and pass the url and capability that we created
WebDriver driver = new AndroidDriver(url, cd);

// Open url
driver.get("http://www.facebook.com");

// print the title
System.out.println("Title "+driver.getTitle());

// enter username
driver.findElement(By.name("email")).sendKeys("sni****@gmail.com");

// enter password
driver.findElement(By.name("pass")).sendKeys("*****8");

// click on submit button
driver.findElement(By.id("u_0_5")).click();

// close the browser
driver.quit();

1 个答案:

答案 0 :(得分:1)

请更新您的Appium版本,因为它已经很老了,您已经看到了已在1.6.0(2016年10月发布)中解决的Android 7.0的已知问题。

如果无法执行此操作,请在运行脚本之前运行以下命令:

adb -s device_serial uninstall io.appium.settings  
adb -s device_serial uninstall io.appium.unlock 
相关问题