Appium Appium IOS 真机测试 iphone

testly · 2015年01月29日 · 1520 次阅读

@all

使用 APPIUM + java 操作真机报下面的错误!
错误详情:
错误:

配置

代码

package ios;

import static org.junit.Assert.*;
import io.appium.java_client.remote.MobileCapabilityType;

import java.io.File;
import java.net.URL;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class CASE {


    WebDriver driver;

    @Before
    public void setUp() throws Exception {
          // set up appium
//      File appDir = new File(System.getProperty("github/local/AppiumTest/sample-code/apps/TestApp/Products");

      DesiredCapabilities capabilities = new DesiredCapabilities();
     // capabilities.setCapability("device", "iPhone Simulator");
      //capabilities.setCapability(CapabilityType.BROWSER_NAME,"iOS");
      capabilities.setCapability(CapabilityType.VERSION,"7.1");
      capabilities.setCapability(CapabilityType.PLATFORM,"Mac");
      capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      capabilities.setCapability("deviceName", "pohoto");
      capabilities.setCapability("platformName", "ios");
      capabilities.setCapability(MobileCapabilityType.APP,"com.yiguo.YiGuoApp"); 
      driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"),capabilities);


}

    @Test
    public void example() throws Exception {

        // find an element by tag name
        WebElement button = driver.findElement(By.tagName("button"));
        button.click();

        // get the value of the element
        WebElement texts = driver.findElement(By.tagName("staticText"));
        assertEquals(texts.getText(), "some expected value");
    }
}


APPium 报错打印日志

Last login: Thu Jan 29 15:20:12 on ttys000
liyudeMac-mini:~ admin$ appium -U 728CD07EF9A84DFEB0C04CC20D02A68D3162CD8E --app com.yiguo.YiGuoApp
info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: [debug] Non-default server args: {"app":"com.yiguo.YiGuoApp","udid":"728CD07EF9A84DFEB0C04CC20D02A68D3162CD8E"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"io.appium.TestApp","platformVersion":"7.1","browserName":"","platformName":"iOS","deviceName":"iPhone Simulator"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] App is an iOS bundle, will attempt to run as pre-existing
info: [debug] Creating new appium session 9e25c17f-5e62-4cb6-9835-90c4f196fc4e
info: [debug] Removing any remaining instruments sockets
info: [debug] Cleaned up instruments socket /tmp/instruments_sock
info: [debug] Setting Xcode folder
info: [debug] Setting Xcode version
info: [debug] Setting iOS SDK Version
info: [debug] Getting sdk version from xcrun with a timeout
info: [debug] iOS SDK Version set to 8.1
info: [debug] Not checking whether simulator is available since we're on a real device
info: [debug] Detecting automation tracetemplate
info: [debug] Not auto-detecting udid, running on sim
info: [debug] Could not parse plist file (as binary) at /usr/local/lib/node_modules/appium/io.appium.TestApp/en.lproj/Localizable.strings
info: Will try to parse the plist file as XML
`parseFileSync()` is deprecated. Use `parseStringSync()` instead.
info: [debug] Could not parse plist file (as XML) at /usr/local/lib/node_modules/appium/io.appium.TestApp/en.lproj/Localizable.strings
warn: Could not parse app Localizable.strings; assuming it doesn't exist
info: [debug] Creating instruments
info: On some xcode 6 platforms, instruments-without-delay does not work. If you experience this, you will need to re-run appium with the --native-instruments-lib flag
info: [debug] Preparing uiauto bootstrap
info: [debug] Dynamic bootstrap dir: /Users/admin/Library/Application Support/appium/bootstrap
info: [debug] Dynamic env: {"nodePath":"/usr/local/Cellar/node/0.10.35_2/bin/node","commandProxyClientPath":"/usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js","instrumentsSock":"/tmp/instruments_sock","interKeyDelay":null,"justLoopInfinitely":false,"autoAcceptAlerts":false,"sendKeyStrategy":"grouped"}
info: [debug] Dynamic bootstrap code: // This file is automatically generated. D...ot manually modify!
info: [debug] Dynamic bootstrap path: /Users/admin/Library/Application Support/appium/bootstrap/bootstrap-c28cdf2cec4fb293.js
info: [debug] Reusing dynamic bootstrap: /Users/admin/Library/Application Support/appium/bootstrap/bootstrap-c28cdf2cec4fb293.js
info: [debug] Getting device string from opts: {"forceIphone":false,"forceIpad":false,"xcodeVersion":"6.1","iOSSDKVersion":"8.1","deviceName":"iPhone Simulator","platformVersion":"7.1"}
info: [debug] fixDevice is on
info: [debug] Fixing device. Changed from: "iPhone Simulator (7.1 Simulator)" to: "iPhone 5s (7.1 Simulator)"
info: [debug] Final device string is: 'iPhone 5s (7.1 Simulator)'
info: [debug] Not setting device type since we're on a real device
info: [debug] Checking whether we need to set app preferences
info: [debug] Not setting iOS and app preferences since we're on a real device
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killall iOS Simulator
info: [debug] Killing any other simulator daemons
info: [debug] On a real device; cannot clean device state
info: [debug] Not setting locale because we're using a real device
info: [debug] No iOS / app preferences to set
info: [debug] Starting iOS device log capture via deviceconsole
error: Log capture did not start in a reasonable amount of time
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Log capture did not start in a reasonable amount of time
info: [debug] Error: Log capture did not start in a reasonable amount of time
    at null._onTimeout (/usr/local/lib/node_modules/appium/lib/devices/ios/ios-log.js:137:10)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Log capture did not start in a reasonable amount of time)","origValue":"Log capture did not start in a reasonable amount of time"},"sessionId":null}
