appium在真机上运行IOS实例要注意的几点:包括python和java运行log 和部分关键代码
2016-03-21 12:17
781 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。
最近在研究appium对于IOS的自动化测试,发现在真机上运行appium提供的开源的例子遇到了几个block,询问了一个这个方便面的高手并且总结网上搜到的帖子,现在综合一下。
appium 在模拟器中跑,只需要注意:
1:app=path找到编译后app所在的位置,如:注意Release-iphonesimulator这个是模拟器编译后的文件夹
final File appDir = new File(System.getProperty("user.dir"),
"../../../apps/TestApp/build/Release-iphonesimulator");
final File app = new File(appDir, "TestApp.app");
capabilities.setCapability("app", app.getAbsolutePath());
appium真机上运行:
1:运行的时候要将APP安装到真机上面
2:运行的时候,不能再开instrument
3:命令行里面启动的时候,参数写错了应该是 appium -U 3d2cad7288a64a5445aa98a2cc220132f2cddd1c --app io.appium 然后代码里面 app=bundleID,如以下例子中: capabilities.setCapability("app", "io.appium.TestApp");而不是那个很长的路径,其中-U 参数后面是真机的uuid,可以打开xcode,在windows下的organise下找到,一般mac连接上ipad后会有绿色圆点
现在贴上真机上运行python实例:
Device的UDID和你的应用的Bundle ID正确
2.确保你的应用可以安装到你的真机上
3.安装后请断开与Xcode的连接
4.确保Mac上没有启动Instruments工具
以下是JAVA真机运行log:
devexus-iMac:build devexu$ appium -U 3d2cad7288a64a5445aa98a2cc220132f2cddd1c --app io.appium
info: Welcome to Appium v1.1.0 (REV e433bbc31511f199287db7724e1ce692bcb32117)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: socket.io started
info: Non-default server args: {"app":"io.appium","udid":"3d2cad7288a64a5445aa98a2cc220132f2cddd1c"}
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"platformVersion":"7.1","app":"io.appium.TestApp","platformName":"iOS","deviceName":"iPhone Simulator","browserName":""}}
info: App is an iOS bundle, will attempt to run as pre-existing
info: Creating new appium session 2bcd619b-b7fb-45f5-b20c-79caff8cd24f
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock
info: Cleaning up any tracedirs
info: No tracedirs to clean up
info: Setting Xcode folder
info: Setting Xcode version
info: Setting iOS SDK Version
info: iOS SDK Version set to 7.1
info: Detecting automation tracetemplate
info: Not auto-detecting udid, running on sim
info: Localizable.strings is not currently supported when using real devices.
info: Not setting locale because we're using a real device
debug: Creating instruments
info: Not setting iOS and app preferences since we're on a real device
info: Starting iOS device log capture via idevicesyslog
info: Not setting device type since we're connected to a device
debug: Real device specified but no ipa or app path, assuming bundle ID is on device
debug: Starting instruments
info: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Attempting to run app on real device with UDID 3d2cad7288a64a5445aa98a2cc220132f2cddd1c
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
-w 3d2cad7288a64a5445aa98a2cc220132f2cddd1c io.appium.TestApp -e UIASCRIPT /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments
info: And extra without-delay env: {}
info: And launch timeouts (in ms): {"global":90000}
info: [INST] 2014-07-02 01:29:30 +0000 Start: Bootstrapping uiauto
info: [INST] 2014-07-02 01:29:32 +0000 Start: Got user: devexu
info: [INST] 2014-07-02 01:29:33 +0000 Start: Not using settings file.
info: [INST] 2014-07-02 01:29:33 +0000 Start: isVerbose:false
info: [INST] 2014-07-02 01:29:37 +0000 Start: Using node at: /usr/local/bin/node
info: [INSTSERVER] Instruments is ready to receive commands
info: Instruments launched. Starting poll loop for new commands.
info: Setting bootstrap config keys/values
info: Pushing command to appium work queue: "setBootstrapConfig: autoAcceptAlerts=false"
debug: Sending command to instruments: setBootstrapConfig: autoAcceptAlerts=false
info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: setBootstrapConfig: autoAcceptAlerts=false
info: [INSTSERVER] Socket data received (48 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":""}
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INST] 2014-07-02 01:29:41 +0000 Debug: target.setDeviceOrientation("1")
info: [INSTSERVER] Socket data received (56 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Device launched! Ready for commands
info: Setting command timeout to the default of 60 secs
info: Appium session started with sessionId 2bcd619b-b7fb-45f5-b20c-79caff8cd24f
POST /wd/hub/session 303 22483ms - 9b
debug: Appium request initiated at /wd/hub/session/2bcd619b-b7fb-45f5-b20c-79caff8cd24f
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"warnings":{},"desired":{"platformVersion":"7.1","app":"io.appium.TestApp","platformName":"iOS","deviceName":"iPhone
Simulator","browserName":""},"platformVersion":"7.1","app":"io.appium.TestApp","platformName":"iOS","deviceName":"iPhone Simulator"},"sessionId":"2bcd619b-b7fb-45f5-b20c-79caff8cd24f"}
..........
java真机运行的代码:
package com.saucelabs.appium;
import static org.junit.Assert.assertTrue;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* Simple <a href="https://github.com/appium/appium">Appium</a> test which runs
* against a local Appium instance deployed with the 'TestApp' iPhone project
* which is included in the Appium source distribution.
*
* @author Ross Rowe
*/
public class WiMyOffice {
private AppiumDriver driver;
private List<Integer> values;
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
private Point getCenter(final WebElement element) {
final Point upperLeft = element.getLocation();
final Dimension dimensions = element.getSize();
return new Point(upperLeft.getX() + dimensions.getWidth() / 2,
upperLeft.getY() + dimensions.getHeight() / 2);
}
private void populate() {
// populate text fields with two random number
final List<WebElement> elems = driver.findElements(By
.className("UIATextField"));
final Random random = new Random();
for (final WebElement elem : elems) {
final int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
elem.sendKeys(String.valueOf(rndNum));
values.add(rndNum);
}
}
@Before
public void setUp() throws Exception {
// set up appium
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("app", "io.appium.TestApp");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
values = new ArrayList<Integer>();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void testHideKeyboard() throws Exception {
driver.findElement(By.xpath("//UIATextField[1]")).sendKeys("12");
final WebElement button = driver.findElement(MobileBy
.AccessibilityId("Done"));
assertTrue(button.isDisplayed());
button.click();
}
}
java上在模拟器上跑的实例:
命令行输入:appium &启动服务就可以了
lsof -i:4723查看端口号有没有被占用,占用就用 kill -9 进程ID
代码:
package com.saucelabs.appium;
import static org.junit.Assert.assertTrue;
import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* Simple <a href="https://github.com/appium/appium">Appium</a> test which runs
* against a local Appium instance deployed with the 'TestApp' iPhone project
* which is included in the Appium source distribution.
*
* @author Ross Rowe
*/
public class SimpleTest {
private AppiumDriver driver;
private List<Integer> values;
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
private Point getCenter(final WebElement element) {
final Point upperLeft = element.getLocation();
final Dimension dimensions = element.getSize();
return new Point(upperLeft.getX() + dimensions.getWidth() / 2,
upperLeft.getY() + dimensions.getHeight() / 2);
}
private void populate() {
// populate text fields with two random number
final List<WebElement> elems = driver.findElements(By
.className("UIATextField"));
final Random random = new Random();
for (final WebElement elem : elems) {
final int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
elem.sendKeys(String.valueOf(rndNum));
values.add(rndNum);
}
}
@Before
public void setUp() throws Exception {
// set up appium
final File appDir = new File(System.getProperty("user.dir"),
"../../../apps/TestApp/build/Release-iphonesimulator");
final File app = new File(appDir, "TestApp.app");
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
values = new ArrayList<Integer>();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void testActive() throws Exception {
final WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
assertTrue(text.isDisplayed());
final WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
assertTrue(button.isDisplayed());
}
}
最近在研究appium对于IOS的自动化测试,发现在真机上运行appium提供的开源的例子遇到了几个block,询问了一个这个方便面的高手并且总结网上搜到的帖子,现在综合一下。
appium 在模拟器中跑,只需要注意:
1:app=path找到编译后app所在的位置,如:注意Release-iphonesimulator这个是模拟器编译后的文件夹
final File appDir = new File(System.getProperty("user.dir"),
"../../../apps/TestApp/build/Release-iphonesimulator");
final File app = new File(appDir, "TestApp.app");
capabilities.setCapability("app", app.getAbsolutePath());
appium真机上运行:
1:运行的时候要将APP安装到真机上面
2:运行的时候,不能再开instrument
3:命令行里面启动的时候,参数写错了应该是 appium -U 3d2cad7288a64a5445aa98a2cc220132f2cddd1c --app io.appium 然后代码里面 app=bundleID,如以下例子中: capabilities.setCapability("app", "io.appium.TestApp");而不是那个很长的路径,其中-U 参数后面是真机的uuid,可以打开xcode,在windows下的organise下找到,一般mac连接上ipad后会有绿色圆点
现在贴上真机上运行python实例:
<span class="n" style="color: rgb(68, 68, 68);">Kingsons</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="n" style="color: rgb(68, 68, 68);">MacBook</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="n" style="color: rgb(68, 68, 68);">Study</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">kingson</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);">$</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);"><span style="color: black; background-color: rgb(255, 255, 102);">appium</span></span><span style="color: rgb(68, 68, 68);"> </span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="n" style="color: rgb(68, 68, 68);">U</span><span style="color: rgb(68, 68, 68);"> </span><span class="mi" style="color: rgb(0, 153, 153);">1</span><span class="n" style="color: rgb(68, 68, 68);">a601f5cd791bc379115095fc81cd69b096582a3</span><span style="color: rgb(68, 68, 68);"> </span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">--</span><span class="n" style="color: rgb(68, 68, 68);">app</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">com</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="n" style="color: rgb(68, 68, 68);">telenavsoftware</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="n" style="color: rgb(68, 68, 68);">doudouy</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Welcome</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">to</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);"><span style="color: black; background-color: rgb(255, 255, 102);">Appium</span></span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">v0</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="mf" style="color: rgb(0, 153, 153);">11.4</span><span style="color: rgb(68, 68, 68);"> </span><span class="p" style="color: rgb(68, 68, 68);">(</span><span class="n" style="color: rgb(68, 68, 68);">REV</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">b04decd191002628c88e9bf475553da1cd04a036</span><span class="p" style="color: rgb(68, 68, 68);">)</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);"><span style="color: black; background-color: rgb(255, 255, 102);">Appium</span></span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">REST</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">http</span><span style="color: rgb(68, 68, 68);"> </span><span class="nb" style="color: rgb(0, 134, 179);">int</span><span class="n" style="color: rgb(68, 68, 68);">erface</span><span style="color: rgb(68, 68, 68);"> </span><span class="nb" style="color: rgb(0, 134, 179);">list</span><span class="n" style="color: rgb(68, 68, 68);">ener</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">started</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">on</span><span style="color: rgb(68, 68, 68);"> </span><span class="mf" style="color: rgb(0, 153, 153);">0.0</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="mf" style="color: rgb(0, 153, 153);">0.0</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="mi" style="color: rgb(0, 153, 153);">4723</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span style="color: rgb(68, 68, 68);"> </span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">socket</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="n" style="color: rgb(68, 68, 68);">io</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">started</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">debug</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);"><span style="color: black; background-color: rgb(255, 255, 102);">Appium</span></span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">request</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">initiated</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">at</span><span style="color: rgb(68, 68, 68);"> </span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">wd</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">hub</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">session</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">debug</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Request</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">received</span><span style="color: rgb(68, 68, 68);"> </span><span class="k" style="color: rgb(68, 68, 68); font-weight: bold;">with</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">params</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="p" style="color: rgb(68, 68, 68);">{</span><span class="s" style="color: rgb(221, 17, 68);">"sessionId"</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="n" style="color: rgb(68, 68, 68);">null</span><span class="p" style="color: rgb(68, 68, 68);">,</span><span class="s" style="color: rgb(221, 17, 68);">"desiredCapabilities"</span><span class="p" style="color: rgb(68, 68, 68);">:{</span><span class="s" style="color: rgb(221, 17, 68);">"device"</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="s" style="color: rgb(221, 17, 68);">"iPhone Simulator"</span><span class="p" style="color: rgb(68, 68, 68);">,</span><span class="s" style="color: rgb(221, 17, 68);">"platform"</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="s" style="color: rgb(221, 17, 68);">"Mac"</span><span class="p" style="color: rgb(68, 68, 68);">,</span><span class="s" style="color: rgb(221, 17, 68);">"browserName"</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="s" style="color: rgb(221, 17, 68);">"iOS"</span><span class="p" style="color: rgb(68, 68, 68);">,</span><span class="s" style="color: rgb(221, 17, 68);">"version"</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="s" style="color: rgb(221, 17, 68);">"7.0"</span><span class="p" style="color: rgb(68, 68, 68);">,</span><span class="s" style="color: rgb(221, 17, 68);">"app"</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="s" style="color: rgb(221, 17, 68);">"com.telenavsoftware.doudouy"</span><span class="p" style="color: rgb(68, 68, 68);">}}</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">App</span><span style="color: rgb(68, 68, 68);"> </span><span class="ow" style="color: rgb(68, 68, 68); font-weight: bold;">is</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">an</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">iOS</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">bundle</span><span class="p" style="color: rgb(68, 68, 68);">,</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">will</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">attempt</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">to</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">run</span><span style="color: rgb(68, 68, 68);"> </span><span class="k" style="color: rgb(68, 68, 68); font-weight: bold;">as</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">pre</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="n" style="color: rgb(68, 68, 68);">existing</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Creating</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">new</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);"><span style="color: black; background-color: rgb(255, 255, 102);">appium</span></span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">session</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">a36fdf63</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">9</span><span class="n" style="color: rgb(68, 68, 68);">b22</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">48</span><span class="n" style="color: rgb(68, 68, 68);">a4</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="n" style="color: rgb(68, 68, 68);">bb01</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">4</span><span class="n" style="color: rgb(68, 68, 68);">b44ddb54aff</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Removing</span><span style="color: rgb(68, 68, 68);"> </span><span class="nb" style="color: rgb(0, 134, 179);">any</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">remaining</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">instruments</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">sockets</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Cleaned</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">up</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">instruments</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">socket</span><span style="color: rgb(68, 68, 68);"> </span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">tmp</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">instruments_sock</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Cleaning</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">up</span><span style="color: rgb(68, 68, 68);"> </span><span class="nb" style="color: rgb(0, 134, 179);">any</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">tracedirs</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">No</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">tracedirs</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">to</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">clean</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">up</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Localizable</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="nb" style="color: rgb(0, 134, 179);">str</span><span class="n" style="color: rgb(68, 68, 68);">ings</span><span style="color: rgb(68, 68, 68);"> </span><span class="ow" style="color: rgb(68, 68, 68); font-weight: bold;">is</span><span style="color: rgb(68, 68, 68);"> </span><span class="ow" style="color: rgb(68, 68, 68); font-weight: bold;">not</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">currently</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">supported</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">when</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">using</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">real</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">devices</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">info</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Not</span><span style="color: rgb(68, 68, 68);"> </span><span class="nb" style="color: rgb(0, 134, 179);">set</span><span class="n" style="color: rgb(68, 68, 68);">ting</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">device</span><span style="color: rgb(68, 68, 68);"> </span><span class="nb" style="color: rgb(0, 134, 179);">type</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">since</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">we</span><span class="s" style="color: rgb(221, 17, 68);">'re connected to a device</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: Starting iOS device log capture via idevicesyslog</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">debug: Real device specified but no ipa, assuming bundle ID is on device</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">debug: Creating instruments</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: instruments is: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: Attempting to run app on real device with UDID 1a601f5cd791bc379115095fc81cd69b096582a3</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w 1a601f5cd791bc379115095fc81cd69b096582a3 com.telenavsoftware.doudouy -e UIASCRIPT /usr/local/lib/node_modules/<span style="color: black; background-color: rgb(255, 255, 102);">appium</span>/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/<span style="color: black; background-color: rgb(255, 255, 102);">appium</span>-instruments/</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: And extra without-delay env: {}</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: And launch timeout: 90000ms</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: [INST STDERR] 2013-12-10 10:40:22.536 instruments[53424:507] Connection to the remote device lost while launching target. Aborting...</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: [INST STDERR] 2013-12-10 10:40:22.539 instruments[53424:507] Recording cancelled : At least one target failed to launch; aborting run</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: [INST STDERR] Instruments Trace Error : Error Domain=com.apple.instruments Code=1 "Error Starting Recording" UserInfo=0x7ff6d308f220 {NSLocalizedDescription=Error Starting Recording, NSLocalizedRecoverySuggestion=At least one target failed to launch; aborting run}</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">Instruments Trace Error : Failed to start trace.</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: [INSTSERVER] Instruments exited with code 253</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">error: Instruments did not launch successfully, failing session</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: Cleaning up <span style="color: black; background-color: rgb(255, 255, 102);">appium</span> session</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">error: Failed to start an <span style="color: black; background-color: rgb(255, 255, 102);">Appium</span> session, err was: Error: Instruments did not launch successfully--please check your app paths or bundle IDs and try again</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments did not launch successfully--please check your app paths or bundle IDs and try again)","origValue":"Instruments did not launch successfully--please check your app paths or bundle IDs and try again"},"sessionId":null}</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">POST /wd/hub/session 500 6015ms - 342b```</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s"><strong><span style="font-size: 18px; color: rgb(51, 51, 255);">我的部分代码片段:</span></strong></span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">```python</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);">class TestSequenceFunctions(unittest.TestCase):</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> def setUp(self):</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> # set up <span style="color: black; background-color: rgb(255, 255, 102);">appium</span></span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> app = "com.telenavsoftware.doudouy"</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> #app = os.path.join(os.path.dirname(__file__),</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> # '</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">../../</span><span class="n" style="color: rgb(68, 68, 68);">apps</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">DDY</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">build</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="s" style="color: rgb(221, 17, 68);">',</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> # '</span><span class="n" style="color: rgb(68, 68, 68);">DouDouY</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="n" style="color: rgb(68, 68, 68);">app</span><span class="s" style="color: rgb(221, 17, 68);">')</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> #app = os.path.abspath(app)</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> self.driver = webdriver.Remote(</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> command_executor='</span><span class="n" style="color: rgb(68, 68, 68);">http</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">//</span><span class="mf" style="color: rgb(0, 153, 153);">127.0</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">.</span><span class="mf" style="color: rgb(0, 153, 153);">0.1</span><span class="p" style="color: rgb(68, 68, 68);">:</span><span class="mi" style="color: rgb(0, 153, 153);">4723</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">wd</span><span class="o" style="color: rgb(68, 68, 68); font-weight: bold;">/</span><span class="n" style="color: rgb(68, 68, 68);">hub</span><span class="s" style="color: rgb(221, 17, 68);">',</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> desired_capabilities={</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> '</span><span class="n" style="color: rgb(68, 68, 68);">browserName</span><span class="s" style="color: rgb(221, 17, 68);">': '</span><span class="n" style="color: rgb(68, 68, 68);">iOS</span><span class="s" style="color: rgb(221, 17, 68);">',</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> '</span><span class="n" style="color: rgb(68, 68, 68);">device</span><span class="s" style="color: rgb(221, 17, 68);">': '</span><span class="n" style="color: rgb(68, 68, 68);">iPhone</span><span style="color: rgb(68, 68, 68);"> </span><span class="n" style="color: rgb(68, 68, 68);">Simulator</span><span class="s" style="color: rgb(221, 17, 68);">',</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> '</span><span class="n" style="color: rgb(68, 68, 68);">platform</span><span class="s" style="color: rgb(221, 17, 68);">': '</span><span class="n" style="color: rgb(68, 68, 68);">Mac</span><span class="s" style="color: rgb(221, 17, 68);">',</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> '</span><span class="n" style="color: rgb(68, 68, 68);">version</span><span class="s" style="color: rgb(221, 17, 68);">': '</span><span class="mf" style="color: rgb(0, 153, 153);">7.0</span><span class="s" style="color: rgb(221, 17, 68);">',</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> '</span><span class="n" style="color: rgb(68, 68, 68);">app</span><span class="s" style="color: rgb(221, 17, 68);">': app</span><span class="err" style="color: rgb(166, 23, 23); background-color: rgb(227, 210, 210);"> </span><span class="s" style="color: rgb(221, 17, 68);"> })```</span>1.启动Appium时,保证你的Real
Device的UDID和你的应用的Bundle ID正确
2.确保你的应用可以安装到你的真机上
3.安装后请断开与Xcode的连接
4.确保Mac上没有启动Instruments工具
以下是JAVA真机运行log:
devexus-iMac:build devexu$ appium -U 3d2cad7288a64a5445aa98a2cc220132f2cddd1c --app io.appium
info: Welcome to Appium v1.1.0 (REV e433bbc31511f199287db7724e1ce692bcb32117)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: socket.io started
info: Non-default server args: {"app":"io.appium","udid":"3d2cad7288a64a5445aa98a2cc220132f2cddd1c"}
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"platformVersion":"7.1","app":"io.appium.TestApp","platformName":"iOS","deviceName":"iPhone Simulator","browserName":""}}
info: App is an iOS bundle, will attempt to run as pre-existing
info: Creating new appium session 2bcd619b-b7fb-45f5-b20c-79caff8cd24f
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock
info: Cleaning up any tracedirs
info: No tracedirs to clean up
info: Setting Xcode folder
info: Setting Xcode version
info: Setting iOS SDK Version
info: iOS SDK Version set to 7.1
info: Detecting automation tracetemplate
info: Not auto-detecting udid, running on sim
info: Localizable.strings is not currently supported when using real devices.
info: Not setting locale because we're using a real device
debug: Creating instruments
info: Not setting iOS and app preferences since we're on a real device
info: Starting iOS device log capture via idevicesyslog
info: Not setting device type since we're connected to a device
debug: Real device specified but no ipa or app path, assuming bundle ID is on device
debug: Starting instruments
info: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Attempting to run app on real device with UDID 3d2cad7288a64a5445aa98a2cc220132f2cddd1c
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
-w 3d2cad7288a64a5445aa98a2cc220132f2cddd1c io.appium.TestApp -e UIASCRIPT /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments
info: And extra without-delay env: {}
info: And launch timeouts (in ms): {"global":90000}
info: [INST] 2014-07-02 01:29:30 +0000 Start: Bootstrapping uiauto
info: [INST] 2014-07-02 01:29:32 +0000 Start: Got user: devexu
info: [INST] 2014-07-02 01:29:33 +0000 Start: Not using settings file.
info: [INST] 2014-07-02 01:29:33 +0000 Start: isVerbose:false
info: [INST] 2014-07-02 01:29:37 +0000 Start: Using node at: /usr/local/bin/node
info: [INSTSERVER] Instruments is ready to receive commands
info: Instruments launched. Starting poll loop for new commands.
info: Setting bootstrap config keys/values
info: Pushing command to appium work queue: "setBootstrapConfig: autoAcceptAlerts=false"
debug: Sending command to instruments: setBootstrapConfig: autoAcceptAlerts=false
info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: setBootstrapConfig: autoAcceptAlerts=false
info: [INSTSERVER] Socket data received (48 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":""}
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INST] 2014-07-02 01:29:41 +0000 Debug: target.setDeviceOrientation("1")
info: [INSTSERVER] Socket data received (56 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Device launched! Ready for commands
info: Setting command timeout to the default of 60 secs
info: Appium session started with sessionId 2bcd619b-b7fb-45f5-b20c-79caff8cd24f
POST /wd/hub/session 303 22483ms - 9b
debug: Appium request initiated at /wd/hub/session/2bcd619b-b7fb-45f5-b20c-79caff8cd24f
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"warnings":{},"desired":{"platformVersion":"7.1","app":"io.appium.TestApp","platformName":"iOS","deviceName":"iPhone
Simulator","browserName":""},"platformVersion":"7.1","app":"io.appium.TestApp","platformName":"iOS","deviceName":"iPhone Simulator"},"sessionId":"2bcd619b-b7fb-45f5-b20c-79caff8cd24f"}
..........
java真机运行的代码:
package com.saucelabs.appium;
import static org.junit.Assert.assertTrue;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* Simple <a href="https://github.com/appium/appium">Appium</a> test which runs
* against a local Appium instance deployed with the 'TestApp' iPhone project
* which is included in the Appium source distribution.
*
* @author Ross Rowe
*/
public class WiMyOffice {
private AppiumDriver driver;
private List<Integer> values;
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
private Point getCenter(final WebElement element) {
final Point upperLeft = element.getLocation();
final Dimension dimensions = element.getSize();
return new Point(upperLeft.getX() + dimensions.getWidth() / 2,
upperLeft.getY() + dimensions.getHeight() / 2);
}
private void populate() {
// populate text fields with two random number
final List<WebElement> elems = driver.findElements(By
.className("UIATextField"));
final Random random = new Random();
for (final WebElement elem : elems) {
final int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
elem.sendKeys(String.valueOf(rndNum));
values.add(rndNum);
}
}
@Before
public void setUp() throws Exception {
// set up appium
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("app", "io.appium.TestApp");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
values = new ArrayList<Integer>();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void testHideKeyboard() throws Exception {
driver.findElement(By.xpath("//UIATextField[1]")).sendKeys("12");
final WebElement button = driver.findElement(MobileBy
.AccessibilityId("Done"));
assertTrue(button.isDisplayed());
button.click();
}
}
java上在模拟器上跑的实例:
命令行输入:appium &启动服务就可以了
lsof -i:4723查看端口号有没有被占用,占用就用 kill -9 进程ID
代码:
package com.saucelabs.appium;
import static org.junit.Assert.assertTrue;
import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* Simple <a href="https://github.com/appium/appium">Appium</a> test which runs
* against a local Appium instance deployed with the 'TestApp' iPhone project
* which is included in the Appium source distribution.
*
* @author Ross Rowe
*/
public class SimpleTest {
private AppiumDriver driver;
private List<Integer> values;
private static final int MINIMUM = 0;
private static final int MAXIMUM = 10;
private Point getCenter(final WebElement element) {
final Point upperLeft = element.getLocation();
final Dimension dimensions = element.getSize();
return new Point(upperLeft.getX() + dimensions.getWidth() / 2,
upperLeft.getY() + dimensions.getHeight() / 2);
}
private void populate() {
// populate text fields with two random number
final List<WebElement> elems = driver.findElements(By
.className("UIATextField"));
final Random random = new Random();
for (final WebElement elem : elems) {
final int rndNum = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;
elem.sendKeys(String.valueOf(rndNum));
values.add(rndNum);
}
}
@Before
public void setUp() throws Exception {
// set up appium
final File appDir = new File(System.getProperty("user.dir"),
"../../../apps/TestApp/build/Release-iphonesimulator");
final File app = new File(appDir, "TestApp.app");
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
values = new ArrayList<Integer>();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void testActive() throws Exception {
final WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
assertTrue(text.isDisplayed());
final WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
assertTrue(button.isDisplayed());
}
}
相关文章推荐
- iOS AssetsLibrary和Photos的使用总结: 原图获取(2)
- iOS支持MP4,AVI,NAVI,DV-AVI,DIVX,MOV,ASF,WMV,RM,RMVB等视频格式。
- iOS中常用的持久化存储方式有好几种
- iOS学习路线历程
- iOS AssetsLibrary和Photos的使用总结: 权限及相册的获取(1)
- iOS-OC-iOS传值大全(代理传值,block 传值,单例传值,通知传值,属性传值)
- iOS-OC-NSMutableArray用法大全详细说明
- iOS蓝牙4.0协议简单介绍
- iOS-OC-NSArray用法大全详细说明
- iOS-OC-NSDictionary和NSMutableDictionary用法大全详细说明
- iOS-OC-NSString和NSMutableString用法大全
- iOS-OC-监听键盘的高度 隐藏和出现
- iOS系统相册的有关操作
- iOS-OC-语音播放之切换听筒和扬声器的方法解决方案(红外感应)
- 对iOS锁的一些研究
- ionic input can't run on ios
- iOS_SN_CoreData数据迁移
- iOS 学习日志 : 向服务器发送Json数据
- iOS沙盒与清除缓存
- IOS开发他山之石系列-安装Alcatraz