首页 文章

无法执行Appium脚本

提问于
浏览
0

我编写了简单的脚本,它在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”:“无法创建新会话 . (原始错误:命令失败:C:\ Windows \ system32 \ cmd.exe / s / c“D:\ android-sdk \ platform-tools \ adb.exe -s ZY2239HZB2 install”C:\ Program Files(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,”code“:1,”signal“:null,”cmd“:”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”“”,“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-d ebug.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“},”sessionId“:null}

码:

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 回答

  • 1

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

    如果无法做到这一点,请在运行脚本之前运行以下命令:

    adb -s device_serial uninstall io.appium.settings  
    adb -s device_serial uninstall io.appium.unlock
    

相关问题