├── .classpath ├── .idea ├── .name ├── ant.xml ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── workspace.xml ├── .project ├── MacacaAutomation.iml ├── README.md ├── app └── README.md ├── bin ├── README.md └── exec_replace.sh ├── build └── testngcase │ └── ios │ └── IOSAppTest.class ├── build_testng.xml ├── lib ├── commons-codec-1.9.jar ├── commons-logging-1.2.jar ├── fastjson-1.2.15.jar ├── guice-4.0.jar ├── httpclient-4.5.2.jar ├── httpcore-4.4.4.jar ├── jcommander-1.48.jar ├── macacaclient-2.0.1.jar ├── reportng-1.1.4.jar ├── testng-6.10.jar ├── velocity-1.4.jar └── velocity-dep-1.4.jar ├── pom.xml ├── report ├── html │ ├── index.html │ ├── overview.html │ ├── reportng.css │ ├── reportng.js │ ├── sorttable.js │ ├── suite1_test1_results.html │ └── suites.html ├── img │ ├── README.md │ ├── img20180131143205.png │ ├── img20180131143828.png │ ├── img20180131143925.png │ ├── img20180131144004.png │ ├── img20180131152154.png │ └── img20180131165729.png └── xml │ └── testngcase.ios.IOSAppTest_results.xml ├── settings.xml ├── src └── testngcase │ └── ios │ └── IOSAppTest.java ├── target └── classes │ └── testngcase │ └── ios │ └── IOSAppTest.class └── testng.xml /.classpath: -------------------------------------------------------------------------------- 1 | ?xml version="1.0" encoding="UTF-8"?> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MacacaAutomation -------------------------------------------------------------------------------- /.idea/ant.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | TESTNG.XML 92 | 93 | 94 | C:\Users\baozhida\.m2\repository\com\alibaba\fastjson\1.2.15\fastjson-1.2.15.jar 95 | 96 | 97 | 98 | 100 | 101 | 111 | 112 | 113 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | fields. 207 | 208 | hasInputs = (typeof node.getElementsByTagName == 'function') && 209 | node.getElementsByTagName('input').length; 210 | 211 | if (node.getAttribute("sorttable_customkey") != null) { 212 | return node.getAttribute("sorttable_customkey"); 213 | } 214 | else if (typeof node.textContent != 'undefined' && !hasInputs) { 215 | return node.textContent.replace(/^\s+|\s+$/g, ''); 216 | } 217 | else if (typeof node.innerText != 'undefined' && !hasInputs) { 218 | return node.innerText.replace(/^\s+|\s+$/g, ''); 219 | } 220 | else if (typeof node.text != 'undefined' && !hasInputs) { 221 | return node.text.replace(/^\s+|\s+$/g, ''); 222 | } 223 | else { 224 | switch (node.nodeType) { 225 | case 3: 226 | if (node.nodeName.toLowerCase() == 'input') { 227 | return node.value.replace(/^\s+|\s+$/g, ''); 228 | } 229 | case 4: 230 | return node.nodeValue.replace(/^\s+|\s+$/g, ''); 231 | break; 232 | case 1: 233 | case 11: 234 | var innerText = ''; 235 | for (var i = 0; i < node.childNodes.length; i++) { 236 | innerText += sorttable.getInnerText(node.childNodes[i]); 237 | } 238 | return innerText.replace(/^\s+|\s+$/g, ''); 239 | break; 240 | default: 241 | return ''; 242 | } 243 | } 244 | }, 245 | 246 | reverse: function(tbody) { 247 | // reverse the rows in a tbody 248 | newrows = []; 249 | for (var i=0; i=0; i--) { 253 | tbody.appendChild(newrows[i]); 254 | } 255 | delete newrows; 256 | }, 257 | 258 | /* sort functions 259 | each sort function takes two parameters, a and b 260 | you are comparing a[0] and b[0] */ 261 | sort_numeric: function(a,b) { 262 | aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); 263 | if (isNaN(aa)) aa = 0; 264 | bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); 265 | if (isNaN(bb)) bb = 0; 266 | return aa-bb; 267 | }, 268 | sort_alpha: function(a,b) { 269 | if (a[0]==b[0]) return 0; 270 | if (a[0] 0 ) { 316 | var q = list[i]; list[i] = list[i+1]; list[i+1] = q; 317 | swap = true; 318 | } 319 | } // for 320 | t--; 321 | 322 | if (!swap) break; 323 | 324 | for(var i = t; i > b; --i) { 325 | if ( comp_func(list[i], list[i-1]) < 0 ) { 326 | var q = list[i]; list[i] = list[i-1]; list[i-1] = q; 327 | swap = true; 328 | } 329 | } // for 330 | b++; 331 | 332 | } // while(swap) 333 | } 334 | } 335 | 336 | /* ****************************************************************** 337 | Supporting functions: bundled here to avoid depending on a library 338 | ****************************************************************** */ 339 | 340 | // Dean Edwards/Matthias Miller/John Resig 341 | 342 | /* for Mozilla/Opera9 */ 343 | if (document.addEventListener) { 344 | document.addEventListener("DOMContentLoaded", sorttable.init, false); 345 | } 346 | 347 | /* for Internet Explorer */ 348 | /*@cc_on @*/ 349 | /*@if (@_win32) 350 | document.write(" 11 | 12 | 13 |

IOSTest1

14 |

15 | Test duration: 42.469s 16 |

17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 35 | 41 | 42 |
Passed Tests
testngcase.ios.IOSAppTest
30 | case_001xxx 31 | 33 | 16.252s 34 | 36 | 37 | 38 | 39 | 40 |
43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /report/html/suites.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | IOSUIAutoTestReport - Suites 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |

IOSUIAutoTestReport

16 |

17 | Overview 18 |

19 |
20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 |
24 | IOS 25 |
32 | 33 | IOSTest1 34 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /report/img/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /report/img/img20180131143205.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/report/img/img20180131143205.png -------------------------------------------------------------------------------- /report/img/img20180131143828.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/report/img/img20180131143828.png -------------------------------------------------------------------------------- /report/img/img20180131143925.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/report/img/img20180131143925.png -------------------------------------------------------------------------------- /report/img/img20180131144004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/report/img/img20180131144004.png -------------------------------------------------------------------------------- /report/img/img20180131152154.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/report/img/img20180131152154.png -------------------------------------------------------------------------------- /report/img/img20180131165729.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/report/img/img20180131165729.png -------------------------------------------------------------------------------- /report/xml/testngcase.ios.IOSAppTest_results.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | false 11 | 12 | central 13 | bintray 14 | http://jcenter.bintray.com 15 | 16 | 17 | 18 | 19 | 20 | false 21 | 22 | central 23 | bintray-plugins 24 | http://jcenter.bintray.com 25 | 26 | 27 | bintray 28 | 29 | 30 | 31 | bintray 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/testngcase/ios/IOSAppTest.java: -------------------------------------------------------------------------------- 1 | package testngcase.ios; 2 | 3 | //import static org.testng.AssertJUnit.assertTrue; 4 | //import static org.testng.AssertJUnit.fail; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | 11 | import org.testng.annotations.AfterClass; 12 | import org.testng.annotations.AfterMethod; 13 | import org.testng.annotations.BeforeClass; 14 | import org.testng.annotations.BeforeMethod; 15 | import org.testng.annotations.Test; 16 | 17 | import com.alibaba.fastjson.JSONObject; 18 | 19 | import macaca.client.MacacaClient; 20 | import macaca.client.commands.Element; 21 | 22 | 23 | 24 | public class IOSAppTest { 25 | 26 | boolean isFail; 27 | 28 | private MacacaClient driver = new MacacaClient(); 29 | 30 | public MacacaClient initDriver() throws Exception { 31 | 32 | JSONObject porps = new JSONObject(); 33 | porps.put("platformName", "Android"); 34 | porps.put("package", "com.tuniu.app.ui"); 35 | porps.put("activity", "com.tuniu.app.ui.activity.LaunchActivity"); 36 | //0: 启动并安装 app。1 (默认): 卸载并重装 app。 2: 仅重装 app。3: 在测试结束后保持 app 状态。 37 | porps.put("reuse", 3); 38 | porps.put("udid", "4d4aa2f3"); 39 | JSONObject desiredCapabilities = new JSONObject(); 40 | desiredCapabilities.put("desiredCapabilities", porps); 41 | 42 | return driver.initDriver(desiredCapabilities); 43 | } 44 | 45 | @BeforeClass 46 | public void setUp() throws Exception { 47 | 48 | initDriver(); 49 | } 50 | 51 | @BeforeMethod 52 | public void beforecase() throws Exception { 53 | //重置isFail,判读是否执行 aftercase方法 54 | isFail = true; 55 | } 56 | 57 | @Test 58 | public void case_001xxx() { 59 | // set screenshot save path 60 | //String courseFile = directory.getCanonicalPath(); 61 | try { 62 | driver.sleep(5000); 63 | Element el = driver.elementByXPath("//*[@resource-id='com.tuniu.app.ui:id/mainpage_my']"); 64 | System.out.println("------------我的控件存在------------------"); 65 | 66 | el.click(); 67 | //判断到达新页面 68 | assertTrueReWrite("assertTrue:元素未找到!",driver.sleep(5000).isElementExist("xpath", "//*[@text='我的订单']")); 69 | //screenShot(); 70 | System.out.println("------------控件存在------------------"); 71 | 72 | //返回首页 73 | driver.elementByXPath("//*[@resource-id='com.tuniu.app.ui:id/mainpage']").click(); 74 | driver.sleep(2000); 75 | isFail = false; 76 | } catch (Exception e) { 77 | failReWrite(e.toString()+e.getLocalizedMessage()); 78 | } 79 | 80 | } 81 | 82 | @AfterMethod 83 | public void aftercase() throws Exception { 84 | System.out.println("------------进入aftercase方法-----------------"); 85 | if(isFail==true){ 86 | 87 | } 88 | //如果5次循环都不能到首页,重新初始化driver 89 | //initDriver(); 90 | } 91 | 92 | @AfterClass 93 | public void tearDown() throws Exception { 94 | driver.quit(); 95 | } 96 | 97 | public void failReWrite(String message) { 98 | String imgurl = screenShot(); 99 | if (message == null) { 100 | throw new AssertionError(); 101 | } 102 | throw new AssertionError(message+" Check:"+" ltltlta target=_blank href=file://"+imgurl+"gtgtgtScreenShotltltlt/agtgtgt"+" "); 103 | } 104 | 105 | 106 | public void assertTrueReWrite(String message, boolean condition) { 107 | if (!condition) { 108 | failReWrite(message); 109 | } 110 | } 111 | 112 | 113 | public String getDateTime(){ 114 | SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); 115 | return df.format(new Date()); 116 | } 117 | 118 | 119 | public String screenShot(){ 120 | 121 | File directory = new File(""); 122 | String courseFile; 123 | try { 124 | courseFile = directory.getCanonicalPath(); 125 | String imgname = courseFile+"/report/img/img"+getDateTime()+".png"; 126 | System.out.println("-------imgname----------"+imgname); 127 | driver.saveScreenshot(imgname); 128 | return imgname; 129 | } catch (IOException e) { 130 | System.out.println("获取路径失败,报错信息:"+e.getMessage()); 131 | return ""; 132 | } catch (Exception e1) { 133 | System.out.println("截图失败,报错信息:"+e1.getMessage()); 134 | return ""; 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /target/classes/testngcase/ios/IOSAppTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baozhida/MacacaAutomation/d391fd34d266e21d80316e12615bf00969b4bd9a/target/classes/testngcase/ios/IOSAppTest.class -------------------------------------------------------------------------------- /testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | --------------------------------------------------------------------------------