appium在真机上运行IOS实例要注意的几点:包括python和java运行log和部分关键代码

上传人:泽*** 文档编号:75449697 上传时间:2022-04-15 格式:DOC 页数:26 大小:87KB
返回 下载 相关 举报
appium在真机上运行IOS实例要注意的几点:包括python和java运行log和部分关键代码_第1页
第1页 / 共26页
appium在真机上运行IOS实例要注意的几点:包括python和java运行log和部分关键代码_第2页
第2页 / 共26页
appium在真机上运行IOS实例要注意的几点:包括python和java运行log和部分关键代码_第3页
第3页 / 共26页
点击查看更多>>
资源描述
appium 在真机上运行 IOS 实例要注意的几点:包括 python 和 java 运行 log 和部分关键代码最近在研究 appium 对于 IOS 的自动化测试,发现在真机上运行 appium 提供的开源的例子遇到了几个 block, 询问了一个这个方便面的高手并且总结网上搜到的帖子,现在综合一下。appium在模拟器中跑,只需要注意:1:app=path 找到编译后 app 所在的位置,如:注意 Release-iphonesimulator 这个是模拟器编译后的文件夹final File appDir = newFile(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: 运行的时候,不能再开 instrument3: 命令行里面启动的时候,参数写错了应该是 appium -U 3d2cad7288a64a5445aa98a2cc220132f2cddd1c -app io.appium 然后代码里面 app=bundleID, 如以下例子中:而不是那个很长的路径,其中 U 参数后面是真机的uuid ,可以打开 xcode, 在 windows 下的 organise 下找到,一般 mac 连接上 ipad 后会有绿色圆点现在贴上真机上运行Python 实例:info- socket.io startedinfo: App is an iOS bundle, will attempt to run as pre-existinginfo: Creating new appium session a36fdf63-9b22-48a4-bb01-4b44ddb54affinfo: Removing any remaining instruments socketsinfo: Cleaned up instruments socket/tmp/instruments_sockinfo: Cleaning up any tracedirsinfo: No tracedirs to clean upinfo: Localizable.strings is not currently supported when using real devices.info: Not setting device type since were connected to a deviceinfo: Starting iOS device log capture via idevicesyslog debug: Real device specified but no ipa, assuming bundle ID is on devicedebug: Creating instrumentsinfo: instruments is:/Applications/Xcode.app/Contents/Developer/usr/bin/instrumentsinfo: INSTSERVER Instruments socket server started at /tmp/instruments_sockinfo: Attempting to run app on real device with UDID 1a601f5cd791bc379115095fc81cd69b096582a3 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 -w1a601f5cd791bc379115095fc81cd69b096582a3/usr/local/lib/node_modules/appium/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH/tmp/appium-instruments/info: And extra without-delay env: info: And launch timeout: 90000msinfo: INST STDERR 2013-12-10 10:40:22.536 instruments53424:507 Connection to the remote device lost while launching target. Aborting.info: INST STDERR 2013-12-10 10:40:22.539 instruments53424:507 Recording cancelled : At least one target failed to launch; aborting runNSLocalizedDescription=Error Starting Recording, NSLocalizedRecoverySuggestion=At least one target failed to launch; aborting runInstruments Trace Error : Failed to start trace.info: INSTSERVER Instruments exited with code 253 error: Instruments did not launch successfully, failing sessioninfo: Cleaning up appium sessionerror: Failed to start an Appium session, err was: Error: Instruments did not launch successfully-please check your app paths or bundle IDs and try againinfo: 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:nullPOST /wd/hub/session 500 6015ms - 342b我的部分代码片段:pythonclass TestSequenceFunctions(unittest.TestCase):def setUp(self):# set up appium# ././apps/DDY/build/, # DouDouY.app)self.driver = webdriver.Remote(desired_capabilities=browserName: iOS,device: iPhone Simulator,platform: Mac,version: 7.0,app: app)1. 启动 Appium 时,保证你的RealDevice 的 UDID 和你的应用的Bundle ID正确2. 确保你的应用可以安装到你的真机上3. 安装后请断开与 Xcode 的连接4. 确保 Mac 上没有启动 Instruments 工具以下是 JAVA 真机运行 log :devexus-iMac:build devexu$appium -U3d2cad7288a64a5445aa98a2cc220132f2cddd1c -appio.appiuminfo: socket.io startedinfo: Non-default server args:app:io.appium,udid:3d2cad7288a64a5445aa98a2cc220132f2cddd1cdebug: Appium request initiated at /wd/hub/sessiondebug: Request received with params:desiredCapabilities:platformVersion:7.1,app:io.appium.TestApp,platformName:iOS,deviceName:iPho ne Simulator,browserName:info: App is an iOS bundle, will attempt to run as pre-existinginfo: Creating new appium session2bcd619b-b7fb-45f5-b20c-79caff8cd24finfo: Removing any remaining instruments socketsinfo: Cleaned up instruments socket/tmp/instruments_sockinfo: Cleaning up any tracedirsinfo: No tracedirs to clean upinfo: Setting Xcode folderinfo: Setting Xcode versioninfo: Setting iOS SDK Versioninfo: iOS SDK Version set to 7.1info: Detecting automation tracetemplateinfo: Not auto-detecting udid, running on siminfo: Localizable.strings is not currently supported when using real devices.info: Not setting locale because were using a real devicedebug: Creating instrumentsinfo: Not setting iOS and app preferences since were on areal deviceinfo: Starting iOS device log capture via idevicesyslog info: Not setting device type since were connected to a devicedebug: Real device specified but no ipa or app path, assuming bundle ID is on device debug: Starting instrumentsinfo: Instruments is at:/Applications/Xcode.app/Contents/Developer/usr/bin/instrumentsinfo: INSTSERVER Instruments socket server started at /tmp/instruments_sockinfo: Attempting to run app on real device with UDID3d2cad7288a64a5445aa98a2cc220132f2cddd1cinfo: 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/usr/local/lib/node_modules/appium/node_modules/appiu m-uiauto/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instrumentsinfo: And extra without-delay env: info: And launch timeouts (in ms): global:90000info: INST 2014-07-02 01:29:30 +0000 Start:Bootstrapping uiautoinfo: INST 2014-07-02 01:29:32 +0000 Start: Got user:devexuinfo: INST 2014-07-02 01:29:33 +0000 Start: Not using settings file.info: INST 2014-07-02 01:29:33 +0000 Start:isVerbose:falseinfo: INST 2014-07-02 01:29:37 +0000 Start: Using nodeat: /usr/local/bin/nodeinfo: INSTSERVER Instruments is ready to receive commandsinfo: Instruments launched. Starting poll loop for new commands.info: Setting bootstrap config keys/valuesinfo: Pushing command to appium work queue:setBootstrapConfig: autoAcceptAlerts=falsedebug: Sending command to instruments:setBootstrapConfig: autoAcceptAlerts=falseinfo: INSTSERVER Socket data received (15 bytes)info: INSTSERVER Socket data being routed for cmd eventinfo: INSTSERVER Sending command to instruments:setBootstrapConfig: autoAcceptAlerts=falseinfo: INSTSERVER Socket data received (48 bytes)info: INSTSERVER Socket data being routed for cmd eventinfo: 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 eventinfo: INSTSERVER Got result from instruments:status:0,value:PORTRAITinfo: Device launched! Ready for commandsinfo: 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,locationC ontextEnabled:false,browserName:,platform:MAC, javascriptEnabled:true,databaseEnabled:false,takesScreenshot:true,warnings:,desired:platformVersion:7.eName:iPhoneSimulator,browserName:,platformVersion:7.1,app:iPhoneSimulator,sessionId:2bcd619b-b7fb-45f5-b20c-79caff8cd24f.java 真机运行的代码:import* Simple <a href= > 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 AppiumDriverdriver;private List<Integer>values;privatestatic final int MINIMUM = 0;private static final int MAXIMUM = 10;private PointgetCenter(final WebElement element) final PointupperLeft = 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 numberfinal 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); Beforepublic void setUp() throws Exception / set up appiumfinal DesiredCapabilitiescapabilities = new DesiredCapabilities();capabilities.setCapability(CapabilityType.BROWSER_NA ME, );capabilities.setCapability(platformVersion, 7.1);capabilities.setCapability(platformName, iOS);capabilities.setCapability(deviceName, iPhone Simulator);driver = new AppiumDriver(newcapabilities);values = new ArrayList<Integer>(); Afterpublic void tearDown() throws Exception driver.quit(); Testpublic void testHideKeyboard() throws Exception driver.findElement(By.xpath(/UIATextField1).sendKeys(12);final WebElement button =driver.findElement(MobileBy.AccessibilityId(Done);assertTrue(button.isDisplayed();button.click();java 上在模拟器上跑的实例:命令行输入: appium &启动服务就可以了lsof -i:4723查看端口号有没有被占用,占用就用kill -9进程 ID代码:import* Simple <ahref= > 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; static final int MINIMUM = 0;privateprivate static final int MAXIMUM = 10; getCenter(final WebElement element) upperLeft = element.getLocation();private Pointfinal Pointfinal 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 numberfinal 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); Beforepublic void setUp() throws Exception / set up appiumfinal File appDir = newFile(System.getProperty(user.dir),./././apps/TestApp/build/Release-iphonesimulator);final File app = new File(appDir, TestApp.app);final DesiredCapabilities capabilities = newDesiredCapabilities();capabilities.setCapability(CapabilityType.BROWSER_NA ME, );capabilities.setCapability(platformVersion, 7.1);capabilities.setCapability(platformName, iOS);capabilities.setCapability(deviceName, iPhone Simulator);capabilities.setCapability(app,app.getAbsolutePath();driver = new AppiumDriver(newcapabilities);values = new ArrayList<Integer>(); Afterpublic void tearDown() throws Exception driver.quit(); Testpublic void testActive() throws Exception final WebElement text =driver.findElement(By.xpath(/UIATextField1);assertTrue(text.isDisplayed();final WebElementbutton = driver.findElement(By.xpath(/UIAButton1);assertTrue(button.isDisplayed();
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!