天天看點

Appium IOS 真機測試 iphone

使用APPIUM + java 操作真機報下面的錯誤!

錯誤詳情:

錯誤:

Appium IOS 真機測試 iphone

配置

Appium IOS 真機測試 iphone

代碼

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了

繼續閱讀