Best JavaScript code snippet using appium
_api.js
Source:_api.js
1// QT4i-Instruments端-JavaScript-API2(function($) {3 UIAElementsCache = function() {4 this.caches = {};5 this.id = 0;6 this.append(UIATarget.localTarget().frontMostApp());7 };8 UIAElementsCache.prototype = {9 release_all : function() {10 this.caches = {};11 },12 release_invalid : function() {13 //for (var id in this.caches) {14 // if (!this.caches[id].isValid()) {15 // delete this.caches[id];16 // };17 //};18 },19 release : function(id) {20 //var element = this.caches[id];21 //if (!element.isValid()) {22 // delete this.caches[id];23 //};24 },25 append : function(element) {26 if (element == null || element.toString() == "[object UIAElementNil]") {27 return undefined;28 }29 var id = (this.id += 1);30 this.caches[id] = element;31 return id;32 },33 append_elements : function(elements) {34 var ids = new Array();35 for (var i = 0; i < elements.length; i++) {36 ids.push(this.append(elements[i]));37 };38 return ids;39 },40 set : function(id, element) {41 if (this.caches[id]) {42 this.caches[id] = element;43 return true;44 };45 return false;46 },47 get : function(id) {48 this.set(1, UIATarget.localTarget().frontMostApp());49 if ( typeof id == 'number') {50 var element = this.caches[id];51 if (element) {52 //if (element.isValid()) {53 return element;54 //} else {55 // this.release(id);56 //};57 };58 };59 if ( typeof id == 'string' && new RegExp(/^\/classname *\= *(\'|\")\w+(\'|\").*$/i).test(id)) {60 var element = $.QPath(id).findElement(0);61 if (element) {62 return element;63 };64 throw new Error("element not found: " + id);65 };66 throw new Error("element id is invalid: " + id);67 }68 };69})($);70// -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*-71(function($) {72 var uia_elements_cache = new UIAElementsCache();73 var switch_locator = function(strategy, locator) {74 switch(strategy.toLocaleLowerCase()) {75 case 'qpath':76 return $.QPath(locator);77 };78 };79 var last_alert_msg = null;80 var flag_alert_auto_handled = Environment.flag_alert_auto_handled ? Environment.flag_alert_auto_handled : false;81 var rules_of_alert_auto_handle = Environment.rules_of_alert_auto_handle ? Environment.rules_of_alert_auto_handle : new Array();82 UIATarget.onAlert = function(alert) {83 alert.logElementTreeExt();84 $.log("enter onAlert flag_alert_auto_handled: "+$.str.objectToString(flag_alert_auto_handled))85 var texts = alert.getAllTexts();86 last_alert_msg = texts;87 var buttons = [];88 buttons = alert.getElementsByClassName('^UIAButton$');89 if (buttons.length == 0) {90 buttons = alert.getElementsByClassName('^UIACollectionCell$');91 };92 if (buttons.length == 0) {93 buttons = alert.getElementsByClassName('^UIATableCell$');94 };95 for (var rule_i = 0; rule_i < rules_of_alert_auto_handle.length; rule_i++) {96 var rule = rules_of_alert_auto_handle[rule_i];97 for (var text_i = 0; text_i < texts.length; text_i++) {98 var text = texts[text_i];99 if (rule.message_text == text || new RegExp(rule.message_text).test(text)) {100 if (rule.button_text) {101 for (var button_i = 0; button_i < buttons.length; button_i++) {102 var button = buttons[button_i];103 var button_texts = button.getAllTexts();104 for (var button_text_i = 0; button_text_i < button_texts.length; button_text_i++) {105 var button_text = button_texts[button_text_i];106 if (rule.button_text == button_text || new RegExp(rule.button_text).test(button_text)) {107 button.tap();108 //for(var delay_i=0; delay_i<30; delay_i++){109 // UIATarget.localTarget().delay(0.1);110 // if (alert.isValid()==false){111 // return true;112 // };113 //};114 $.log("onAlert double matched: "+$.str.objectToString(flag_alert_auto_handled))115 return true;116 };117 };118 };119 };120 $.log("onAlert single matched: "+$.str.objectToString(flag_alert_auto_handled))121 return true;122 };123 };124 };125 $.log("onAlert no matched: "+$.str.objectToString(flag_alert_auto_handled))126 return flag_alert_auto_handled;127 };128 // -*- -*- -*- -*- -*- -*-129 api = {130 'DoNotReturn' : encodeURIComponent("<<<[[[DoNotReturn]]]>>>"),131 // -*- -*- -*- -*- -*- -*-132 'uia.release' : function(cmd_id) {133 /**134 * ç»æ¢å¹¶éåºDriver135 * Returns136 * 'released' - ç»æ¢å®æ¯137 */138 return bootstrap.release();139 },140 'uia.set_cmd_fetch_delegate_timeout' : function(cmd_id, seconds) {141 /**142 * 设置cmd_fetch_delegateçè¶
æ¶å¼143 * Paramaters:144 * seconds - ç§145 */146 var seconds = parseInt(seconds);147 if (seconds > 0) {148 Environment.cmd_fetch_delegate_timeout = seconds;149 };150 },151 'uia.get_cmd_fetch_delegate_timeout' : function(cmd_id) {152 /**153 * è·åcmd_fetch_delegateçè¶
æ¶å¼154 * Returns155 * seconds - ç§156 */157 return Environment.cmd_fetch_delegate_timeout;158 },159 'uia.uia_elements_cache.release_all' : function(cmd_id) {160 /**161 * æ¸
空ææçelementsçç¼åï¼å¼å¸¸æ¶ä¼èªå¨æ¸
çï¼elementæ ææ¶ä¼èªå¨æ¸
çï¼162 */163 uia_elements_cache.release_all();164 },165 'uia.uia_elements_cache.release_invalid' : function(cmd_id) {166 /**167 * æ¸
空æ æçelementçç¼åï¼å¼å¸¸æ¶ä¼èªå¨æ¸
çï¼elementæ ææ¶ä¼èªå¨æ¸
çï¼168 */169 uia_elements_cache.release_invalid();170 },171 'uia.uia_elements_cache.release_element' : function(cmd_id, id) {172 /**173 * æ¸
çæå®elementçç¼å174 * Paramaters:175 * id - elementçid176 */177 uia_elements_cache.release(id);178 },179 'uia.front_most_app' : function(cmd_id) {180 return uia_elements_cache.append(UIATarget.localTarget().frontMostApp());181 },182 // -*- -*- -*- -*- -*- -*-183 'uia.element.function' : function(cmd_id, id, func, args) {184 /**185 * è°ç¨æå®elementçåçå½æ°ï¼UIAElementï¼186 * Paramaters:187 * id - elementçid188 * func - å½æ°å189 * args - å½æ°çæåºåæ°éå190 * Returns:191 * return value - 被è°ç¨å½æ°çè¿åå¼ï¼åºç¡ç±»åï¼192 */193 var element = uia_elements_cache.get(id);194 var args = args ? args : [];195 if (element[func]) {196 return element[func].apply(element, args);197 };198 throw new Error('uia.element.function "func: ' + func + '" is invalid.');199 },200 'uia.element.is_valid' : function(cmd_id, id) {201 try {202 uia_elements_cache.get(id);203 return true;204 } catch(e) {205 return false;206 };207 },208 'uia.element.find' : function(cmd_id, locator, timeout, interval, strategy, parent_id) {209 /**210 * æ¥æ¾å个element对象ï¼è¿åæ¥æ¾å°çelement对象çç¼åidãä¸æå®parent_idåä»UIAApplicationä¸å¼å§æç´¢ã211 * 第ä¸ä¸ªå¯¹è±¡æ°¸è¿æ¯UIAApplication - è¿æ¯ä¸ºäºå
¼å®¹Pythonå±Windowå°è£
ä¸åPathã212 * Paramaters:213 * locator - å®ä½elementçå符串ï¼ä¾å¦: "/classname='UIAWindow'"214 * parent_id - ç¶elementçidï¼å¦ä¸æå®åä»UIAApplicationä¸æ¥æ¾215 * timeout - æ¥æ¾elementçè¶
æ¶å¼ï¼åä½: ç§ï¼216 * strategy - locatorçç±»åï¼ä¾å¦: "qpath"217 * Returns - json: {'element': id, 'path': <encode str>, 'valid_path_part': <encode str>, 'invalid_path_part': <encode str>, 'find_count': <int>, "find_time": int}218 */219 var strategy = strategy ? strategy : 'qpath';220 var locator = switch_locator(strategy, locator);221 var parent = parent_id ? uia_elements_cache.get(parent_id) : null;222 var timeout = timeout ? (timeout * 1000 - 80) : 0;223 var interval = interval ? (interval * 1000) : 10;224 var result = locator.findElement(timeout, interval, parent);225 var element = result['element'];226 var element_id = element ? uia_elements_cache.append(element) : null;227 result['element'] = element_id;228 $.log("TORPC: " + $.str.objectToString({'id':cmd_id, 'result':result}));229 return api.DoNotReturn;230 },231 'uia.element.find_elements' : function(cmd_id, locator, timeout, interval, strategy, parent_id) {232 /**233 * æ¥æ¾å¤ä¸ªelement对象ï¼è¿åæ¥æ¾å°çelement对象çç¼åçidéåãä¸æå®parent_idåä»UIAApplicationä¸å¼å§æç´¢ã234 * Paramaters:235 * locator - å®ä½elementçå符串ï¼ä¾å¦: "/classname='UIAWindow'"236 * parent_id - ç¶elementçidï¼å¦ä¸æå®åä»UIAApplicationä¸æ¥æ¾237 * timeout - æ¥æ¾elementçè¶
æ¶å¼ï¼åä½: ç§ï¼238 * strategy - locatorçç±»åï¼ä¾å¦: "qpath"239 * Returns - json: {'elements': [{'element':id, 'attributes':<encode str>}], 'path': <encode str>, 'valid_path_part': <encode str>, 'invalid_path_part': <encode str>, 'find_count': <int>, "find_time": int}240 */241 var strategy = strategy ? strategy : 'qpath';242 var locator = switch_locator(strategy, locator);243 var parent = parent_id ? uia_elements_cache.get(parent_id) : null;244 var timeout = timeout ? (timeout * 1000 - 100) : 0;245 var interval = interval ? (interval * 1000) : 10;246 var result = locator.findElements(timeout, interval, parent);247 var elements = result['elements'];248 var elements_dict = new Array();249 for (var i=0; i<elements.length; i++){250 var element_id = uia_elements_cache.append(elements[i]);251 var element_dict = encodeURIComponent($.str.objectToString(elements[i].getElementDict()));252 elements_dict.push({'element': element_id, 'attributes': element_dict});253 };254 result['elements'] = elements_dict;255 $.log("TORPC: " + $.str.objectToString({'id':cmd_id, 'result':result}));256 return api.DoNotReturn;257 },258 'uia.element.first_with_name' : function(cmd_id, id, name) {259 /**260 * éè¿nameææ¬è·å第ä¸ä¸ªå¹é
çåelement261 * Paramaters:262 * id - elementçid263 * name - é¢æåelementçname264 * Returns:265 * id - åæ§ä»¶çid266 */267 var root = uia_elements_cache.get(id);268 var elem = root.elements().firstWithName(name);269 return uia_elements_cache.append(elem);270 },271 'uia.element.with_name' : function(cmd_id, id, name) {272 /**273 * éè¿nameææ¬è·åå¹é
çåelements274 * Paramaters:275 * id - elementçid276 * name - é¢æåelementçname277 * Returns:278 * id - åæ§ä»¶çidéå279 */280 var root = uia_elements_cache.get(id);281 var elems = root.elements().withName(name);282 return uia_elements_cache.append_elements(elems);283 },284 'uia.element.first_with_predicate' : function(cmd_id, id, predicate) {285 /**286 * éè¿predicateææ¬è·å第ä¸ä¸ªå¹é
çåelement287 * Paramaters:288 * id - elementçid289 * predicate - é¢æåelementçpredicate ï¼ä¾å¦ï¼âname beginswith 'xxx'âï¼290 * Returns:291 * id - åæ§ä»¶çid292 */293 var root = uia_elements_cache.get(id);294 var elem = root.elements().firstWithPredicate(predicate);295 return uia_elements_cache.append(elem);296 },297 'uia.element.with_predicate' : function(cmd_id, id, predicate) {298 /**299 * éè¿predicateææ¬è·åå¹é
çåelements300 * Paramaters:301 * id - elementçid302 * predicate - é¢æåelementçpredicate ï¼ä¾å¦ï¼âname beginswith âxxx'âï¼303 * Returns:304 * id - åæ§ä»¶çidéå305 */306 var root = uia_elements_cache.get(id);307 var elems = root.elements().withPredicate(predicate);308 return uia_elements_cache.append_elements(elems);309 },310 'uia.element.first_with_value_for_key' : function(cmd_id, id, key, value) {311 /**312 * éè¿å¹é
æå®keyçvalueï¼è·å第ä¸ä¸ªå¹é
çåelement313 * Paramaters:314 * id - elementçid315 * key - key ï¼ä¾å¦ï¼labelãnameãvalueï¼316 * value - 对åºkeyçvalueå¼317 * Returns:318 * id - åæ§ä»¶çid319 */320 var root = uia_elements_cache.get(id);321 var elem = root.elements().firstWithValueForKey(value, key);322 return uia_elements_cache.append(elem);323 },324 'uia.element.with_value_for_key' : function(cmd_id, id, key, value) {325 /**326 * éè¿å¹é
æå®keyçvalueï¼è·åå¹é
çåelements327 * Paramaters:328 * id - elementçid329 * key - key ï¼ä¾å¦ï¼labelãnameãvalueï¼330 * value - 对åºkeyçvalueå¼331 * Returns:332 * id - åæ§ä»¶çidéå333 */334 var root = uia_elements_cache.get(id);335 var elems = root.elements().withValueForKey(value, key);336 return uia_elements_cache.append_elements(elems);337 },338 'uia.element.get_parent' : function(cmd_id, id) {339 /**340 * è·åæå®elementçç¶elementçid341 * Paramaters:342 * id - elementçid343 * Returns:344 * id - ç¶elementçid345 */346 var parent = uia_elements_cache.get(id).parent();347 return parent ? uia_elements_cache.append(parent) : undefined;348 },349 'uia.element.get_children' : function(cmd_id, id) {350 /**351 * è·åæå®elementçåelementséå352 * Paramaters:353 * id - elementçid354 * Returns:355 * [id, ...] - åelementsçidéå356 */357 var elements = uia_elements_cache.get(id).elements();358 return elements.length > 0 ? uia_elements_cache.append_elements(elements) : [];359 },360 'uia.element.get_attr' : function(cmd_id, id, name) {361 /**362 * è·åæå®elementçå±æ§363 * Paramaters:364 * id - elementçid365 * name - å±æ§åï¼ä¾å¦: nameãlableãvalue366 * Returns:367 * attr value - è¿ååºç¡ç±»åçæ°æ®368 */369 var name = name.toLowerCase();370 if (new RegExp(/^isEnabled$|^enabled$|^isValid$|^valid$|^isVisible$|^visible$|^hasKeyboardFocus$|^focus$/i).test(name)) {371 switch (name) {372 case "isenabled":373 name = "isEnabled";374 break;375 case "enabled":376 name = "isEnabled";377 break;378 case "isvalid":379 name = "isValid";380 break;381 case "valid":382 name = "isValid";383 break;384 case "isvisible":385 name = "isVisible";386 break;387 case "visible":388 name = "isVisible";389 break;390 case "haskeyboardfocus":391 name = "hasKeyboardFocus";392 break;393 case "focus":394 name = "hasKeyboardFocus";395 break;396 };397 };398 return api['uia.element.function'](cmd_id, id, name);399 },400 'uia.element.get_rect' : function(cmd_id, id) {401 /**402 * è·åæå®elementçåæ åé¿å®½403 * Paramaters:404 * id - element id405 * Returns:406 * JSON - åæ åé¿å®½407 */408 return uia_elements_cache.get(id).rect();409 },410 'uia.element.capture' : function(cmd_id, id, path) {411 /**412 * æªå¾ï¼æªåæå®elementçå¾çï¼å¹¶å°å¾çè¾åºè³æå®çè·¯å¾ï¼413 * Paramaters:414 * path - å°å¾çåå¨è³è¯¥è·¯å¾ï¼pngæ ¼å¼ï¼ï¼ä¾å¦ï¼/Users/tester/Desktop/test.png415 * ä¸ä¼ è·¯å¾ æ è·¯å¾ä»
å«æ件åï¼åæªå¾ååå¨è³é»è®¤è·¯å¾ï¼é»è®¤è·¯å¾å
åå¨çå¾çæ¯æ¬¡éå¯é½ä¼è¢«æ¸
空ï¼ã416 */417 var rect = uia_elements_cache.get(id).rect();418 return api['uia.target.capture_rect'](cmd_id, rect, path);419 },420 'uia.element.tap' : function(cmd_id, id, x, y) {421 /**422 * ç¹å»æå®çelement423 * Paramaters:424 * id - element id425 * x - xåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°426 * y - yåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°427 */428 var element = uia_elements_cache.get(id);429 var rect = element.rect();430 var size = rect['size'];431 var x = size['width'] * x;432 var y = size['height'] * y;433 //element.scrollToVisible();434 element.tap(x, y);435 },436 'uia.element.double_tap' : function(cmd_id, id, x, y) {437 /**438 * åå»æå®çelement439 * Paramaters:440 * id - element id441 * x - xåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°442 * y - yåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°443 */444 if (x && y) {445 for (var i = 0; i < 2; i++) {446 api['uia.element.tap'](cmd_id, id, x, y);447 };448 } else {449 var element = uia_elements_cache.get(id);450 //element.scrollToVisible();451 element.doubleTap();452 };453 },454 'uia.element.tap_with_options' : function(cmd_id, id, options) {455 /**456 * èªå®ä¹ç¹å»457 * Paramaters:458 * id - element id459 * options = {460 * tapCount : 1, // 轻触次æ°461 * touchCount : 1, // 触æ¸ç¹462 * duration : 1, // æç»æ¶é´463 * tapOffset : { x: 1.0, y: 0.1 } // 轻触å移ç¾åæ¯464 * }465 */466 var element = uia_elements_cache.get(id);467 //element.scrollToVisible();468 element.tapWithOptions(options);469 },470 'uia.element.click' : function(cmd_id, id, x, y) {471 /**472 * ç¹å»æå®çelement(éé
QTA)473 * Paramaters:474 * id - element id475 * x - xåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°476 * y - yåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°477 */478 api['uia.element.tap'](cmd_id, id, x, y);479 },480 'uia.element.double_click' : function(cmd_id, id, x, y) {481 /**482 * åå»æå®çelement483 * Paramaters:484 * id - element id485 * x - xåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°486 * y - yåæ ï¼ç¸å¯¹äºå½åelementï¼ï¼å¯ä¸ä¼ å
¥è¯¥åæ°487 */488 api['uia.element.double_tap'](cmd_id, id, x, y);489 },490 'uia.element.drag_inside_with_options' : function(cmd_id, id, options) {491 /**492 * ææ½493 * Paramaters:494 * id - element id495 * options = {496 * touchCount : 1, // 触æ¸ç¹497 * duration : 0.5, // æ¶é´498 * startOffset : { x: 0.0, y: 0.1}, // å移ç¾åæ¯499 * endOffset : { x: 1.0, y: 0.1 }, // å移ç¾åæ¯500 * repeat : 1 // éå¤è¯¥æä½501 * interval : 0 // éå¤è¯¥æä½çé´éæ¶é´ï¼ç§ï¼502 * }503 */504 var repeat = options.repeat ? options.repeat : 1;505 var interval = options.interval ? options.interval : 0;506 for (var i = 0; i < repeat; i++) {507 uia_elements_cache.get(id).dragInsideWithOptions(options);508 if (repeat > 1 && interval > 0) {509 UIATarget.localTarget().delay(interval);510 };511 };512 },513 'uia.element.drag_inside_right_to_left' : function(cmd_id, id) {514 /**515 * åæå¨æ§ä»¶çä¸å¤®ä»å³åå·¦ææ½ï¼åé¿æ§ä»¶è¾¹ç¼ï¼ææ½è¿ç¨ä½¿ç¨1ç§ï¼516 */517 var _options = {518 touchCount : 1,519 duration : 1.5,520 startOffset : {521 x : 0.5,522 y : 0.5523 },524 endOffset : {525 x : 0.1,526 y : 0.5527 }528 };529 uia_elements_cache.get(id).dragInsideWithOptions(_options);530 },531 'uia.element.drag_inside_left_to_right' : function(cmd_id, id) {532 /**533 * åæå¨æ§ä»¶çä¸å¤®ä»å·¦åå³ææ½ï¼åé¿æ§ä»¶è¾¹ç¼ï¼ææ½è¿ç¨ä½¿ç¨1ç§ï¼534 */535 var _options = {536 touchCount : 1,537 duration : 1.5,538 startOffset : {539 x : 0.5,540 y : 0.5541 },542 endOffset : {543 x : 0.9,544 y : 0.5545 }546 };547 uia_elements_cache.get(id).dragInsideWithOptions(_options);548 },549 'uia.element.drag_inside_up_to_down' : function(cmd_id, id) {550 /**551 * åæå¨æ§ä»¶çä¸å¤®ä»ä¸åä¸ææ½ï¼åé¿æ§ä»¶è¾¹ç¼ï¼ææ½è¿ç¨ä½¿ç¨1ç§ï¼552 */553 var _options = {554 touchCount : 1,555 duration : 1.5,556 startOffset : {557 x : 0.5,558 y : 0.5559 },560 endOffset : {561 x : 0.5,562 y : 0.9563 }564 };565 uia_elements_cache.get(id).dragInsideWithOptions(_options);566 },567 'uia.element.drag_inside_down_to_up' : function(cmd_id, id) {568 /**569 * åæå¨æ§ä»¶çä¸å¤®ä»ä¸åä¸ææ½ï¼åé¿æ§ä»¶è¾¹ç¼ï¼ææ½è¿ç¨ä½¿ç¨1ç§ï¼570 */571 var _options = {572 touchCount : 1,573 duration : 1.5,574 startOffset : {575 x : 0.5,576 y : 0.5577 },578 endOffset : {579 x : 0.5,580 y : 0.1581 }582 };583 uia_elements_cache.get(id).dragInsideWithOptions(_options);584 },585 'uia.element.flick_inside_with_options' : function(cmd_id, id, options) {586 /**587 * å¼¹å»/æå»588 * Paramaters:589 * id - element id590 * options = {591 * touchCount : 1, // 触æ¸ç¹592 * startOffset : { x: 0.5, y: 0.9 }, // å移ç¾åæ¯593 * endOffset : { x: 1.0, y: 0.9 } // å移ç¾åæ¯594 * repeat : 1 // éå¤è¯¥æä½595 * interval : 0 // éå¤è¯¥æä½çé´éæ¶é´ï¼ç§ï¼596 * }597 */598 var repeat = options.repeat ? options.repeat : 1;599 var interval = options.interval ? options.interval : 0;600 for (var i = 0; i < repeat; i++) {601 uia_elements_cache.get(id).flickInsideWithOptions(options);602 if (repeat > 1 && interval > 0) {603 UIATarget.localTarget().delay(interval);604 };605 };606 },607 'uia.element.flick_inside_right_to_left' : function(cmd_id, id) {608 /**609 * åæå¨æ§ä»¶ä¸å¤®ä»å³å左弹å»/æå»ï¼åé¿æ§ä»¶è¾¹ç¼ï¼610 */611 var _options = {612 touchCount : 1,613 startOffset : {614 x : 0.5,615 y : 0.5616 },617 endOffset : {618 x : 0.1,619 y : 0.5620 }621 };622 uia_elements_cache.get(id).flickInsideWithOptions(_options);623 },624 'uia.element.flick_inside_left_to_right' : function(cmd_id, id) {625 /**626 * åæå¨æ§ä»¶ä¸å¤®ä»å·¦åå³å¼¹å»/æå»ï¼åé¿æ§ä»¶è¾¹ç¼ï¼627 */628 var _options = {629 touchCount : 1,630 startOffset : {631 x : 0.5,632 y : 0.5633 },634 endOffset : {635 x : 0.9,636 y : 0.5637 }638 };639 uia_elements_cache.get(id).flickInsideWithOptions(_options);640 },641 'uia.element.flick_inside_up_to_down' : function(cmd_id, id) {642 /**643 * åæå¨æ§ä»¶ä¸å¤®ä»ä¸åä¸å¼¹å»/æå»ï¼åé¿æ§ä»¶è¾¹ç¼ï¼644 */645 var _options = {646 touchCount : 1,647 startOffset : {648 x : 0.5,649 y : 0.5650 },651 endOffset : {652 x : 0.5,653 y : 0.9654 }655 };656 uia_elements_cache.get(id).flickInsideWithOptions(_options);657 },658 'uia.element.flick_inside_down_to_up' : function(cmd_id, id) {659 /**660 * åæå¨æ§ä»¶ä¸å¤®ä»ä¸åä¸å¼¹å»/æå»ï¼åé¿æ§ä»¶è¾¹ç¼ï¼661 */662 var _options = {663 touchCount : 1,664 startOffset : {665 x : 0.5,666 y : 0.5667 },668 endOffset : {669 x : 0.5,670 y : 0.1671 }672 };673 uia_elements_cache.get(id).flickInsideWithOptions(_options);674 },675 'uia.element.rotate_with_options' : function(cmd_id, id, options) {676 /**677 * æ转678 * Paramaters:679 * id - element id680 * options = {681 * centerOffset : {x:0.0, y:0.0}, // ä¸å¿ç¹682 * duration : 1.5, // æç»æ¶é´683 * radius : 100, // åå¾684 * rotation : 100, // æ转弧度çé¿åº¦ï¼é»è®¤ä¸ºåå¨çPI685 * touchCount : 2 // 触æ¸ç¹ï¼æ大5个ç¹ï¼è¿éé»è®¤2个ï¼686 * }687 */688 uia_elements_cache.get(id).rotateWithOptions(options);689 },690 'uia.element.scroll_to_visible' : function(cmd_id, id) {691 /**692 * èªå¨æ»å¨å°è¯¥element为å¯è§693 * Paramaters:694 * id - element id695 */696 uia_elements_cache.get(id).scrollToVisible();697 // --- --- --- retryæ æ698 //var element = uia_elements_cache.get(id);699 //var retry = retry ? retry : 5;700 //var target = UIATarget.localTarget();701 //var error = null;702 //for (var i = 0; i < retry; i++) {703 // try {704 // element.scrollToVisible();705 // return;706 // } catch(e) {707 // target.delay(1);708 // error = e;709 // };710 //};711 //throw error;712 // --- --- ---713 },714 'uia.element.touch_and_hold' : function(cmd_id, id, duration) {715 /**716 * æç»æä½717 * Paramaters:718 * id - element id719 * duration - æä½å¤é¿æ¶é´ï¼ç§ï¼720 */721 uia_elements_cache.get(id).touchAndHold(duration);722 },723 'uia.element.two_finger_tap' : function(cmd_id, id) {724 /**725 * äºæ轻触726 * Paramaters:727 * id - element id728 */729 uia_elements_cache.get(id).twoFingerTap();730 },731 'uia.element.wait_for_invalid' : function(cmd_id, id, timeout) {732 /**733 * çå¾
å½åelementç´å°æ æ734 * Paramaters:735 * id - element id736 * timeout - è¶
æ¶å¼ï¼ç§ï¼737 */738 var element = uia_elements_cache.get(id);739 var timeout = timeout ? timeout : 5;740 var target = UIATarget.localTarget();741 target.pushTimeout(timeout);742 var result = element.waitForInvalid();743 target.popTimeout();744 return result;745 },746 'uia.element.set_value' : function(cmd_id, id, value) {747 /**748 * 设置æå®elementçvalue749 * Paramaters:750 * id - element id751 * value - å¼752 */753 uia_elements_cache.get(id).setValue(value);754 },755 'uia.element.drag_to_value' : function(cmd_id, id, value) {756 /**757 * 设置æå®sliderçvalue758 * Paramaters:759 * id - element id760 * value - å¼761 */762 uia_elements_cache.get(id).dragToValue(value);763 }, 764 'uia.element.sent_keys' : function(cmd_id, id, keys) {765 /**766 * å¨æå®elementä¸é®çè¾å
¥767 * Paramaters:768 * id - element id769 * keys - é®å
¥çå符串770 */771 var elem = uia_elements_cache.get(id);772 elem.tap();773 elem.typeString(keys);774 },775 'uia.element.get_element_dict' : function(cmd_id, id) {776 /**777 * è·åæå®elementçå±æ§ä¿¡æ¯778 * Returns779 * JSON String - å±æ§780 */781 var dict = uia_elements_cache.get(id).getElementDict();782 var result = encodeURIComponent($.str.objectToString(dict, true));783 $.log("TORPC: " + $.str.objectToString({784 'id' : cmd_id,785 'result' : result786 }));787 return api.DoNotReturn;788 },789 'uia.element.log_element_dict' : function(cmd_id, id) {790 /**791 * æå°å¹¶è·åæå®elementçå±æ§ä¿¡æ¯792 * Returns793 * JSON String - å±æ§794 */795 var dict = uia_elements_cache.get(id).logElementDict();796 var result = encodeURIComponent($.str.objectToString(dict, true));797 $.log("TORPC: " + $.str.objectToString({798 'id' : cmd_id,799 'result' : result800 }));801 return api.DoNotReturn;802 },803 'uia.element.get_element_tree' : function(cmd_id, id) {804 /**805 * è·åæå®elementçææååelementæ 806 * Paramaters:807 * id - elementçid808 * Returns:809 * JSON - ååèç¹æ 810 */811 var dict = uia_elements_cache.get(id).getElementTree();812 var result = encodeURIComponent($.str.objectToString(dict, true));813 $.log("TORPC: " + $.str.objectToString({814 'id' : cmd_id,815 'result' : result816 }));817 return api.DoNotReturn;818 },819 'uia.element.log_element_tree_ext' : function(cmd_id, id) {820 /**821 * ä»æå®elementå¼å§è·åUIæ 822 * Returns823 * JSON String - UIæ 824 */825 var dict = uia_elements_cache.get(id).logElementTreeExt();826 var result = encodeURIComponent($.str.objectToString(dict, true));827 $.log("TORPC: " + $.str.objectToString({828 'id' : cmd_id,829 'result' : result830 }));831 return api.DoNotReturn;832 },833 // -*- -*- -*- -*- -*- -*-834 'uia.application.function' : function(cmd_id, func, args) {835 /**836 * è°ç¨UIAApplicationçåçå½æ°837 * Paramaters:838 * func - å½æ°å839 * args - å½æ°çæåºåæ°é840 * Returns:841 * return value - 被è°ç¨å½æ°çè¿åå¼ï¼åºç¡ç±»åï¼842 */843 var app = UIATarget.localTarget().frontMostApp();844 var args = args ? args : [];845 if (app[func]) {846 return app[func].apply(app, args);847 };848 throw new Error('uia.application.function "func: ' + func + '" is invalid.');849 },850 //'uia.application.get_attr' : function(cmd_id, name) {851 // /**852 // * è·åUIAApplicationçå±æ§853 // * Paramaters:854 // * name - å±æ§åï¼ä¾å¦: nameãlableãvalue855 // * Returns:856 // * attr value - è¿ååºç¡ç±»åçæ°æ®857 // */858 // return api['uia.application.function'](cmd_id, name);859 //},860 'uia.application.get_main_window' : function(cmd_id) {861 /**862 * è·åAppç主çªå£863 * Returns864 * id - elementçid865 */866 return uia_elements_cache.append(UIATarget.localTarget().frontMostApp().mainWindow());867 },868 'uia.application.get_interface_orientation' : function(cmd_id) {869 /**870 * è·åæ¥å£æ¹å871 * Returns872 * number - 表示æ¹å873 */874 return UIATarget.localTarget().frontMostApp().interfaceOrientation();875 },876 'uia.application.get_app_bundle_id' : function(cmd_id) {877 /**878 * è·åAppçbundleID879 * Returns880 * string - bundleID881 */882 return UIATarget.localTarget().frontMostApp().bundleID();883 },884 'uia.application.get_app_version' : function(cmd_id) {885 /**886 * è·åAppçversion887 * Returns888 * string - version889 */890 return UIATarget.localTarget().frontMostApp().version();891 },892 // -*- -*- -*- -*- -*- -*-893 'uia.target.function' : function(cmd_id, func, args) {894 /**895 * è°ç¨UIATargetçåçå½æ°ï¼æ³¨ï¼deviceå½å空é´å¯¹åºUIATarget对象ï¼896 * Paramaters:897 * func - å½æ°å898 * args - å½æ°çæåºåæ°é899 * Returns:900 * return value - 被è°ç¨å½æ°çè¿åå¼ï¼åºç¡ç±»åï¼901 */902 var target = UIATarget.localTarget();903 var args = args ? args : [];904 if (target[func]) {905 return target[func].apply(target, args);906 };907 throw new Error('uia.target.function "func: ' + func + '" is invalid.');908 },909 //'uia.target.get_attr' : function(cmd_id, name) {910 // /**911 // * è·åUIATargetçå±æ§912 // * Paramaters:913 // * name - å±æ§åï¼ä¾å¦: nameãlableãvalue914 // * Returns:915 // * attr value - è¿ååºç¡ç±»åçæ°æ®916 // */917 // return api['uia.target.function'](cmd_id, name);918 //},919 'uia.target.get_rect' : function(cmd_id) {920 /**921 * è·å设å¤å±å¹å¤§å°922 * Returns:923 * 宽é«924 */925 return UIATarget.localTarget().rect();926 },927 'uia.target.get_model' : function(cmd_id) {928 /**929 * è·å设å¤æ¨¡å930 * Returns:931 * string932 */933 return UIATarget.localTarget().model();934 },935 'uia.target.get_name' : function(cmd_id) {936 /**937 * è·å设å¤å938 * Returns:939 * string940 */941 return UIATarget.localTarget().name();942 },943 'uia.target.get_system_name' : function(cmd_id) {944 /**945 * è·åç³»ç»å946 * Returns:947 * string948 */949 return UIATarget.localTarget().systemName();950 },951 'uia.target.get_system_version' : function(cmd_id) {952 /**953 * è·åç³»ç»çæ¬954 * Returns:955 * string956 */957 return UIATarget.localTarget().systemVersion();958 },959 'uia.target.capture_rect' : function(cmd_id, rect, path) {960 /**961 * æªå¾ï¼æå®åºåæªå¾ï¼å¹¶å°å¾çè¾åºè³æå®çè·¯å¾ï¼962 * Paramaters:963 * rect - æå®åºå964 * {965 * origin : { x: xposition, y: yposition },966 * size : { width: widthvalue, height: heightvalue}967 * }968 * path - å°å¾çåå¨è³è¯¥è·¯å¾ï¼pngæ ¼å¼ï¼ï¼ä¾å¦ï¼/Users/tester/Desktop/test.png969 * ä¸ä¼ è·¯å¾ æ è·¯å¾ä»
å«æ件åï¼åæªå¾ååå¨è³é»è®¤è·¯å¾ï¼é»è®¤è·¯å¾å
åå¨çå¾çæ¯æ¬¡éå¯é½ä¼è¢«æ¸
空ï¼ã970 */971 var name = String(new Date().getTime());972 if (path) {973 var nodes = path.split('/');974 if (nodes[nodes.length - 1].length > 0) {975 name = nodes[nodes.length - 1].replace(/\.\w{3,4} *$/, '');976 nodes[nodes.length - 1] = name;977 };978 path = nodes.join('/');979 };980 if (!new RegExp('^/').test(path)) {981 path = [Environment.screen_shot_path, name].join('/');982 };983 UIATarget.localTarget().captureRectWithName(rect, name);984 name += '.png';985 path += '.png';986 $.log('ScreenshotCaptured: {"name": "' + name + '", "path": "' + path + '"}');987 return path;988 },989 'uia.target.capture_screen' : function(cmd_id, path) {990 /**991 * æªå±(å°è¾åºå¾çè³æå®çè·¯å¾)992 * Paramaters:993 * path - å°å¾çåå¨è³è¯¥è·¯å¾ï¼pngæ ¼å¼ï¼ï¼ä¾å¦ï¼/Users/tester/Desktop/test.png994 * - ä¸ä¼ è·¯å¾ æ è·¯å¾ä»
å«æ件åï¼åæªå¾ååå¨è³é»è®¤è·¯å¾ï¼é»è®¤è·¯å¾å
åå¨çå¾çæ¯æ¬¡éå¯é½ä¼è¢«æ¸
空ï¼ã995 */996 var name = String(new Date().getTime());997 if (path) {998 var nodes = path.split('/');999 if (nodes[nodes.length - 1].length > 0) {1000 name = nodes[nodes.length - 1].replace(/\.\w{3,4} *$/, '');1001 nodes[nodes.length - 1] = name;1002 };1003 path = nodes.join('/');1004 };1005 if (!new RegExp('^/').test(path)) {1006 path = [Environment.screen_shot_path, name].join('/');1007 };1008 UIATarget.localTarget().captureScreenWithName(name);1009 name += '.png';1010 path += '.png';1011 $.log('ScreenshotCaptured: {"name": "' + name + '", "path": "' + path + '"}');1012 return path;1013 },1014 'uia.target.get_element_tree_and_capture_screen' : function(cmd_id, path) {1015 /**1016 * è·åUIæ 并æªå±ï¼è¾åºçJSONå符串æ°æ®éè¦URL解ç ï¼1017 * Paramaters:1018 * path - å°å¾çåå¨è³è¯¥è·¯å¾ï¼pngæ ¼å¼ï¼ï¼ä¾å¦ï¼/Users/tester/Desktop/test.png1019 * - ä¸ä¼ è·¯å¾ æ è·¯å¾ä»
å«æ件åï¼åæªå¾ååå¨è³é»è®¤è·¯å¾ï¼é»è®¤è·¯å¾å
åå¨çå¾çæ¯æ¬¡éå¯é½ä¼è¢«æ¸
空ï¼ã1020 * Returns:1021 * Dict - { element_tree: {}, capture_screen: file_path }1022 */1023 $.log("TORPC: " + $.str.objectToString({1024 'id' : cmd_id,1025 'result' : encodeURIComponent($.str.objectToString({1026 element_tree : UIATarget.localTarget().getElementTree(),1027 capture_screen : api['uia.target.capture_screen'](cmd_id, path)1028 }, true))1029 }));1030 return api.DoNotReturn;1031 },1032 'uia.target.set_rules_of_alert_auto_handle' : function(cmd_id, rules) {1033 /**1034 * 设置èªå¨å¤çAlertè§å1035 * Paramaters:1036 * rules = [ {"message_text": "message_text", "button_text": "button_text"}, ... ]1037 * message_text - (æ¯ææ£å表达å¼)å¨Alertå
ææElementçææ¬ä¸çæææ¬ï¼åä¸Elementçlabelãnameãvalueï¼çäºä¸æ®µææ¬ãå
¶ä¸ä¸é¡¹å¹é
å³å¯ãï¼1038 * button_text - (æ¯ææ£å表达å¼)å¨Alertå
çå¹é
ææ¬çæé®ï¼UIAButtonçlabelãnameãvalueï¼çäºä¸æ®µææ¬ãå
¶ä¸ä¸é¡¹å¹é
å³å¯ãï¼1039 */1040 rules_of_alert_auto_handle = rules;1041 },1042 'uia.target.get_rules_of_alert_auto_handle' : function(cmd_id) {1043 /**1044 * æ¥è¯¢å·²è®¾ç½®çèªå¨å¤çAlertè§å1045 * Returns:1046 * list - [ {"message_text": "message_text", "button_text": "button_text"}, ... ]1047 */1048 return encodeURIComponent($.str.objectToString(rules_of_alert_auto_handle, true));1049 },1050 'uia.target.add_rule_of_alert_auto_handle' : function(cmd_id, message_text, button_text) {1051 /**1052 * èªå¨å¤çAlertè§åå¢å ä¸é¡¹1053 * Paramaters:1054 * message_text - (æ¯ææ£å表达å¼)å¨Alertå
ææElementçææ¬ä¸çæææ¬ï¼åä¸Elementçlabelãnameãvalueï¼çäºä¸æ®µææ¬ãå
¶ä¸ä¸é¡¹å¹é
å³å¯ãï¼1055 * button_text - (æ¯ææ£å表达å¼)å¨Alertå
çå¹é
ææ¬çæé®ï¼UIAButtonçlabelãnameãvalueï¼çäºä¸æ®µææ¬ãå
¶ä¸ä¸é¡¹å¹é
å³å¯ãï¼1056 */1057 rules_of_alert_auto_handle.push({1058 message_text : message_text,1059 button_text : button_text1060 });1061 },1062 'uia.target.clean_rules_of_alert_auto_handle' : function(cmd_id) {1063 /**1064 * æ¸
é¤ææèªå¨å¤çAlertçè§å1065 */1066 rules_of_alert_auto_handle = new Array();1067 },1068 'uia.target.turn_on_auto_close_alert' : function(cmd_id) {1069 /**1070 * æå¼èªå¨å
³éalertæ¡(å¦ærules_of_alert_auto_handleæ å¹é
ï¼å交ç±ç³»ç»èªå¨å
³é)1071 */1072 flag_alert_auto_handled = false;1073 // ææ¹æªå¤çï¼UIAé»è®¤èªå¨å¤ç1074 },1075 'uia.target.turn_off_auto_close_alert' : function(cmd_id) {1076 /**1077 * å
³éèªå¨å
³éalertæ¡1078 */1079 flag_alert_auto_handled = true;1080 // ææ¹å·²å¤çï¼UIAä¸åèªå¨å¤ç1081 },1082 'uia.target.get_last_alert_msg' : function(cmd_id) {1083 /**1084 * è·åæè¿ä¸æ¬¡alertæ¡çæ示å
容1085 * Returns1086 * msg - ææ¬å
容1087 */1088 return last_alert_msg;1089 },1090 'uia.target.delay' : function(cmd_id, seconds) {1091 /**1092 * çå¾
1093 * Paramaters:1094 * seconds - ç§1095 */1096 UIATarget.localTarget().delay(seconds);1097 },1098 'uia.target.get_element_tree' : function(cmd_id) {1099 /**1100 * ä»é¡¶å±å¼å§è·åUIæ ï¼è¾åºçJSONå符串æ°æ®éè¦URL解ç ï¼1101 * Returns1102 * JSON String - UIæ 1103 */1104 var dict = UIATarget.localTarget().getElementTree();1105 var result = encodeURIComponent($.str.objectToString(dict, true));1106 $.log("TORPC: " + $.str.objectToString({1107 'id' : cmd_id,1108 'result' : result1109 }));1110 return api.DoNotReturn;1111 },1112 'uia.target.log_element_tree_ext' : function(cmd_id) {1113 /**1114 * ä»é¡¶å±å¼å§è·åUIæ ï¼è¾åºçJSONå符串æ°æ®éè¦URL解ç ï¼1115 * Returns1116 * JSON String - UIæ 1117 */1118 var dict = UIATarget.localTarget().logElementTreeExt();1119 var result = encodeURIComponent($.str.objectToString(dict, true));1120 $.log("TORPC: " + $.str.objectToString({1121 'id' : cmd_id,1122 'result' : result1123 }));1124 return api.DoNotReturn;1125 },1126 'uia.target.click_volume_down' : function(cmd_id) {1127 /**1128 * æä¸ä¸æ¬¡åå°é³éæé®1129 */1130 UIATarget.localTarget().clickVolumeDown();1131 },1132 'uia.target.click_volume_up' : function(cmd_id) {1133 /**1134 * æä¸ä¸æ¬¡å¢å é³éæé®1135 */1136 UIATarget.localTarget().clickVolumeUp();1137 },1138 'uia.target.hold_volume_down' : function(cmd_id, seconds) {1139 /**1140 * æç»æä½åå°é³éæé®1141 * * Paramaters:1142 * seconds - ç§1143 */1144 var seconds = seconds ? seconds : 1;1145 UIATarget.localTarget().holdVolumeDown(seconds);1146 },1147 'uia.target.hold_volume_up' : function(cmd_id, seconds) {1148 /**1149 * æç»æä½å¢å é³éæé®1150 * * Paramaters:1151 * seconds - ç§1152 */1153 var seconds = seconds ? seconds : 1;1154 UIATarget.localTarget().holdVolumeUp(seconds);1155 },1156 'uia.target.deactivate_app_ror_duration' : function(cmd_id, seconds) {1157 /**1158 * å°Appç½®äºåå°ä¸å®æ¶é´1159 * Paramaters:1160 * seconds - ç§1161 * Returns1162 * Boolean1163 */1164 var seconds = seconds ? seconds : 3;1165 return UIATarget.localTarget().deactivateAppForDuration(seconds);1166 },1167 'uia.target.get_device_orientation' : function(cmd_id) {1168 /**1169 * è·å设å¤çæ¹å1170 * Returns1171 * Number1172 * UIA_DEVICE_ORIENTATION_UNKNOWN1173 * UIA_DEVICE_ORIENTATION_PORTRAIT1174 * UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN1175 * UIA_DEVICE_ORIENTATION_LANDSCAPELEFT1176 * UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT1177 * UIA_DEVICE_ORIENTATION_FACEUP1178 * UIA_DEVICE_ORIENTATION_FACEDOWN1179 */1180 return UIATarget.localTarget().deviceOrientation();1181 },1182 'uia.target.tap' : function(cmd_id, point) {1183 /**1184 * åå»1185 * Paramaters:1186 * point - { x: 0.5, y: 0.5 }1187 */1188 var _rect = UIATarget.localTarget().rect();1189 var _point = point ? point : {};1190 _point.x = _point.x ? _rect.size.width * _point.x : _rect.size.width * 0.5;1191 _point.y = _point.y ? _rect.size.height * _point.y : _rect.size.height * 0.5;1192 UIATarget.localTarget().tap(_point);1193 },1194 'uia.target.double_tap' : function(cmd_id, point) {1195 /**1196 * åå»1197 * Paramaters:1198 * point - { x: 100, y: 100 }1199 */1200 var _rect = UIATarget.localTarget().rect();1201 var _point = point ? point : {};1202 _point.x = _point.x ? _point.x : _rect.size.width * 0.5;1203 _point.y = _point.y ? _point.y : _rect.size.height * 0.5;1204 UIATarget.localTarget().doubleTap(_point);1205 },1206 'uia.target.tap_with_options' : function(cmd_id, point, options) {1207 /**1208 * åå»1209 * Paramaters:1210 * point - { x: 100, y: 100 }1211 * options - {1212 * tapCount : 1, å 次ï¼é»è®¤1次1213 * touchCount : 1, å ç¹ï¼é»è®¤1个ç¹ï¼ä¾å¦ä¸¤ä¸ªææå为2ï¼1214 * duration : 0 æä½çæ¶é´ï¼é»è®¤æ¯01215 * }1216 */1217 UIATarget.localTarget().tapWithOptions(point, options);1218 },1219 'uia.target.touch_and_hold' : function(cmd_id, point, duration) {1220 /**1221 * åå»1222 * Paramaters:1223 * point - { x: 100, y: 100 }1224 * duration - æä½å¤å°ç§1225 */1226 UIATarget.localTarget().touchAndHold(point, duration);1227 },1228 'uia.target.drag_from_to_for_duration' : function(cmd_id, from_point, to_point, duration, repeat, interval) {1229 /**1230 * ææ½1231 * Paramaters:1232 * from_point - { x: 0.5, y: 0.9 } // å移ç¾åæ¯1233 * to_point - { x: 0.5, y: 0.1 } // å移ç¾åæ¯1234 * duration - æç»æ¶é´ï¼ç§ï¼1235 * repeat - éå¤è¯¥æä½1236 * interval - éå¤è¯¥æä½çé´éæ¶é´ï¼ç§ï¼1237 */1238 var rect = UIATarget.localTarget().rect();1239 var from_point = {1240 x : Math.floor(rect.size.width * from_point.x),1241 y : Math.floor(rect.size.height * from_point.y)1242 };1243 var to_point = {1244 x : Math.floor(rect.size.width * to_point.x),1245 y : Math.floor(rect.size.height * to_point.y)1246 };1247 var duration = duration ? duration : 0.5;1248 var repeat = repeat ? repeat : 1;1249 var interval = interval ? interval : 0;1250 for (var i = 0; i < repeat; i++) {1251 UIATarget.localTarget().dragFromToForDuration(from_point, to_point, duration);1252 if (repeat > 1 && interval > 0) {1253 UIATarget.localTarget().delay(interval);1254 };1255 };1256 },1257 'uia.target.drag_right_to_left' : function(cmd_id) {1258 /**1259 * å±å¹ä¸å¤®ä»å³åå·¦ææ½ï¼åé¿å±å¹è¾¹ç¼ï¼1260 */1261 var _from_point = {1262 x : 0.5,1263 y : 0.51264 };1265 var _to_point = {1266 x : 0.1,1267 y : 0.51268 };1269 api['uia.target.drag_from_to_for_duration'](cmd_id, _from_point, _to_point);1270 },1271 'uia.target.drag_left_to_right' : function(cmd_id) {1272 /**1273 * å±å¹ä¸å¤®ä»å·¦åå³ææ½ï¼åé¿å±å¹è¾¹ç¼ï¼1274 */1275 var _from_point = {1276 x : 0.5,1277 y : 0.51278 };1279 var _to_point = {1280 x : 0.9,1281 y : 0.51282 };1283 api['uia.target.drag_from_to_for_duration'](cmd_id, _from_point, _to_point);1284 },1285 'uia.target.drag_up_to_down' : function(cmd_id) {1286 /**1287 * å±å¹ä¸å¤®ä»ä¸åä¸ææ½ï¼åé¿å±å¹è¾¹ç¼ï¼1288 */1289 var _from_point = {1290 x : 0.5,1291 y : 0.51292 };1293 var _to_point = {1294 x : 0.5,1295 y : 0.91296 };1297 api['uia.target.drag_from_to_for_duration'](cmd_id, _from_point, _to_point);1298 },1299 'uia.target.drag_down_to_up' : function(cmd_id) {1300 /**1301 * å±å¹ä¸å¤®ä»ä¸åä¸ææ½ï¼åé¿å±å¹è¾¹ç¼ï¼1302 */1303 var _from_point = {1304 x : 0.5,1305 y : 0.51306 };1307 var _to_point = {1308 x : 0.5,1309 y : 0.11310 };1311 api['uia.target.drag_from_to_for_duration'](cmd_id, _from_point, _to_point);1312 },1313 'uia.target.flick_from_to' : function(cmd_id, from_point, to_point, repeat, interval) {1314 /**1315 * å¼¹å»/æå»1316 * Paramaters:1317 * from_point - { x: 0.5, y: 0.9 } // å移ç¾åæ¯1318 * to_point - { x: 0.5, y: 0.1 } // å移ç¾åæ¯1319 * repeat - éå¤è¯¥æä½1320 * interval - éå¤è¯¥æä½çé´éæ¶é´ï¼ç§ï¼1321 */1322 var rect = UIATarget.localTarget().rect();1323 var from_point = {1324 x : Math.floor(rect.size.width * from_point.x),1325 y : Math.floor(rect.size.height * from_point.y)1326 };1327 var to_point = {1328 x : Math.floor(rect.size.width * to_point.x),1329 y : Math.floor(rect.size.height * to_point.y)1330 };1331 var repeat = repeat ? repeat : 1;1332 var interval = interval ? interval : 0;1333 for (var i = 0; i < repeat; i++) {1334 UIATarget.localTarget().flickFromTo(from_point, to_point);1335 if (repeat > 1 && interval > 0) {1336 UIATarget.localTarget().delay(interval);1337 };1338 };1339 },1340 'uia.target.flick_right_to_left' : function(cmd_id) {1341 /**1342 * å±å¹ä¸å¤®ä»å³å左弹å»/æå»1343 */1344 var _from_point = {1345 x : 0.5,1346 y : 0.51347 };1348 var _to_point = {1349 x : 0.1,1350 y : 0.51351 };1352 api['uia.target.flick_from_to'](cmd_id, _from_point, _to_point);1353 },1354 'uia.target.flick_left_to_right' : function(cmd_id) {1355 /**1356 * å±å¹ä¸å¤®ä»å·¦åå³å¼¹å»/æå»1357 */1358 var _from_point = {1359 x : 0.5,1360 y : 0.51361 };1362 var _to_point = {1363 x : 0.9,1364 y : 0.51365 };1366 api['uia.target.flick_from_to'](cmd_id, _from_point, _to_point);1367 },1368 'uia.target.flick_up_to_down' : function(cmd_id) {1369 /**1370 * å±å¹ä¸å¤®ä»ä¸åä¸å¼¹å»/æå»1371 */1372 var _from_point = {1373 x : 0.5,1374 y : 0.51375 };1376 var _to_point = {1377 x : 0.5,1378 y : 0.91379 };1380 api['uia.target.flick_from_to'](cmd_id, _from_point, _to_point);1381 },1382 'uia.target.flick_down_to_up' : function(cmd_id) {1383 /**1384 * å±å¹ä¸å¤®ä»ä¸åä¸å¼¹å»/æå»1385 */1386 var _from_point = {1387 x : 0.5,1388 y : 0.51389 };1390 var _to_point = {1391 x : 0.5,1392 y : 0.11393 };1394 api['uia.target.flick_from_to'](cmd_id, _from_point, _to_point);1395 },1396 'uia.target.lock_for_duration' : function(cmd_id, duration) {1397 /**1398 * æç»éå®ä¸æ®µæ¶é´1399 * Paramaters:1400 * duration - æç»å¤ä¹
ï¼ç§ï¼1401 */1402 UIATarget.localTarget().lockForDuration(duration);1403 },1404 'uia.target.pinch_close_from_to_for_duration' : function(cmd_id, from_point, to_point, duration) {1405 /**1406 * æå1407 * Paramaters:1408 * from_point - { x: 100, y: 100 }1409 * to_point - { x: 200, y: 200 }1410 * duration - ä»èµ·ç¹è³ç»ç¹æ¶èçæ¶é´ï¼æ§å¶å¿«æ
¢ï¼1411 */1412 UIATarget.localTarget().pinchCloseFromToForDuration(from_point, to_point, duration);1413 },1414 'uia.target.pinch_open_from_to_for_duration' : function(cmd_id, from_point, to_point, duration) {1415 /**1416 * å±å¼1417 * Paramaters:1418 * from_point - { x: 100, y: 100 }1419 * to_point - { x: 200, y: 200 }1420 * duration - ä»èµ·ç¹è³ç»ç¹æ¶èçæ¶é´ï¼æ§å¶å¿«æ
¢ï¼1421 */1422 UIATarget.localTarget().pinchOpenFromToForDuration(from_point, to_point, duration);1423 },1424 'uia.target.rotate_with_options' : function(cmd_id, location, options) {1425 /**1426 * æ转1427 * Paramaters:1428 * location - { x: 100, y: 100 } ä¸å¿ç¹1429 * options - {1430 * duration : 1, æç»çæ¶é´ï¼ç§ï¼1431 * radius : 50, åå¾1432 * rotation : 100, åå¨ï¼é»è®¤æ¯åå¨çPI1433 * touchCount : 2 触æ¸ç¹æ°é 2 - 51434 * }1435 */1436 UIATarget.localTarget().rotateWithOptions(location, options);1437 },1438 'uia.target.set_device_orientation' : function(cmd_id, orientation) {1439 /**1440 * 设置设å¤çæ¹å1441 * Paramaters:1442 * orientation - 代表æ¹åçæ°å¼1443 * UIA_DEVICE_ORIENTATION_UNKNOWN1444 * UIA_DEVICE_ORIENTATION_PORTRAIT1445 * UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN1446 * UIA_DEVICE_ORIENTATION_LANDSCAPELEFT1447 * UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT1448 * UIA_DEVICE_ORIENTATION_FACEUP1449 * UIA_DEVICE_ORIENTATION_FACEDOWN1450 */1451 UIATarget.localTarget().setDeviceOrientation(orientation);1452 },1453 'uia.target.set_location' : function(cmd_id, coordinates) {1454 /**1455 * 设置设å¤çGPSåæ 1456 * Paramaters:1457 * coordinates - {1458 * latitude : 100, // 以度为åä½ç纬度ãæ£å¼è¡¨ç¤ºçº¬åº¦èµ¤é以åãè´å¼è¡¨ç¤ºçº¬åº¦èµ¤é以åã1459 * longitude : 100 // 以度为åä½çç»åº¦ãæµéæ¯ç¸å¯¹äºé¶åå线ï¼ç¨æ£å¼åä¸å»¶ä¼¸çç»ç»åç»ç»çè´å¼è¥¿ä¾§å»¶ä¼¸ã1460 * }1461 */1462 UIATarget.localTarget().setLocation(orientation);1463 },1464 'uia.target.set_location_with_options' : function(cmd_id, coordinates, options) {1465 /**1466 * 设置设å¤çGPSåæ 1467 * Paramaters:1468 * coordinates - {1469 * latitude : 100, // 以度为åä½ç纬度ãæ£å¼è¡¨ç¤ºçº¬åº¦èµ¤é以åãè´å¼è¡¨ç¤ºçº¬åº¦èµ¤é以åã1470 * longitude : 100 // 以度为åä½çç»åº¦ãæµéæ¯ç¸å¯¹äºé¶åå线ï¼ç¨æ£å¼åä¸å»¶ä¼¸çç»ç»åç»ç»çè´å¼è¥¿ä¾§å»¶ä¼¸ã1471 * }1472 * options - {1473 * altitude : 50, // æµ·æé«åº¦ï¼ä»¥ç±³ä¸ºåä½ï¼ç¸å¯¹äºæµ·å¹³é¢ãæ£å¼è¡¨ç¤ºæµ·æé«åº¦ãè´å¼è¡¨ç¤ºä½äºæµ·å¹³é¢çé«åº¦ã1474 * horizontalAccuracy : 10, // æ°´å¹³åå¾ï¼ä¸ç¡®ä½ç½®æ¶çèå´å
ï¼ä»¥ç±³ä¸ºåä½ãè´çå¼æ¯æ æçã1475 * verticalAccuracy : 10, // åç´åå¾ï¼ä¸ç¡®ä½ç½®æ¶çèå´å
ï¼ä»¥ç±³ä¸ºåä½ãè´çå¼æ¯æ æçã1476 * course : 1, // 设å¤æ¯ç§»å¨çï¼ä¸ç¡®å®ç§»å¨æ¹å1477 * speed : 1 // 移å¨é度ï¼ç±³/ç§ï¼1478 * }1479 */1480 UIATarget.localTarget().setLocationWithOptions(orientation, options);1481 },1482 'uia.target.shake' : function(cmd_id) {1483 /**1484 * ææ设å¤1485 */1486 UIATarget.localTarget().shake();1487 },1488 'uia.target.unlock' : function(cmd_id) {1489 /**1490 * 解é设å¤1491 */1492 UIATarget.localTarget().unlock();1493 },1494 'uia.target.lock' : function(cmd_id) {1495 /**1496 * éå®è®¾å¤1497 */1498 UIATarget.localTarget().lock();1499 },1500 'uia.keyboard.sent_keys' : function(cmd_id, keys) {1501 /**1502 * é®çè¾å
¥1503 */1504 UIATarget.localTarget().frontMostApp().keyboard().typeString(keys);1505 },1506 };...
FollowWorker.js
Source:FollowWorker.js
...726 const random1 = Math.floor(200 + Math.random()*200);727 const random2 = Math.floor(Math.random()*150);728 const random3 = Math.floor(Math.random()*147);729 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)730 await element.flick(0, -(random1 + random2), random1 + random3);731 await sleep(0);732 }733 } catch(e) {734 console.log(`ëì í¼ë보기 ìë¬: ${e.name}`);735 }736}737async function myDmView(running, driver) {738 try {739 await gotoMain(running, driver);740 const element = await driver.element("id", "action_bar_inbox_button");741 await element.click();742 const random = Math.floor(Math.random()*10);743 for (let i=0; i<random; i++) {744 const element = await driver.element("id", "inbox_refreshable_thread_list_recyclerview");745 const random1 = Math.floor(200 + Math.random()*200);746 const random2 = Math.floor(Math.random()*150);747 const random3 = Math.floor(Math.random()*147);748 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)749 await element.flick(0, -(random1 + random2), random1 + random3);750 await sleep(0);751 }752 const inboxs = await driver.elements("id", "row_inbox_container");753 const inbox = inboxs[Math.floor(Math.random()*inboxs.length)];754 inbox.click();755 const random2 = Math.floor(Math.random()*10);756 // console.log(`ëë¤ì¹´ì´í¸ : ${random2}`);757 for (let i=0; i<random2; i++) {758 const element = await driver.element("id", "message_list");759 const random1 = Math.floor(200 + Math.random()*200);760 const random2 = Math.floor(Math.random()*150);761 const random3 = Math.floor(Math.random()*147);762 // console.log(`${i} - flick(0, ${random1 + random2}, ${random1 + random3});`)763 await element.flick(0, random1 + random2, random1 + random3);764 await sleep(0);765 }766 } catch(e) {767 console.log(`ëì ëì 보기 ìë¬: ${e.name}`);768 console.log(e);769 }770}771async function viewStory(running, driver) {772 try {773 await gotoMain(running, driver);774 await sleep(2);775 const element = await driver.elements("id", "outer_container");776 await element[1].click();777 const random = Math.floor(40 + Math.random()*60);778 for (let i=0; i<random; i++) {779 const random1 = Math.floor(Math.random()*100);780 // console.log(`pass number : ${random1}`);781 if (random1 < 50) {782 const element = await driver.element("id", "bottom_sheet_container");783 const random1 = Math.floor(200 + Math.random()*200);784 const random2 = Math.floor(Math.random()*150);785 const random3 = Math.floor(Math.random()*147);786 // console.log(`${i} - flick(${-(random1 + random2)}, 0, ${random1 + random3});`)787 await element.flick(-(random1 + random2), 0, random1 + random3);788 }789 await rsleep(2, 10);790 }791 const back = await driver.element("id", "bottom_sheet_container");792 const random1 = Math.floor(800 + Math.random()*200);793 const random2 = Math.floor(Math.random()*150);794 const val = random1 + random2;795 await back.flick(0, val, Math.floor(val/10));796 } catch(e) {797 // console.log(`ëì viewStory ìë¬: ${e.name}`);798 console.log(e);799 }800}801async function myProfileView(running, driver) {802 try {803 await gotoMain(running, driver);804 const bottomBar = await driver.elements("id", "tab_icon");805 await bottomBar[4].click();806 const random = Math.floor(1 + Math.random()*10);807 for (let i=0; i<random; i++) {808 const element = await driver.element("id", "coordinator_root_layout");809 const random1 = Math.floor(200 + Math.random()*200);810 const random2 = Math.floor(Math.random()*150);811 const random3 = Math.floor(Math.random()*147);812 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)813 await element.flick(0, -(random1 + random2), random1 + random3);814 await sleep(0);815 }816 } catch(e) {817 console.log(`ëì í¼ë보기 ìë¬: ${e.name}`);818 }819}820async function myProfileFollowerView(running, driver) {821 try {822 await gotoMain(running, driver);823 const bottomBar = await driver.elements("id", "tab_icon");824 await bottomBar[4].click();825 await sleep(2);826 const element2 = await driver.element("id", "row_profile_header_followers_container");827 await element2.click();828 const random = Math.floor(1 + Math.random()*20);829 for (let i=0; i<random; i++) {830 const element = await driver.element("id", "layout_listview_parent_container");831 const random1 = Math.floor(10 + Math.random()*2000);832 const random2 = Math.floor(Math.random()*169);833 const random3 = Math.floor(Math.random()*152);834 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${Math.floor((random1 + random3)/10)});`)835 await element.flick(0, -(random1 + random2), Math.floor((random1 + random3)/10));836 await sleep(0);837 }838 } catch(e) {839 console.log(`ëì myProfileFollowerView ìë¬: ${e.name}`);840 console.log(e);841 }842}843async function myProfileFollowingView(running, driver) {844 try {845 await gotoMain(running, driver);846 const bottomBar = await driver.elements("id", "tab_icon");847 await bottomBar[4].click();848 await sleep(2);849 const element2 = await driver.element("id", "row_profile_header_following_container");850 await element2.click();851 const random = Math.floor(1 + Math.random()*20);852 for (let i=0; i<random; i++) {853 const element = await driver.element("id", "layout_listview_parent_container");854 const random1 = Math.floor(10 + Math.random()*2000);855 const random2 = Math.floor(Math.random()*179);856 const random3 = Math.floor(Math.random()*163);857 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${Math.floor((random1 + random3)/10)});`)858 await element.flick(0, -(random1 + random2), Math.floor((random1 + random3)/10));859 await sleep(0);860 }861 } catch(e) {862 console.log(`ëì myProfileFollowingView ìë¬: ${e.name}`);863 console.log(e);864 }865}866async function myActiveView(running, driver) {867 try {868 await gotoMain(running, driver);869 const bottomBar = await driver.elements("id", "tab_icon");870 await bottomBar[3].click();871 const random = Math.floor(5 + Math.random()*30);872 for (let i=0; i<random; i++) {873 const element = await driver.element("id", "newsfeed_pager");874 const random1 = Math.floor(200 + Math.random()*200);875 const random2 = Math.floor(Math.random()*150);876 const random3 = Math.floor(Math.random()*147);877 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)878 await element.flick(0, -(random1 + random2), random1 + random3);879 await sleep(0);880 }881 } catch(e) {882 console.log(`ëì myActiveView ìë¬: ${e.name}`);883 console.log(e);884 }885} 886async function searchView(running, driver) {887 try {888 await gotoMain(running, driver);889 const bottomBar = await driver.elements("id", "tab_icon");890 await bottomBar[1].click();891 const random = Math.floor(10 + Math.random()*60);892 for (let i=0; i<random; i++) {893 const element = await driver.element("id", "recycler_view");894 const random1 = Math.floor(200 + Math.random()*200);895 const random2 = Math.floor(Math.random()*150);896 const random3 = Math.floor(Math.random()*147);897 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)898 await element.flick(0, -(random1 + random2), random1 + random3);899 await rsleep(0, 4);900 }901 } catch(e) {902 console.log(`ëì searchView ìë¬: ${e.name}`);903 }904}905async function searchImageView(running, driver) {906 try {907 await gotoMain(running, driver);908 const bottomBar = await driver.elements("id", "tab_icon");909 await bottomBar[1].click();910 await sleep(2);911 const imageElements = await driver.elements("id", "image_button");912 const key = Math.floor(Math.random()*imageElements.length);913 await imageElements[key].click();914 const random = Math.floor(10 + Math.random()*60);915 for (let i=0; i<random; i++) {916 const element = await driver.element("id", "sticky_header_list");917 const random1 = Math.floor(200 + Math.random()*200);918 const random2 = Math.floor(Math.random()*151);919 const random3 = Math.floor(Math.random()*148);920 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)921 await element.flick(0, -(random1 + random2), random1 + random3);922 await rsleep(0, 2);923 }924 } catch(e) {925 console.log(`ëì searchImageView ìë¬: ${e.name}`);926 console.log(e);927 }928}929async function randomProfileView(running, driver) {930 try {931 await gotoMain(running, driver);932 const bottomBar = await driver.elements("id", "tab_icon");933 await bottomBar[1].click();934 await rsleep(2, 3);935 const imageElements = await driver.elements("id", "image_button");936 const key = Math.floor(Math.random()*imageElements.length);937 await imageElements[key].click();938 await rsleep(0, 1);939 const profileName = await driver.elements("id", "row_feed_photo_profile_name");940 await profileName[0].click();941 const random = Math.floor(1 + Math.random()*10);942 for (let i=0; i<random; i++) {943 const element = await driver.element("id", "coordinator_root_layout");944 const random1 = Math.floor(200 + Math.random()*200);945 const random2 = Math.floor(Math.random()*155);946 const random3 = Math.floor(Math.random()*152);947 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)948 await element.flick(0, -(random1 + random2), random1 + random3);949 await sleep(0);950 }951 } catch(e) {952 console.log(`ëì randomProfileView ìë¬: ${e.name}`);953 console.log(e);954 }955}956async function gotoMain(running, driver) {957 let count = 0;958 while(running.state) {959 if (count > 10) {960 break;961 }962 try {963 let backButton1 = await driver.elements("id", "action_bar_button_back");964 let backButton2 = await driver.elements("id", "action_bar_cancel");965 let backButton3 = await driver.elements("id", "close_button");966 if (backButton1[0]) {967 await backButton1[0].click();968 } else if(backButton2[0]) {969 await backButton2[0].click();970 } else if(backButton3[0]) {971 await backButton3[0].click();972 } else {973 const element = await driver.elements("id", "tab_icon");974 if (element.length > 3) {975 break;976 } else {977 await driver.back();978 }979 }980 } catch(e) { break; }981 count += 1;982 await sleep(1);983 }984}985async function recentPost(running, driver, hashtag) {986 while(running.state) {987 let count = 0;988 try {989 await gotoMain(running, driver);990 const elementTwo = await driver.elements("id", "tab_icon");991 await elementTwo[1].click();992 let searchEditText = await driver.element("id", "action_bar_search_edit_text");993 await searchEditText.click();994 await searchEditText.type(hashtag);995 await driver.hideDeviceKeyboard();996 let searchHashs = await driver.elements("id", "row_hashtag_textview_tag_name");997 let searchTag = null;998 for (let searchHash of searchHashs) {999 let name = await searchHash.text();1000 if (name === `#${hashtag}`) {1001 searchTag = searchHash;1002 break;1003 }1004 }1005 await searchTag.click();1006 break;1007 } catch(e) {1008 count += 1;1009 if (count > 10) {1010 throw {name: 'No SearchHash'};1011 }1012 await sleep(1);1013 }1014 }1015 1016 await sleep(3);1017 while(running.state) {1018 let count = 0;1019 try {1020 let tabButtons = await driver.elements("class name", "android.widget.TextView");1021 let recentButton = null;1022 1023 for (let tabButton of tabButtons) {1024 let name = await tabButton.text();1025 if (name === 'ìµê·¼ ê²ì물') {1026 recentButton = tabButton;1027 break;1028 }1029 }1030 await recentButton.click();1031 break;1032 } catch(e) {1033 count += 1;1034 if (count > 10) {1035 throw {name: 'Not Found RecentButton'};1036 }1037 await sleep(1);1038 }1039 }1040 await rsleep(2,4);1041 1042 while(running.state) {1043 let count = 0;1044 try {1045 let imageViews = await driver.elements("class name", "android.widget.ImageView");1046 let imageElements = [];1047 for(let imageView of imageViews) {1048 const desc = await imageView.getAttribute("content-desc");1049 if (desc && desc.includes('ì¬ì§')) {1050 imageElements.push(imageView);1051 }1052 }1053 console.log(imageViews.length);1054 console.log(imageElements.length);1055 if (imageElements.length < 1) {1056 throw {name: 'Not Load imageViews'};1057 } 1058 const key = Math.floor(Math.random()*imageElements.length);1059 await imageElements[key].click();1060 break;1061 } catch(e) {1062 console.log('eerrrr');1063 console.log(e);1064 count += 1;1065 if (count > 10) {1066 throw {name: 'Not Found imageViews'};1067 }1068 await sleep(1);1069 }1070 }1071}1072function run(store, http, option, worklog, devOption, count) {1073 console.log(count);1074 const wd = require("wd");1075 const running = {1076 state: true,1077 }1078 let driver;1079 // let appiumServer;1080 let setting = option.instagramOption;1081 let work = {1082 logs: [],1083 instagramWork: [],1084 unfollowUser: [],1085 friends: {1086 date: null,1087 value: [],1088 },1089 beforeText: '',1090 }1091 const opts2 = {1092 platformName: "Android",1093 platformVersion: option.platformVersion,1094 deviceName: option.deviceName,1095 appPackage: "com.instagram.android",1096 appActivity: "com.instagram.mainactivity.MainActivity",1097 systemPort: 8200 + count,1098 fullReset: "false",1099 noReset: "true",1100 };1101 1102 logMessage(http, work, option, 'ìì
ì ììí©ëë¤.');1103 setTimeout(async () => {1104 let beforeTime = 0;1105 while(running.state) {1106 try {1107 if (checkActiveTime(setting.activeTimes)) {1108 const currentTime = new Date().getTime();1109 if (currentTime > new Date(option.expired).getTime()) {1110 break;1111 }1112 if (setting.followType === 1) {1113 if(setting.targetTags.length < 1) {1114 break;1115 }1116 if (checkOmit(devOption, worklog)) {1117 logMessage(http, work, option, 'ì¡ì
ëë½ë°ì ìì
ì 1ì¼ê° ì¤ì§í©ëë¤. ');1118 await sleep(60);1119 continue;1120 }1121 // if (currentTime - beforeTime >= CHECK_TIME) {1122 // await saveAccountLogAndProfile(http, driver, option);1123 // beforeTime = currentTime;1124 // }1125 for (let hashtag of shuffle(setting.targetTags)) {1126 if (!running.state) break;1127 if (checkOmit(devOption, worklog)) break;1128 try { await driver.quit(); } catch (e) { };1129 driver = await wd.promiseChainRemote({1130 host: '127.0.0.1',1131 port: option.appiumPort,1132 });1133 await driver.init(opts2);1134 console.log(hashtag);1135 let sleepTime = 0;1136 // íëìê° ì²´í¬ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@1137 1138 let dummyAction = [myFeedView, myDmView, viewStory, myProfileView, myProfileFollowerView, myProfileFollowingView, myActiveView, searchView, searchImageView, randomProfileView];1139 dummyAction = shuffle(dummyAction);1140 let _tempPercent = Math.random()*100;1141 if (_tempPercent < 40) {1142 console.log(`before-DummyAction : ${dummyAction[0].name} - START`);1143 logMessage(http, work, option, `before-DummyAction:${dummyAction[0].name}`);1144 await dummyAction[0](running, driver);1145 console.log(`before-DummyAction : ${dummyAction[0].name} - END`);1146 } else {1147 console.log(`before-DummyAction:PASS (${_tempPercent})`);1148 logMessage(http, work, option, `before-DummyAction:PASS`);1149 }1150 _tempPercent = Math.random()*100;1151 if (_tempPercent < 85) {1152 if (checkActiveTime(setting.activeTimes)) {1153 if (checkFollowLimit(worklog, setting) || checkLikeLimit(worklog, setting) || checkCommentLimit(worklog, setting)) {1154 await sleep(Math.random()*5 + 3);1155 console.log('log 1');1156 if (currentTime - beforeTime >= CHECK_TIME) {1157 await saveAccountLogAndProfile(http, driver, option);1158 beforeTime = currentTime;1159 }1160 // try {1161 await recentPost(running, driver, hashtag);1162 // } catch(e) {1163 // console.log(e);1164 // continue;1165 // }1166 1167 const randomCount = 10 + Math.floor(Math.random() * 150);1168 // const randomCount = 5;1169 for (let i = 0; i < randomCount; i++) {1170 if (!running.state) break;1171 if (checkOmit(devOption, worklog)) break;1172 if (checkFollowLimit(worklog, setting) || checkLikeLimit(worklog, setting) || checkCommentLimit(worklog, setting)) {1173 try {1174 let feedHeader = await driver.element("id", "row_feed_profile_header");1175 let feedFooter = await driver.element("id", "row_feed_view_group_buttons");1176 if (feedHeader && feedFooter) {1177 let headerY = (await feedHeader.getLocation()).y;1178 let footerY = (await feedFooter.getLocation()).y;1179 for(let i = 0; headerY < 160 && i < 10; i++) {1180 try {1181 const element = await driver.element("id", "sticky_header_list");1182 const random1 = Math.floor(10 + Math.random()*100);1183 const random2 = Math.floor(Math.random()*50);1184 // console.log(`${i} - flick(0, ${random1 + random2}, ${random1 + random2});`)1185 await element.flick(0, random1 + random2, random1 + random2);1186 headerY = (await feedHeader.getLocation()).y;1187 } catch(e) {1188 console.log(e);1189 await recentPost(running, driver, hashtag);1190 }1191 }1192 if (headerY < footerY) {1193 let followButton = feedHeader.element("id", "button");1194 let buttonText = await followButton.text();1195 if (buttonText === 'íë¡ì°') {1196 let commentButton = await feedFooter.element("id", "row_feed_button_comment");1197 if (commentButton && checkCommentLimit(worklog, setting)) {1198 await submitComment(running, driver, setting, option, hashtag, work, worklog)1199 feedHeader = await driver.element("id", "row_feed_profile_header");1200 feedFooter = await driver.element("id", "row_feed_view_group_buttons");1201 }1202 if (checkLikeLimit(worklog, setting)) {1203 const likeButton = await feedFooter.element("id", "row_feed_button_like");1204 await clickLike(likeButton, option, work, worklog);1205 }1206 console.log(1);1207 console.log(checkFollowLimit(worklog, setting));1208 if (checkFollowLimit(worklog, setting)) {1209 console.log(11);1210 let followButton = null;1211 for(let i = 0; !followButton && i < 10; i++) {1212 try {1213 feedHeader = await driver.element("id", "row_feed_profile_header");1214 feedFooter = await driver.element("id", "row_feed_view_group_buttons");1215 headerY = (await feedHeader.getLocation()).y;1216 footerY = (await feedFooter.getLocation()).y;1217 if (headerY > footerY) {1218 throw 'nop!';1219 }1220 followButton = await feedHeader.element("id", "button");1221 } catch(e) {1222 console.log(e);1223 try {1224 console.log('action2');1225 let action = new wd.TouchAction(driver);1226 const random = 200 + Math.random()*500;1227 action.press({x: 200, y: random})1228 .moveTo({x: 200, y: random + 150})1229 .release();1230 await action.perform();1231 } catch(e) {1232 console.log(e);1233 }1234 }1235 }1236 const user = (await (await feedHeader.element("id", "row_feed_photo_profile_name")).text()).replace(/[ â¢]/g, '');1237 await clickFollow(followButton, option, work, worklog, setting, user, hashtag);1238 } 1239 sleepTime += (Math.random()*90 + 90);1240 console.log(`sleepTime: ${sleepTime}`);1241 }1242 }1243 }1244 } catch(e) { }1245 try {1246 const element = await driver.element("id", "sticky_header_list");1247 const random1 = Math.floor(200 + Math.random()*240);1248 const random2 = Math.floor(Math.random()*139);1249 const random3 = Math.floor(Math.random()*128);1250 // console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)1251 await element.flick(0, -(random1 + random2), random1 + random3);1252 } catch(e) {1253 console.log(e);1254 await recentPost(running, driver, hashtag);1255 }1256 }1257 saveLogDetail(http, work);1258 }1259 } else {1260 saveLogDetail(http, work);1261 await sleep(120);1262 }1263 saveLogDetail(http, work);1264 } else {1265 await sleep(120);...
Test.js
Source:Test.js
...87 const random1 = Math.floor(200 + Math.random()*200);88 const random2 = Math.floor(Math.random()*150);89 const random3 = Math.floor(Math.random()*147);90 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)91 await element.flick(0, -(random1 + random2), random1 + random3);92 await sleep(0);93 }94 } catch(e) {95 console.log(`ëì í¼ë보기 ìë¬: ${e.name}`);96 }97}98async function myDmView(driver) {99 try {100 await gotoMain(driver);101 console.log('ëì ëì 보기 ìì');102 const element = await driver.element("id", "action_bar_inbox_button");103 await element.click();104 const random = Math.floor(Math.random()*10);105 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);106 for (let i=0; i<random; i++) {107 const element = await driver.element("id", "inbox_refreshable_thread_list_recyclerview");108 const random1 = Math.floor(200 + Math.random()*200);109 const random2 = Math.floor(Math.random()*150);110 const random3 = Math.floor(Math.random()*147);111 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)112 await element.flick(0, -(random1 + random2), random1 + random3);113 await sleep(0);114 }115 const inboxs = await driver.elements("id", "row_inbox_container");116 const inbox = inboxs[Math.floor(Math.random()*inboxs.length)];117 inbox.click();118 const random2 = Math.floor(Math.random()*10);119 console.log(`ëë¤ì¹´ì´í¸ : ${random2}`);120 for (let i=0; i<random2; i++) {121 const element = await driver.element("id", "message_list");122 const random1 = Math.floor(200 + Math.random()*200);123 const random2 = Math.floor(Math.random()*150);124 const random3 = Math.floor(Math.random()*147);125 console.log(`${i} - flick(0, ${random1 + random2}, ${random1 + random3});`)126 await element.flick(0, random1 + random2, random1 + random3);127 await sleep(0);128 }129 } catch(e) {130 console.log(`ëì ëì 보기 ìë¬: ${e.name}`);131 console.log(e);132 }133}134async function viewStory(driver) {135 try {136 await gotoMain(driver);137 console.log('viewStory Start;')138 await sleep(2);139 const element = await driver.elements("id", "outer_container");140 await element[1].click();141 const random = Math.floor(40 + Math.random()*60);142 console.log(`randomCount: ${random}`);143 for (let i=0; i<random; i++) {144 const random1 = Math.floor(Math.random()*100);145 console.log(`pass number : ${random1}`);146 if (random1 < 50) {147 const element = await driver.element("id", "bottom_sheet_container");148 const random1 = Math.floor(200 + Math.random()*200);149 const random2 = Math.floor(Math.random()*150);150 const random3 = Math.floor(Math.random()*147);151 console.log(`${i} - flick(${-(random1 + random2)}, 0, ${random1 + random3});`)152 await element.flick(-(random1 + random2), 0, random1 + random3);153 }154 await rsleep(2, 10);155 }156 const back = await driver.element("id", "bottom_sheet_container");157 const random1 = Math.floor(800 + Math.random()*200);158 const random2 = Math.floor(Math.random()*150);159 const val = random1 + random2;160 await back.flick(0, val, Math.floor(val/10));161 } catch(e) {162 console.log(`ëì viewStory ìë¬: ${e.name}`);163 console.log(e);164 }165}166async function myProfileView(driver) {167 try {168 await gotoMain(driver);169 console.log('ëì í¼ë보기 ìì');170 const bottomBar = await driver.elements("id", "tab_icon");171 await bottomBar[4].click();172 const random = Math.floor(1 + Math.random()*10);173 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);174 for (let i=0; i<random; i++) {175 const element = await driver.element("id", "coordinator_root_layout");176 const random1 = Math.floor(200 + Math.random()*200);177 const random2 = Math.floor(Math.random()*150);178 const random3 = Math.floor(Math.random()*147);179 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)180 await element.flick(0, -(random1 + random2), random1 + random3);181 await sleep(0);182 }183 } catch(e) {184 console.log(`ëì í¼ë보기 ìë¬: ${e.name}`);185 }186}187async function myProfileFollowerView(driver) {188 try {189 await gotoMain(driver);190 console.log('ëì myProfileFollowerView ìì');191 const bottomBar = await driver.elements("id", "tab_icon");192 await bottomBar[4].click();193 await sleep(2);194 const element2 = await driver.element("id", "row_profile_header_followers_container");195 await element2.click();196 const random = Math.floor(1 + Math.random()*20);197 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);198 for (let i=0; i<random; i++) {199 const element = await driver.element("id", "layout_listview_parent_container");200 const random1 = Math.floor(10 + Math.random()*2000);201 const random2 = Math.floor(Math.random()*169);202 const random3 = Math.floor(Math.random()*152);203 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${Math.floor((random1 + random3)/10)});`)204 await element.flick(0, -(random1 + random2), Math.floor((random1 + random3)/10));205 await sleep(0);206 }207 } catch(e) {208 console.log(`ëì myProfileFollowerView ìë¬: ${e.name}`);209 console.log(e);210 }211}212async function myProfileFollowingView(driver) {213 try {214 await gotoMain(driver);215 console.log('ëì myProfileFollowingView ìì');216 const bottomBar = await driver.elements("id", "tab_icon");217 await bottomBar[4].click();218 await sleep(2);219 const element2 = await driver.element("id", "row_profile_header_following_container");220 await element2.click();221 const random = Math.floor(1 + Math.random()*20);222 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);223 for (let i=0; i<random; i++) {224 const element = await driver.element("id", "layout_listview_parent_container");225 const random1 = Math.floor(10 + Math.random()*2000);226 const random2 = Math.floor(Math.random()*179);227 const random3 = Math.floor(Math.random()*163);228 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${Math.floor((random1 + random3)/10)});`)229 await element.flick(0, -(random1 + random2), Math.floor((random1 + random3)/10));230 await sleep(0);231 }232 } catch(e) {233 console.log(`ëì myProfileFollowingView ìë¬: ${e.name}`);234 console.log(e);235 }236}237async function myActiveView(driver) {238 try {239 await gotoMain(driver);240 console.log('ëì myActiveView ìì');241 const bottomBar = await driver.elements("id", "tab_icon");242 await bottomBar[3].click();243 const random = Math.floor(5 + Math.random()*30);244 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);245 for (let i=0; i<random; i++) {246 const element = await driver.element("id", "newsfeed_pager");247 const random1 = Math.floor(200 + Math.random()*200);248 const random2 = Math.floor(Math.random()*150);249 const random3 = Math.floor(Math.random()*147);250 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)251 await element.flick(0, -(random1 + random2), random1 + random3);252 await sleep(0);253 }254 } catch(e) {255 console.log(`ëì myActiveView ìë¬: ${e.name}`);256 console.log(e);257 }258} 259async function searchView(driver) {260 try {261 await gotoMain(driver);262 console.log('ëì searchView ìì');263 const bottomBar = await driver.elements("id", "tab_icon");264 await bottomBar[1].click();265 const random = Math.floor(10 + Math.random()*60);266 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);267 for (let i=0; i<random; i++) {268 const element = await driver.element("id", "recycler_view");269 const random1 = Math.floor(200 + Math.random()*200);270 const random2 = Math.floor(Math.random()*150);271 const random3 = Math.floor(Math.random()*147);272 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)273 await element.flick(0, -(random1 + random2), random1 + random3);274 await rsleep(0, 4);275 }276 } catch(e) {277 console.log(`ëì searchView ìë¬: ${e.name}`);278 }279}280async function searchImageView(driver) {281 try {282 await gotoMain(driver);283 console.log('ëì searchImageView ìì');284 const bottomBar = await driver.elements("id", "tab_icon");285 await bottomBar[1].click();286 await sleep(2);287 const imageElements = await driver.elements("id", "image_button");288 console.log(imageElements);289 const key = Math.floor(Math.random()*imageElements.length);290 console.log(key);291 await imageElements[key].click();292 const random = Math.floor(10 + Math.random()*60);293 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);294 for (let i=0; i<random; i++) {295 const element = await driver.element("id", "sticky_header_list");296 const random1 = Math.floor(200 + Math.random()*200);297 const random2 = Math.floor(Math.random()*151);298 const random3 = Math.floor(Math.random()*148);299 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)300 await element.flick(0, -(random1 + random2), random1 + random3);301 await rsleep(0, 2);302 }303 } catch(e) {304 console.log(`ëì searchImageView ìë¬: ${e.name}`);305 console.log(e);306 }307}308async function randomProfileView(driver) {309 try {310 await gotoMain(driver);311 console.log('ëì randomProfileView ìì');312 const bottomBar = await driver.elements("id", "tab_icon");313 await bottomBar[1].click();314 await rsleep(2, 3);315 const imageElements = await driver.elements("id", "image_button");316 console.log(imageElements);317 const key = Math.floor(Math.random()*imageElements.length);318 console.log(key);319 await imageElements[key].click();320 await rsleep(0, 1);321 const profileName = await driver.elements("id", "row_feed_photo_profile_name");322 await profileName[0].click();323 const random = Math.floor(1 + Math.random()*10);324 console.log(`ëë¤ì¹´ì´í¸ : ${random}`);325 for (let i=0; i<random; i++) {326 const element = await driver.element("id", "coordinator_root_layout");327 const random1 = Math.floor(200 + Math.random()*200);328 const random2 = Math.floor(Math.random()*155);329 const random3 = Math.floor(Math.random()*152);330 console.log(`${i} - flick(0, ${-(random1 + random2)}, ${random1 + random3});`)331 await element.flick(0, -(random1 + random2), random1 + random3);332 await sleep(0);333 }334 } catch(e) {335 console.log(`ëì randomProfileView ìë¬: ${e.name}`);336 console.log(e);337 }338}339async function gotoMain(driver) {340 while(true) {341 try {342 let backButton1 = await driver.elements("id", "action_bar_button_back");343 let backButton2 = await driver.elements("id", "action_bar_cancel");344 let backButton3 = await driver.elements("id", "close_button");345 if (backButton1[0]) {...
basic.js
Source:basic.js
1/**2 * User: dengwei3 * Date: 16-7-184 * Time: ä¸å4:145 * Author: dw1130736 * Description: åºç¡ç±»7 */8var basic = {9 init: function () {//å¤èµ·appï¼å¹¶æå°æµè¯ä¿¡æ¯10 var targetName = this.target().name();11 var appName = this.target().frontMostApp().name();12 var deviceModel = this.target().model();13 var osVersion = this.target().systemVersion();14 var osName = this.target().systemName();15 var appVersion = this.target().frontMostApp().bundleID();16 UIALogger.logStart("UI驱å¨å¼å§...");17 UIALogger.logMessage("è°è¯å
å称ï¼" + appName);18 UIALogger.logMessage("æµè¯å
çæ¬ï¼" + appVersion);19 UIALogger.logMessage("设å¤å称ï¼" + targetName);20 UIALogger.logMessage("设å¤åå·ï¼" + deviceModel);21 UIALogger.logMessage("ç³»ç»çæ¬ï¼" + osVersion);22 UIALogger.logMessage("æä½ç³»ç»ç±»åï¼" + osName);23 UIALogger.logMessage("monkeyInfoLabel: " + UIATarget.localTarget().systemVersion() + " " + UIATarget.localTarget().name());24 },25 isNewMain:function(){26 return true;27 },28 appVersion: function(){29 return this.target().frontMostApp().bundleID();30 },31 screenRect: function () {//è·åå½åappç主window32 return this.target().rect();33 },34 body: function () {//è·åå½åappç主window35 return this.target().frontMostApp().mainWindow();36 },37 app: function () {//è·åå½å设å¤çfrontMostApp38 return this.target().frontMostApp();39 },40 target: function () {//è·åå½å设å¤çlocalTargetjj41 return UIATarget.localTarget();42 },43 /**44 * è·åå½å设å¤çmainWindow45 * @returns {*}46 */47 window: function () {//è·åå½å设å¤çlocalTargetjj48 return UIATarget.localTarget().frontMostApp().mainWindow();49 },50 /**51 * è°ç¨shellï¼keyæ¯å¯¹åº.shæ件çç»å¯¹è·¯å¾ãä¸è½æ§è¡sudoæéçèæ¬ã52 * @param key53 */54 shell: function (key) {55 var result = this.target().host().performTaskWithPathArgumentsTimeout("/bin/sh", [key], 5);56 // basic.say("exitCode: " + result.exitCode);57 basic.say("stdout: " + result.stdout);58 // basic.say("stderr: " + result.stderr);59 },60 wait: function (seconds) {//çå¾
æ°ç§ãsecondsæ¯ç§æ°ã61 this.target().delay(seconds);62 },63 // tap: function(ele){//æ ¹æ®ä½ç½®ä¿¡æ¯ï¼å¼ºè¡ç¹å»ä¸ä¸ªæ§ä»¶.64 // if(ele==null){65 // this.warning('basic.tap()并没æåå°åæ³åæ°ï¼');66 // return null;67 // }68 // var tapPointHorizontal =parseFloat(ele.rect().origin.x+(0.5*ele.rect().size.width));69 // var tapPointVertical =parseFloat(ele.rect().origin.y+(0.5*ele.rect().size.height));70 // // basic.say(''+ele.rect().origin.x);71 // // basic.say(''+ele.rect().origin.y);72 // // basic.say(''+ele.rect().size.width);73 // // basic.say(''+ele.rect().size.height);74 //75 // // this.say("the x is "+tapPointHorizontal+" and the y is "+tapPointVertical);76 // this.target().tap({x:tapPointHorizontal,y:tapPointVertical});77 // },78 tree: function () {//å¨logä¸æå°æ§ä»¶æ .79 this.target().logElementTree();80 },81 longTap: function (tmpX, tmpY) {//é¿ææç¹ãtmpXåtmpYåå«æ¯æç¹çxyåæ ã82 this.target().tapWithOptions(83 {x: tmpX, y: tmpY},84 {85 duration: 286 }87 );88 this.wait(miniSleep);89 },90 flickUp: function (element) {//åä¸æ»å¨æ§ä»¶ãrateæ»å¨å¯¹æ¯æ§ä»¶æ¬èº«æ¯ä¾91 element.flickInsideWithOptions({startOffset: {x: 0.5, y: 0.8}, endOffset: {x: 0.5, y: 0.2}});92 this.wait(miniSleep);93 },94 flickDown: function (element) {//åä¸æ»å¨æ§ä»¶ãrateæ»å¨å¯¹æ¯æ§ä»¶æ¬èº«æ¯ä¾95 element.flickInsideWithOptions({startOffset: {x: 0.5, y: 0.2}, endOffset: {x: 0.5, y: 0.8}});96 this.wait(miniSleep);97 },98 flickLeft: function (element) {//åå·¦æ»å¨æ§ä»¶ãrateæ»å¨å¯¹æ¯æ§ä»¶æ¬èº«æ¯ä¾99 element.flickInsideWithOptions({startOffset: {x: 0.8, y: 0.5}, endOffset: {x: 0.2, y: 0.5}});100 this.wait(miniSleep);101 },102 flickRight: function (element) {//åå³æ»å¨æ§ä»¶ãrateæ»å¨å¯¹æ¯æ§ä»¶æ¬èº«æ¯ä¾103 element.flickInsideWithOptions({startOffset: {x: 0.2, y: 0.5}, endOffset: {x: 0.8, y: 0.5}});104 this.wait(miniSleep);105 },106 rollUp: function (key) {//åä¸åå¨ãkey为空æ¶ï¼å¨å±å¹ä¸é´åä¸åãkeyä¸ä¸ºç©ºæ¶ï¼åå¨æ°åkeyæ å®ç横åæ åä¸å107 var position;108 if (key == null) {109 position = this.target().rect().size.width * 0.5;110 } else {111 position = key;112 }113 this.target().dragFromToForDuration(114 {x: position, y: this.target().rect().size.height * 0.7},115 {x: position, y: this.target().rect().size.height * 0.3},116 0.5117 );118 this.wait(miniSleep);119 },120 rollWithPosition: function (startX,startY,endX,endY) {121 this.target().dragFromToForDuration(122 {x: startX, y: startY},123 {x: endX, y: endY},124 0.5125 );126 this.wait(miniSleep);127 },128 rollDown: function (key) {//åä¸åå¨ãkey为空æ¶ï¼å¨å±å¹ä¸é´åä¸åãkeyä¸ä¸ºç©ºæ¶ï¼åå¨æ°åkeyæ å®ç横åæ åä¸å129 var position;130 if (key == null) {131 position = this.target().rect().size.width * 0.5;132 } else {133 position = key;134 }135 this.target().dragFromToForDuration(136 {x: position, y: this.target().rect().size.height * 0.3},137 {x: position, y: this.target().rect().size.height * 0.7},138 0.5139 );140 this.wait(miniSleep);141 },142 rollLeft: function (key) {//åå·¦åå¨ãkey为空æ¶ï¼å¨å±å¹ä¸é´åå·¦åãkeyä¸ä¸ºç©ºæ¶ï¼åå¨æ°åkeyæ å®ç纵åæ åå·¦å143 var position;144 if (key == null) {145 position = this.target().rect().size.height * 0.5;146 } else {147 position = key;148 }149 this.target().dragFromToForDuration(150 {x: this.target().rect().size.width * 0.7, y: position},151 {x: this.target().rect().size.width * 0.3, y: position},152 0.5153 );154 this.wait(miniSleep);155 },156 longRollLeft: function (key) {//åå·¦åå¨ãkey为空æ¶ï¼å¨å±å¹ä¸é´åå·¦åãkeyä¸ä¸ºç©ºæ¶ï¼åå¨æ°åkeyæ å®ç纵åæ åå·¦å157 var position;158 if (key == null) {159 position = this.target().rect().size.height * 0.5;160 } else {161 position = key;162 }163 this.target().dragFromToForDuration(164 {x: this.target().rect().size.width * 0.9, y: position},165 {x: this.target().rect().size.width * 0.1, y: position},166 0.5167 );168 this.wait(miniSleep);169 },170 rollRight: function (key) {//åå³åå¨ãkey为空æ¶ï¼å¨å±å¹ä¸é´åå³åãkeyä¸ä¸ºç©ºæ¶ï¼åå¨æ°åkeyæ å®ç纵åæ åå³å171 var position;172 if (key == null) {173 position = this.target().rect().size.height * 0.5;174 } else {175 position = key;176 }177 this.target().dragFromToForDuration(178 {x: this.target().rect().size.width * 0.3, y: position},179 {x: this.target().rect().size.width * 0.7, y: position},180 0.5181 );182 this.wait(miniSleep);183 },184 rotate: function () {//æ转å°å¾180度185 this.target().rotateWithOptions(186 {x: this.target().rect().size.width * 0.5, y: this.target().rect().size.height * 0.5},//æå¿ä¸å¿ç¹åæ 187 {188 duration: 1, //æå¿æ¶é¿189 radius: this.target().rect().size.width * 0.1, //åå¾190 rotation: Math.PI, //æ转è§åº¦191 touchCount: 2192 }//æå¿ææ个æ°193 );194 this.wait(miniSleep);195 },196 photo: function (key) {//æªå¾ï¼keyæ¯å¾çå称197 this.target().captureRectWithName({198 origin: {x: 0, y: 20},199 size: {width: this.target().rect().size.width, height: this.target().rect().size.height - 20}200 }, key);201 },202 /**203 * ç¹å»å±å¹åæ 204 * @param x205 * @param y206 */207 tap: function (x, y) {208 this.target().tap({x: x, y: y});209 },210 /**211 * ç¹å»ä¸ä¸ªæ¨ªåæ§ä»¶çä¸é¨åãkey1æ¯åæ°,key2æ¯ç¬¬å å212 * @param ele213 * @param key1214 * @param key2215 */216 tapPart: function (ele, key1, key2) {217 var step = (1 / key1) * ele.rect().size.width;218 var tapPointHorizontal = parseFloat(ele.rect().origin.x + (key2 - 0.5) * step);219 var tapPointVertical = parseFloat(ele.rect().origin.y + (0.5 * ele.rect().size.height));220 this.target().tap({x: tapPointHorizontal, y: tapPointVertical});221 },222 randomItem: function (arr) {//è¾å
¥ä¸ä¸ªæ°ç»ï¼è¿åæ°ç»ä¸çéæºä¸ä¸ªæå223 var i = Math.round(Math.random() * (arr.length - 1));224 return arr[i];225 },226 randomNum: function (min, max) {//ç»åºä¸ä¸ªéæºæ´æ°ï¼åå¼èå´æ¯[min,max]227 return Math.round(Math.random() * (max - min)) + min;228 },229 /**230 * éå±231 * @param times : åä½ä¸ºç§232 */233 lock: function (times) {//éå±keyç§åå解éãè¥key为空åé»è®¤é2ç§ã234 var seconds;235 if (key == null) {236 seconds = 2;237 } else {238 seconds = key;239 }240 basic.target().lockForDuration(seconds);241 },242 /**243 * appç½®åå°244 * @param times: åä½ä¸ºç§245 */246 home: function (times) {//ç¹å»homeé®æappååå°ï¼keyç§ååååæ¥ãkey为空åé»è®¤2ç§åååæ¥ã247 var seconds;248 if (key == null) {249 seconds = 2;250 } else {251 seconds = key;252 }253 basic.target().deactivateApp(seconds);254 },255 setDeviceOrientationUp: function () {//è°æ´ææºçéåæåºï¼è®©ææºä»¥ä¸ºèªå·±æ¯æ£åææ¾çã256 basic.target().setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);257 },258 setDeviceOrientationDown: function () {//è°æ´ææºçéåæåºï¼è®©ææºä»¥ä¸ºèªå·±æ¯åç«ææ¾çã259 basic.target().setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN);260 },261 setDeviceOrientationLeft: function () {//è°æ´ææºçéåæåºï¼è®©ææºä»¥ä¸ºèªå·±æ¯å·¦è¾¹åä¸ææ¾çã262 basic.target().setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT);263 },264 setDeviceOrientationRight: function () {//è°æ´ææºçéåæåºï¼è®©ææºä»¥ä¸ºèªå·±æ¯å³è¾¹åä¸ææ¾çã265 basic.target().setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT);266 },267 voiceUp: function (key) {//ç¹å»é³éå¢å¤§æé®ãkeyæ¯ç¹å»æ¬¡æ°ï¼key为空æ¶é»è®¤ç¹ä¸ä¸ã268 var times;269 if (key == null) {270 times = 1;271 } else {272 times = key;273 }274 for (var i = 0; i < times; i++) {275 this.target().clickVolumeUp();276 this.wait(0.3);277 }278 },279 voiceDown: function (key) {//ç¹å»é³éåå°æé®ãkeyæ¯ç¹å»æ¬¡æ°ï¼key为空æ¶é»è®¤ç¹ä¸ä¸ã280 var times;281 if (key == null) {282 times = 1;283 } else {284 times = key;285 }286 for (var i = 0; i < times; i++) {287 this.target().clickVolumeDown();288 this.wait(0.3);289 }290 },291 back: function () {//ç¹å»å·¦ä¸è§è¿åæé®292 this.target().tap({x: 27, y: 45});293 this.wait(miniSleep);294 }295}296var eleObject = {297 info: {298 name: 'æªå½åæ§ä»¶',299 part: 1,300 },301 name: function () {302 return this.info.name;303 },304 head: function () {305 basic.say("å°è¦æä½\"" + this.info.name + "\"æ§ä»¶äºå¦");306 },307 tail: function () {308 basic.say("å·²ç»æä½è¿\"" + this.info.name + "\"æ§ä»¶äºå¦");309 },310 part: function () {311 return this.info.part;312 },...
Tester.js
Source:Tester.js
1const { Session } = require('./Session');2class Tester {3 static get Session() {4 return Session;5 }6 constructor(options) {7 const Session = this.constructor.Session;8 this.session = options.session || new Session(options);9 this.currentElements = [];10 this.currentElementIndex = 0;11 this.currentElementsSelector = null;12 this.executeChain = null;13 this.timeout = 10000;14 this.promise = new Promise((resolve, reject) => {15 this.executeChain = resolve;16 });17 }18 get currentElement() {19 if (this.currentElementIndex >= this.currentElements.length) {20 throw new Error(`could not find element "${this.currentElementsSelector}[${this.currentElementIndex}]"`);21 } else {22 return this.currentElements[this.currentElementIndex];23 }24 }25 /**26 * Set how long to wait for various things to happen before throwing an error.27 * 28 * For example if no elements are found for a specific selector an error is thrown29 * after trying to find them for `timeout` milliseconds.30 * 31 * @param {number} timeout32 * Timeout in milliseconds.33 */34 setImplicitWaitTimeout(timeout) {35 return this.then(() => {36 this.timeout = value(timeout);37 return this.session.setImplicitWaitTimeout(this.timeout);38 });39 }40 /**41 * Select the `index`th result element of the previous `elements` call as the current element.42 * 43 * @returns {WebDriverChain}44 */45 at(index) {46 return this.then(() => {47 this.currentElementIndex = value(index);48 });49 }50 /**51 * Select the `index`th last result element of the previous `elements` call as the current element.52 * 53 * @returns {WebDriverChain}54 */55 reverseAt(index) {56 return this.then(() => {57 this.currentElementIndex = this.currentElements.length - value(index) - 1;58 });59 }60 /**61 * This must be called once to start things off.62 * 63 * @returns {Promise}64 * When this promise is resolved, the test chain execution is started.65 */66 init() {67 return this.session.create().then(() => this.executeChain());68 }69 /**70 * This must be called once after the tests to release resources.71 * 72 * @returns {Promise}73 */74 quit() {75 return this.then(() => this.session.destroy());76 }77 /**78 * Finds elements.79 * 80 * @param {string} using81 * The algorithm to use. Must be one of ['xpath', 'class name', 'id'].82 * 83 * @param {string} selector84 * The element selector.85 * 86 * @returns {WebDriverChain}87 */88 elements({using, selector}) {89 return this.then(() => {90 return this.session.elements({using: value(using), selector: value(selector)}).then(elements => {91 this.currentElements = elements;92 this.currentElementIndex = 0;93 this.currentElementsSelector = selector;94 return elements;95 });96 });97 }98 /**99 * Find elements using xpath selector.100 * 101 * @param {string} selector 102 * @returns {WebDriverChain}103 */104 elementsByXpath(selector) {105 return this.elements({using: 'xpath', selector});106 }107 /**108 * Find elements using id.109 * 110 * @param {string} selector 111 * @returns {WebDriverChain}112 */113 elementsById(selector) {114 return this.elements({using: 'id', selector});115 }116 /**117 * Find elements using class name.118 * 119 * @param {string} selector 120 * @returns {WebDriverChain}121 */122 elementsByClassName(selector) {123 return this.elements({using: 'class name', selector});124 }125 /**126 * Click the current element.127 */128 click() {129 return this.then(() => this.currentElement.click());130 }131 /**132 * Send text to the current element.133 */134 setValue(val) {135 return this.then(() => this.currentElement.setValue(value(val)));136 }137 /**138 * Clear text from the current element.139 */140 clear() {141 return this.then(() => this.currentElement.clear());142 }143 /**144 * Return the text of the current element145 */146 text() {147 return this.then(() => this.currentElement.text());148 }149 /**150 * Return the bounding box of the current element151 */152 rect() {153 return this.then(() => this.currentElement.rect());154 }155 /**156 * Flick the current element.157 */158 flick({xoffset, yoffset, speed}) {159 return this.then(() => {160 return this.currentElement.flick({161 xoffset: value(xoffset), 162 yoffset: value(yoffset), 163 speed: value(speed)164 });165 });166 }167 /**168 * Flick the current element up.169 */170 flickUp(offset, speed) {171 return this.then(() => this.currentElement.flickUp(value(offset), value(speed)));172 }173 /**174 * Flick the current element down.175 */176 flickDown(offset, speed) {177 return this.then(() => this.currentElement.flickDown(value(offset), value(speed)));178 }179 /**180 * Flick the current left.181 */182 flickLeft(offset, speed) {183 return this.then(() => this.currentElement.flickLeft(value(offset), value(speed)));184 }185 /**186 * Flick the current right.187 */188 flickRight(offset, speed) {189 return this.then(() => this.currentElement.flickRight(value(offset), value(speed)));190 }191 /**192 * Assert that the current element is visible.193 */194 isDisplayed() {195 return this.then(() => this._assertDisplayed(true));196 }197 /**198 * Assert that the current element is visible.199 */200 isNotDisplayed() {201 return this.then(() => this._assertDisplayed(false));202 }203 /**204 * @private205 */206 _assertDisplayed(expectedValue) {207 // If the element is not found at all, it is not visible.208 if (!expectedValue && this.currentElements.length === 0) {209 return true;210 }211 return this.currentElement212 .isDisplayed()213 .then(isDisplayed => {214 if (isDisplayed !== expectedValue) {215 throw new Error(`element "${this.currentElementsSelector}[${this.currentElementIndex}]" is${expectedValue ? ' not ' : ' '}displayed`);216 } else {217 return true;218 }219 });220 }221 /**222 * Wait until the current element is visible. An error is thrown if the element is not223 * visible after the implicit wait timeout. See `setImplicitWaitTimeout` method.224 */225 waitDisplayed(timeout) {226 return this.then(() => {227 return this.poll(() => {228 return this._assertDisplayed(true);229 }, value(timeout));230 });231 }232 /**233 * Wait until the current element is not visible. An error is thrown if the element is234 * visible after the implicit wait timeout. See `setImplicitWaitTimeout` method.235 */236 waitNotDisplayed(timeout) {237 return this.then(() => {238 return this.poll(() => {239 return this._assertDisplayed(false);240 }, value(timeout));241 });242 }243 /**244 * Assert that the current element is enabled.245 */246 isEnabled() {247 return this.then(() => this._assertEnabled(true));248 }249 /**250 * Assert that the current element is not enabled.251 */252 isDisabled() {253 return this.then(() => this._assertEnabled(false));254 }255 /**256 * @private257 */258 _assertEnabled(expectedValue) {259 return this.currentElement260 .isEnabled()261 .then(isEnbaled => {262 if (isEnbaled !== expectedValue) {263 throw new Error(`element "${this.currentElementsSelector}[${this.currentElementIndex}]" is${expectedValue ? ' not ' : ' '}enabled`);264 } else {265 return true;266 }267 });268 }269 /**270 * Wait until the current element is enabled. An error is thrown if the element is not271 * enabled after the implicit wait timeout. See `setImplicitWaitTimeout` method.272 */273 waitEnabled(timeout) {274 return this.then(() => {275 return this.poll(() => {276 return this._assertEnabled(true);277 }, value(timeout));278 });279 }280 /**281 * Wait until the current element is disabled. An error is thrown if the element is not282 * disabled after the implicit wait timeout. See `setImplicitWaitTimeout` method.283 */284 waitDisabled(timeout) {285 return this.then(() => {286 return this.poll(() => {287 return this._assertEnabled(false);288 }, value(timeout));289 });290 }291 /**292 * Assert that the current element is selected.293 */294 isSelected() {295 return this.then(() => this._assertSelected(true));296 }297 /**298 * Assert that the current element is not selected.299 */300 isNotSelected() {301 return this.then(() => this._assertSelected(false));302 }303 /**304 * @private305 */306 _assertSelected(expectedValue) {307 return this.currentElement308 .isSelected()309 .then(isSelected => {310 if (isSelected !== expectedValue) {311 throw new Error(`element "${this.currentElementsSelector}[${this.currentElementIndex}]" is${expectedValue ? ' not ' : ' '}selected`);312 } else {313 return true;314 }315 });316 }317 /**318 * Wait until the current element is selected. An error is thrown if the element is not319 * selected after the implicit wait timeout. See `setImplicitWaitTimeout` method.320 */321 waitSelected(timeout) {322 return this.then(() => {323 return this.poll(() => {324 return this._assertSelected(true);325 }, value(timeout));326 });327 }328 /**329 * Wait until the current element is not selected. An error is thrown if the element is330 * selected after the implicit wait timeout. See `setImplicitWaitTimeout` method.331 */332 waitNotSelected(timeout) {333 return this.then(() => {334 return this.poll(() => {335 return this._assertSelected(false);336 }, value(timeout));337 });338 }339 /**340 * Wait until the current element stops moving.341 */342 waitStop(timeout) {343 return this.then(() => {344 let prevRect = null;345 346 return this.poll(() => {347 return this.currentElement.rect().then(rect => {348 if (prevRect === null || prevRect.x !== rect.x || prevRect.y !== rect.y) {349 prevRect = rect;350 // Retry.351 throw new Error(`element "${this.currentElementsSelector}[${this.currentElementIndex}]" did not stop moving`);352 }353 });354 }, value(timeout));355 });356 }357 sleep(time) {358 return this.then(() => new Promise(resolve => setTimeout(resolve, value(time))));359 }360 windowRect() {361 return this.then(() => this.session.windowRect());362 }363 resetApp() {364 return this.then(() => this.session.resetApp());365 }366 hideKeyboard() {367 return this.then(() => this.session.hideKeyboard());368 }369 then(...args) {370 this.promise = this.promise.then(...args);371 return this;372 }373 catch(...args) {374 this.promise = this.promise.catch(...args);375 return this;376 }377 poll(op, timeout) {378 const pollInterval = 50;379 const startTime = Date.now();380 const doPoll = () => {381 return op().catch(err => {382 const theTimeout = timeout || this.timeout;383 if (Date.now() - startTime < theTimeout) {384 return delay(pollInterval).then(doPoll);385 } else {386 throw err;387 }388 });389 };390 return doPoll();391 }392}393function delay(delay) {394 return new Promise(resolve => setTimeout(resolve, delay));395}396function value(val) {397 if (typeof val === 'function') {398 return val();399 } else {400 return val;401 }402}403module.exports = {404 Tester...
iOSMonkey2.js
Source:iOSMonkey2.js
1/*2 *3 *4 */5function iOSMonkey2(){6 this.elementArray = null;7 this._addToArray = function(root,len){8 var rootname = root.name()+""9 rootname = rootname.toLowerCase();10 if( !this._isIndicator(root) && root.toString() != "[object UIAKey]" && rootname.match("notap"+"$") !="notap" ){11 if(root.isEnabled() && root.isVisible()){12 if(len==0){13 if(root.hitpoint() != null){14 var rect = root.hitpoint();15 if(rect.y>20){16 this.elementArray.push(root);17 }18 }19 }20 if(this._toFlick(root) || this._toType(root)){21 this.elementArray.push(root);22 }23 }24 }25 }26 this._iterator = function(root){27 var eleArray = null;28 if(root.toString() !="[object UIAWebView]" && root.toString() != "[object UIAKeyboard]"){29 eleArray = root.elements();30 this._addToArray(root,eleArray.length);31 if(eleArray.length != 0 && eleArray != null){32 for(var i = 0; i< eleArray.length; i++){33 this._iterator(eleArray[i]);34 }35 }36 }37 }38 this._isIndicator = function(element){39 return element.toString().match("Indicator"+"$")=="Indicator";40 }41 this._findIndicator = function(root){42 var elements = root.elements();43 if(elements.length !=0 && elements != null){44 for(var i =0; i<elements.length;i++){45 if(this._isIndicator(elements[i])){46 return 1;47 }48 this._findIndicator(elements[i]);49 }50 }51 }52 this._getAllElements = function(){53 var app = UIATarget.localTarget().frontMostApp();54 this.elementArray = null;55 this.elementArray = new Array();56 this._iterator(app);57 }58 this._getElementAncestry = function(element){59 var arr = element.ancestry();60 var tmp = ""61 for(var i = 0; i< arr.length; i++){62 tmp += arr[i].toString()+"->"63 }64 return tmp;65 }66 this._selector = function(){67 this._getAllElements();68 var len = this.elementArray.length;69 //UIALogger.logMessage(len+"");70 var random = Math.round(Math.random() * len);71 if (random == len){72 random = random-1;73 }74 return this.elementArray[random];75 }76 this._toFlick = function(element){77 if(element.toString()=="[object UIATableView]" || element.toString()=="[object UIAScrollView]" || element.toString()=="[object UIATableCell]"){78 return 1;79 }80 return 0;81 }82 this._toType = function(element){83 if(element.toString()=="[object UIATextField]" || element.toString()=="[object UIASecureTextField]" || element.toString()=="[object UIATextView]"){84 return 1;85 }86 return 0;87 }88 this._tap = function(element){89 if(element.toString()=="[object UIASwitch]"){90 if(element.value() != "" && element.value() != null){91 element.setValue(this._falseString(element.value()));92 }93 }else{94 var x = Math.random().toFixed(2);95 var y = Math.random().toFixed(2);96 element.tapWithOptions({tapOffset:{x:x,y:y}});97 }98 }99 this._flick = function(element){100 //element.scrollToVisible();101 var x = Math.random().toFixed(2);102 var y = Math.random().toFixed(2);103 element.flickInsideWithOptions({startOffset:{x:0.5, y:0.5}, endOffset:{x:x,y:y}});104 }105 this._getAppSize = function(){106 var rect = UIATarget.localTarget().frontMostApp().rect();107 return rect;108 }109 this._type = function(element){110 var len = Math.round(Math.random()*100);111 var value = this._randomChar(len);112 element.setValue(value);113 }114 this._falseString = function(value){115 if(value=="0"){116 return "1";117 }else{118 return "0";119 }120 }121 this._randomChar = function(len){122 var x="0123456789qwertyuioplkjhgfdsazxcvbnm";123 var tmp="";124 for(var i = 0;i < len;i++){125 tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);126 }127 return tmp;128 }129 this.operator = function(){130 var element = this._selector();131 UIALogger.logMessage("æ¬æ¬¡æä½ç对象çç±»åæ¯ï¼"+element.toString());132 var ancestry = this. _getElementAncestry(element);133 UIALogger.logMessage(ancestry+element.toString()+"->name:"+element.name());134 if (this._toFlick(element)){135 this._flick(element);136 }else if(this._toType(element)){137 this._type(element);138 }else{139 if(element.hitpoint() != null){140 this._tap(element);141 }142 }143 }144 this.screenShoot = function(imageName){145 var target = UIATarget.localTarget();146 var app = target.frontMostApp();147 target.captureRectWithName(target.frontMostApp().rect(),imageName);148 }149 this.waitForLoad = function(preDelay) { 150 var target = UIATarget.localTarget();151 if (!preDelay) {152 target.delay(0);153 }154 else {155 target.delay(preDelay);156 }157 var done = false;158 var counter = 0; 159 while ((!done) && (counter < 60)) {160 var progressIndicator = UIATarget.localTarget().frontMostApp().windows()[0].activityIndicators()[0];161 var indicator = this._findIndicator(UIATarget.localTarget().frontMostApp());162 if (indicator == 1) {163 UIALogger.logMessage("æ¥å°è¿éçå¾
ä¸ä¸")164 target.delay(0.5);165 counter++; 166 }167 else {168 done = true; 169 }170 }171 target.delay(0.5);172 }173}174mon = new iOSMonkey2();175UIATarget.localTarget().setTimeout(0);176for(var i = 0; i< 1000; i++){177 try{178 mon.operator();179 }catch(err){180 UIALogger.logMessage("è¿éæä¸ä¸ªå¼å¸¸");181 UIALogger.logMessage(err.toString()+"");182 }183 mon.screenShoot("test");184 mon.waitForLoad(1);185 //UIATarget.localTarget().delay(2);...
widget.js
Source:widget.js
1class TimberWidget {2 constructor(element) {3 this._element = document.getElementById('timber-element')4 this._body = document.body5 this._timberElement = document.getElementsByClassName('TimberWidget')[0]6 }7 get element() {8 return this._element9 }10 get documentBody() {11 return this._body12 }13 get timberElement() {14 return this._timberElement15 }16 returnOffset(element) {17 let _x = 018 let _y = 019 while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {20 _x += element.offsetLeft - element.scrollLeft21 _y += element.offsetTop - element.scrollTop22 element = element.offsetParent23 }24 return {25 left: _x,26 top: _y27 }28 }29 appendStyles() {30 let styles = `31 .TimberWidget {32 position: absolute;33 top: 50px;34 left: 200px;35 z-index: 999;36 width: 100%;37 max-width: 320px;38 height: 400px;39 background-color: #fff;40 box-shadow: 0 0 1px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.1);41 border-radius: 5px;42 overflow: hidden;43 }44 .TimberWidget-frame {45 position: relative;46 border: 0;47 outline: 0;48 overflow: hidden;49 border-radius: 5px;50 width: 100%;51 height: 100%;52 }53 `54 document.write(`<style type="text/css">${styles}</style>`)55 }56 createElement() {57 let elementFlickPosition = this.returnOffset(this.element)58 let twContainer = document.createElement('div')59 twContainer.classList.add('TimberWidget')60 twContainer.style.left = elementFlickPosition.left + 'px'61 twContainer.style.top = (elementFlickPosition.top + 20) + 'px'62 twContainer.style.transform = "translateX(-50%)"63 let twFrame = document.createElement('iframe')64 twFrame.src = 'https://alexpate.uk'65 twFrame.classList.add('TimberWidget-frame')66 twContainer.appendChild(twFrame)67 this.documentBody.appendChild(twContainer)68 }69 init() {70 this.appendStyles()71 this.createElement()72 console.log(this.returnOffset(this.element))73 }74}75var timberWidget = new TimberWidget()...
flicking.test.js
Source:flicking.test.js
1describe('flicking flow test', function() {2 var flick,3 flick1,4 data;5 jasmine.getFixtures().fixturesPath = "base/";6 jasmine.getStyleFixtures().fixturesPath = "base/";7 beforeEach(function() {8 loadFixtures("test/fixtures/flick.html");9 loadStyleFixtures('test/fixtures/flick.css');10 data = [11 '<span>flick 1</span>',12 '<span>flick 2</span>',13 '<span>flick 3</span>',14 '<span>flick 4</span>',15 '<span>flick 5</span>'16 ];17 flick = new ne.component.m.Flicking({18 element: document.getElementById('flick'),19 wrapper: document.getElementById('flick-wrap1'),20 isMagnetic: false,21 data: data,22 flow: 'horizontal'23 });24 flick1 = new ne.component.m.Flicking({25 element: document.getElementById('flick2'),26 wrapper: document.getElementById('flick-wrap2')27 });28 });29 it('flicking is defined', function() {30 expect(flick).toBeDefined();31 expect(flick1).toBeDefined();32 var child = flick.wrapper.childNodes;33 expect(child.length).toBe(5);34 });35 describe('set resize for orientation', function() {36 it('resize element', function() {37 flick.setWidth(150);38 var element = flick.element;39 expect(parseInt(element.style.width, 10)).toBe(150);40 });41 });42 describe('drag flow test', function() {43 // todo drag simulation with point44 });45 describe('test magnetic after drag.', function() {46 // todo when touchend/mouseup uprise, check using magnetic47 it('magnetic case', function() {48 });49 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10var webdriver = require('selenium-webdriver'),11 until = webdriver.until;12var driver = new webdriver.Builder()13 .forBrowser('chrome')14 .build();15driver.findElement(By.name('q')).sendKeys('webdriver');16driver.findElement(By.name('btnG')).click();17driver.wait(until.titleIs('webdriver - Google Search'), 1000);18driver.quit();19var webdriver = require('selenium-webdriver'),20 until = webdriver.until;21var driver = new webdriver.Builder()22 .forBrowser('chrome')23 .build();24driver.findElement(By.name('q')).sendKeys('webdriver');25driver.findElement(By.name('btnG')).click();26driver.wait(until.titleIs('webdriver - Google Search'), 1000);27driver.quit();28var webdriver = require('selenium-webdriver'),29 until = webdriver.until;30var driver = new webdriver.Builder()31 .forBrowser('chrome')32 .build();33driver.findElement(By.name('q')).sendKeys('webdriver');34driver.findElement(By.name('btnG')).click();35driver.wait(until.titleIs('webdriver - Google Search'), 1000);36driver.quit();37var webdriver = require('selenium-webdriver'),38 until = webdriver.until;39var driver = new webdriver.Builder()40 .forBrowser('chrome')41 .build();
Using AI Code Generation
1element.flick(100, 100, 100, 100);2element.flick(100, 100, 100, 100, 100);3element.flick(100, 100, 100, 100, 100, 100);4element.flick(100, 100, 100, 100, 100, 100, 100);5element.flick(100, 100, 100, 100, 100, 100, 100, 100);6element.flick(100, 100, 100, 100, 100, 100, 100, 100, 100);7element.flick(100, 100, 100, 100, 100, 100, 100, 100, 100, 100);8element.flick(100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100);
Using AI Code Generation
1describe('Flicking', function() {2 it('should flick the element', function() {3 var el = element(by.id('myElement'));4 el.flick(0, -100);5 });6});7describe('Flicking', function() {8 it('should flick the element', function() {9 var el = element(by.id('myElement'));10 el.flick(0, -100);11 });12});13describe('Flicking', function() {14 it('should flick the element', function() {15 var el = element(by.id('myElement'));16 el.flick(0, -100);17 });18});19describe('Flicking', function() {20 it('should flick the element', function() {21 var el = element(by.id('myElement'));22 el.flick(0, -100);23 });24});25describe('Flicking', function() {26 it('should flick the element', function() {27 var el = element(by.id('myElement'));28 el.flick(0, -100);29 });30});31describe('Flicking', function() {32 it('should flick the element', function() {33 var el = element(by.id('myElement'));34 el.flick(0, -100);35 });36});37describe('Flicking', function() {38 it('should flick the element', function() {39 var el = element(by.id('myElement'));40 el.flick(0, -100);41 });42});43describe('Flicking', function() {44 it('should flick the element', function() {45 var el = element(by.id('myElement'));46 el.flick(0, -100);47 });48});49describe('F
Using AI Code Generation
1public void swipeLeft() {2 int startX = (int) (driver.manage().window().getSize().width * 0.9);3 int endX = (int) (driver.manage().window().getSize().width * 0.1);4 int Y = driver.manage().window().getSize().height / 2;5 TouchAction action = new TouchAction(driver);6 action.press(startX, Y).waitAction(1000).moveTo(endX, Y).release().perform();7}8public void swipeRight() {9 int startX = (int) (driver.manage().window().getSize().width * 0.1);10 int endX = (int) (driver.manage().window().getSize().width * 0.9);11 int Y = driver.manage().window().getSize().height / 2;12 TouchAction action = new TouchAction(driver);13 action.press(startX, Y).waitAction(1000).moveTo(endX, Y).release().perform();14}15public void swipeLeftOnElement(MobileElement element) {16 int startX = (int) (element.getSize().getWidth() * 0.9);17 int endX = (int) (element.getSize().getWidth() * 0.1);18 int Y = element.getSize().getHeight() / 2;19 TouchAction action = new TouchAction(driver);20 action.press(startX, Y).waitAction(1000).moveTo(endX, Y).release().perform();21}22public void swipeRightOnElement(MobileElement element) {23 int startX = (int) (element.getSize().getWidth() * 0.1);24 int endX = (int) (element.getSize().getWidth() * 0.9);25 int Y = element.getSize().getHeight() / 2;26 TouchAction action = new TouchAction(driver);27 action.press(startX, Y
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!