info: <-- POST /wd/hub/session 500 10228.916 ms - 234 
info: [debug] Not pre-launching simulator
info: [debug] Creating iDevice object with udid 728CD07EF9A84DFEB0C04CC20D02A68D3162CD8E
info: [debug] Couldn't find ideviceinstaller, trying built-in at /usr/local/lib/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller
info: [debug] Checking app install status using: /usr/local/lib/node_modules/appium/build/fruitstrap/fruitstrap isInstalled --id 728CD07EF9A84DFEB0C04CC20D02A68D3162CD8E --bundle io.appium.TestApp


解决方案:
1,启动 Appium 加上设备 UDID 和 BUID
2,启动真机代码内的配置内容:

public void setUp() throws Exception {
    // set up appium
        DesiredCapabilities capabilities = new DesiredCapabilities();
        //capabilities.setCapability(CapabilityType.BROWSER_NAME, "ios");
        capabilities.setCapability(CapabilityType.VERSION, "7.1");
        capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
        //capabilities.setCapability("device", "iPhone Simulator");
        //capabilities.setCapability("app", "safai");
        capabilities.setCapability("deviceName", "pohoto");//pohoto
          capabilities.setCapability("platformName", "ios");
        driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

3,这样就可以启动我们真机上的 app 了

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 29 条回复 时间 点赞

截图不看。

@testly 贴代码,不要贴图片。

提问的艺术。~
在这需要初步的问题定位。
你贴一串找人给你定位,谁有空看啊。~还是心情不好的时候。。。。

#5 楼 @lucasluo 抱歉我马上改

#6 楼 @yangchengtest 抱歉实在抱歉

@testly 我不是说我哦~不用和我抱歉了哈。
我是说你 @ 恒温~提个建议罢了。~我还没碰过 IOS 的说。。。

上面错误提示已经很明显了,如果不懂得怎么设置,去官网看看。

还可以在论坛搜搜,恒温早就写过教程。

testly #10 · 2015年01月30日 Author

#12 楼 @beerbox 搜过呢、很少有这个问题的资料

#13 楼 @testly Couldn't find ideviceinstaller, trying built-in at /usr/local/lib/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller 先把这个问题解决。

testly #16 · 2015年01月30日 Author

#14 楼 @lihuazhang 多谢我已经解决了

#15 楼 @testly 怎么解决的?

testly #18 · 2015年01月30日 Author

#16 楼 @lihuazhang 删了几个配置就 OK 了代码里面,然后 appium 后面指定设备和包

#17 楼 @testly 解决问题后记得附上答案, 互相帮助. 这是社区倡导的理念

testly #14 · 2015年01月30日 Author

#18 楼 @seveniruby 好的!

你这个问题是怎么解决的?

testly #22 · 2015年06月02日 Author

#20 楼 @fengytn 下面有解决方案

#21 楼 @testly 奥,那我应该有其它的地方不对,我按你下面那个解决方案还是报错,我再研究下吧,谢谢哈

testly #24 · 2015年06月02日 Author

#22 楼 @fengytn 如果没搞定可以发帖子,我帮你看看!

#23 楼 @testly 能加 QQ 么?主要是 imac 机我以前没用过,我都不知道我配置得对不对.我的 QQ 184210176

appium 1.3.7
@testly 我的也是这个错误,请问你怎么解决的
info: <-- GET /wd/hub/status 200 1.319 ms - 178 {"status":0,"value":{"build":{"version":"1.3.7","revision":"72fbfaa116d3d9f6a862600ee99cf02f6d0e2182"},"isShuttingDown":false},"sessionId":"5e6c2df1-01c0-4041-86d6-a6fd98324b42"}

error: Log capture did not start in a reasonable amount of time

info: [debug] Cleaning up appium session

error: Failed to start an Appium session, err was: Error: Log capture did not start in a reasonable amount of time

info: [debug] Error: Log capture did not start in a reasonable amount of time
at null._onTimeout (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-log.js:137:10)
at Timer.listOnTimeout (timers.js:110:15)

error: Failed to start an Appium session, err was: Error: Log capture did not start in a reasonable amount of time
info: [debug] Error: Log capture did not start in a reasonable amount of time

iOS 遇到这个 error,先检查下 UDID 是不是大写了,大写要改成小写。

testly #20 · 2015年06月09日 Author

#25 楼 @kaixinguo 退到 1.3.4

您好,这个 ios 用 appium 工具,我也是想用 java 写,但是我搭建好环境后,就不知道怎么做了,能提供下流程吗?windows 下 appium 测安卓的搞定了。这个 ios 有点摸不着头脑。

匿名 #29 · 2017年05月23日
恒温 回复

你好,请问下 IOS appium 自动化,用 driver.backgroud_app()将应用退到后台出现,Error Domain=com.facebook.WebDriverAgent Code=1 \"Timeout waiting for application to activate
这个错误有什么解决办法吗?百度没有搜索到相关的,有踩过坑的没?

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