How to use adb.clear method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

createGoogleAccounts.js

Source:createGoogleAccounts.js Github

copy

Full Screen

1const Faker = require('faker');2const ADB = require('./adbf');3const Tools = require('./tools');4const Mysql = require('./mysql');5const MysqlQuery = require('./mysqlQuery');6async function createGoogleAccount(adb, device) {7 try {8 await device.setup(adb);9 await Tools.waitMilli(5000);10 await adb.tapUntilImgFound(device.googleImages.login);11 await Tools.waitMilli(2600);12 await adb.tapUntilImgFound(device.googleImages.createAccount);13 await Tools.waitSec(1);14 await adb.tapUntilImgFound(device.googleImages.myAccount);15 await Tools.waitMilli(1231);16 // Faker.setLocale('ko');17 // Setlocale을 하여도 regex가 설정되지 않았다면 불가능하다.18 const firstName = Faker.name.firstName().replace(/[^a-z0-9A-Z]/g, "");19 const lastName = Faker.name.lastName().replace(/[^a-z0-9A-Z]/g, "");20 const email = (Tools.getRandomFromArray([firstName, lastName]).toLowerCase() + Tools.getRandomLettersOfLenFromPool(6, '1234567890')).replace(/[^a-z0-9]/g, "");21 const password = Tools.getRandomLettersOfLenFromPool(8, '1234567890') + Tools.getRandomLettersOfLenFromPool(4, 'abcdefghijklmnopqrstuvwxyz');22 await adb.tapUntilImgFound(device.googleImages.firstName);23 await adb.type(firstName, device.typeMinInterval, device.typeMaxInterval, true);24 await adb.tapUntilImgFound(device.googleImages.lastName);25 await adb.type(lastName, device.typeMinInterval, device.typeMaxInterval, true);26 await Tools.waitMilli(4000);27 let newGmail = await adb.findImage(device.googleImages.newGmail);28 if (newGmail)29 await adb.tapUntilImgFound(device.googleImages.newGmail);30 let idIsEmpty = await adb.findImage(device.googleImages.userName);31 // if (!idIsEmpty) idIsEmpty = await adb.findImage(device.googleImages.userName2);32 if (!idIsEmpty) {33 await Tools.waitMilli(600);34 await adb.tapImage(device.googleImages.eraseName);35 await Tools.waitMilli(600);36 for (let i = 0; i < 25; i++) {37 await adb.delete();38 }39 }40 else {41 // await adb.tapUntilImgFound([device.googleImages.userName, device.googleImages.userName2]);42 await adb.tapUntilImgFound(device.googleImages.userName);43 }44 await adb.type(email, device.typeMinInterval, device.typeMaxInterval, true);45 await adb.tapUntilImgFound(device.googleImages.password);46 await adb.type(password, device.typeMinInterval, device.typeMaxInterval, true);47 await device.randomScrollDown(adb);48 await adb.tapUntilImgFound(device.googleImages.confirmPassword);49 await adb.type(password, device.typeMinInterval, device.typeMaxInterval, true);50 await Tools.waitMilli(1200);51 await adb.tapUntilImgFound(device.googleImages.next);52 await Tools.waitMilli(4000)53 // 이름 재입력54 const phoneChoice = await adb.findImage(device.googleImages.phoneChoice);55 if (!phoneChoice) {56 console.log('this browser is temporary blocked');57 const clearApp = await adb.getCurrentApp();58 await adb.clearAppData(clearApp);59 return;60 }61 await adb.tapUntilImgFound(device.googleImages.year);62 await adb.typeBasic(Math.floor(Tools.getRandomNumberInRange(1970, 2001)), 110, 600, false);63 await adb.tapUntilImgFound(device.googleImages.date);64 await adb.typeBasic(Math.floor(Tools.getRandomNumberInRange(1, 30)), 110, 600, false);65 await device.dropdown(adb);66 await Tools.waitMilli(1241);67 await adb.tapImage(device.googleImages.next);68 for (let i = 0; i < 10; i++)69 await device.randomScrollDown(adb);70 await adb.tapUntilImgFound(device.googleImages.agreeServices);71 await adb.tapUntilImgFound(device.googleImages.agreeInformation);72 await adb.tapUntilImgFound(device.googleImages.createAccount2);73 await Tools.waitSec(5);74 // 구글 메인화면으로 왔다면 생성 완료75 let retry = 50;76 var isDone = false;77 for (let i = 0; i < retry; i++) {78 if (!isDone)79 isDone = await adb.findImage(device.googleImages.search);80 else break;81 }82 if (isDone) {83 const mysql = await Mysql.new();84 await mysql.exec(MysqlQuery.getInsertGoogleId(email, password, firstName, lastName, device.name, Tools.getCurrentDateTime()));85 }86 const currentApp = await adb.getCurrentApp();87 await adb.clearAppData(currentApp);88 return;89 }90 catch (e) {91 await adb.captureImage();92 console.log('error device = ' + device.name);93 console.log(e);94 return;95 }96}97const s10 = {98 name: 's10',99 typeMinInterval: 110,100 typeMaxInterval: 600,101 setup: async function (adb) {102 await adb.clearAppData('com.sec.android.app.sbrowser');103 await Tools.waitSec(5);104 await adb.openApp('com.sec.android.app.sbrowser');105 await adb.type('');106 await adb.tapUntilImgFound('../img/mobile/samsung/agree.png');107 await Tools.waitMilli(500);108 await adb.tapUntilImgFound('../img/mobile/samsung/later.png');109 await adb.tapUntilImgFound('../img/mobile/samsung/settings.png');110 await adb.tapUntilImgFound('../img/mobile/samsung/lightMode.png');111 await adb.tapUntilImgFound('../img/mobile/samsung/settings.png');112 await adb.tapUntilImgFound('../img/mobile/samsung/options.png');113 await adb.swipe(550, 2000, 550, 0, 1000);114 await Tools.waitMilli(500);115 await adb.tapUntilImgFound('../img/mobile/samsung/personalInfo.png');116 await adb.tapUntilImgFound('../img/mobile/samsung/userNameAndPassword.png');117 await adb.tapUntilImgFound('../img/mobile/samsung/toggle.png');118 await adb.tapUntilImgFound('../img/mobile/samsung/toggle.png');119 await adb.tapUntilImgFound('../img/mobile/samsung/back.png');120 await adb.tapUntilImgFound('../img/mobile/samsung/back.png');121 await adb.tapUntilImgFound('../img/mobile/samsung/back.png');122 await adb.tapUntilImgFound('../img/mobile/samsung/betweenUrl.png');123 await adb.typeBasic('www.google.com');124 await adb.enter();125 },126 dropdown: async function (adb) {127 await adb.tapUntilImgFound('../img/mobile/google/s10/month.png');128 await waitRandom();129 await adb.swipe(550, 2100, 550, Tools.getRandomNumberInRange(1630, 2100), 200);130 await Tools.waitSec(3);131 await adb.tapLocation(550, Tools.getRandomNumberInRange(1650, 2080));132 await adb.tapImage('../img/mobile/samsung/dropdownComplete.png');133 await adb.tapUntilImgFound('../img/mobile/google/s10/sex.png');134 await adb.tapImage('../img/mobile/samsung/dropdownDoNotShow.png');135 await adb.tapImage('../img/mobile/samsung/dropdownComplete.png');136 },137 randomScrollDown: async function (adb) {138 await adb.swipe(139 Tools.getRandomNumberInRange(250, 800),140 Tools.getRandomNumberInRange(1502, 1700),141 Tools.getRandomNumberInRange(250, 800),142 Tools.getRandomNumberInRange(1000, 680), 500);143 },144 googleImages: {145 login: '../img/mobile/google/s10/login.png',146 createAccount: '../img/mobile/google/s10/createAccount.png',147 myAccount: '../img/mobile/google/s10/myAccount.png',148 firstName: '../img/mobile/google/s10/firstName.png',149 lastName: '../img/mobile/google/s10/lastName.png',150 userName: '../img/mobile/google/s10/userName.png',151 // userName2: '../img/mobile/google/s10/userName2.png',152 newGmail: '../img/mobile/google/s10/newGmail.png',153 eraseName: '../img/mobile/google/s10/eraseName.png',154 password: '../img/mobile/google/s10/password.png',155 confirmPassword: '../img/mobile/google/s10/confirmPassword.png',156 next: '../img/mobile/google/s10/next.png',157 phoneChoice: '../img/mobile/google/s10/phoneChoice.png',158 year: '../img/mobile/google/s10/year.png',159 date: '../img/mobile/google/s10/date.png',160 agreeServices: '../img/mobile/google/s10/agreeServices.png',161 agreeInformation: '../img/mobile/google/s10/agreeInformation.png',162 createAccount2: '../img/mobile/google/s10/createAccount2.png',163 search: '../img/mobile/google/s10/search.png'164 }165}166const note5 = {167 name: 'note5',168 typeMinInterval: 100,169 typeMaxInterval: 300,170 setup: async function (adb) {171 await adb.clearAppData('com.sec.android.app.sbrowser');172 await Tools.waitSec(5);173 await adb.openApp('com.sec.android.app.sbrowser');174 await adb.type('');175 await adb.tapUntilImgFound('../img/mobile/samsung/note5/agree.png');176 try {177 await adb.tapUntilImgFound('../img/mobile/samsung/note5/later.png');178 } catch (e) { }179 await adb.tapUntilImgFound('../img/mobile/samsung/note5/settings.png');180 await adb.tapUntilImgFound('../img/mobile/samsung/note5/options.png');181 await adb.swipe(550, 1800, 550, 0, 1000);182 await Tools.waitMilli(500);183 await adb.tapUntilImgFound('../img/mobile/samsung/note5/personalInfo.png');184 await adb.tapUntilImgFound('../img/mobile/samsung/note5/userNameAndPassword.png');185 await adb.tapUntilImgFound('../img/mobile/samsung/note5/toggle.png');186 await adb.tapUntilImgFound('../img/mobile/samsung/note5/toggle.png');187 await adb.tapUntilImgFound('../img/mobile/samsung/note5/back.png');188 await adb.tapUntilImgFound('../img/mobile/samsung/note5/back.png');189 await adb.tapUntilImgFound('../img/mobile/samsung/note5/back.png');190 },191 dropdown: async function (adb) {192 await adb.tapUntilImgFound('../img/mobile/google/note5/month.png');193 await waitRandom();194 await adb.swipe(550, 1800, 550, Tools.getRandomNumberInRange(1400, 1800), 200);195 await Tools.waitSec(3);196 await adb.tapLocation(550, Tools.getRandomNumberInRange(1400, 1800));197 await adb.tapImage('../img/mobile/samsung/note5/dropdownComplete.png');198 await adb.tapUntilImgFound('../img/mobile/google/note5/sex.png');199 await adb.tapImage('../img/mobile/samsung/note5/dropdownDoNotShow.png');200 await adb.tapImage('../img/mobile/samsung/note5/dropdownComplete.png');201 },202 randomScrollDown: async function (adb) {203 await adb.swipe(204 Tools.getRandomNumberInRange(250, 800),205 Tools.getRandomNumberInRange(1502, 1700),206 Tools.getRandomNumberInRange(250, 800),207 Tools.getRandomNumberInRange(900, 680), 500);208 },209 googleImages: {210 login: '../img/mobile/google/note5/login.png',211 createAccount: '../img/mobile/google/note5/createAccount.png',212 myAccount: '../img/mobile/google/note5/myAccount.png',213 firstName: '../img/mobile/google/note5/firstName.png',214 lastName: '../img/mobile/google/note5/lastName.png',215 userName: '../img/mobile/google/note5/userName.png',216 // userName2: '../img/mobile/google/note5/userName2.png',217 newGmail: '../img/mobile/google/note5/newGmail.png',218 eraseName: '../img/mobile/google/note5/eraseName.png',219 password: '../img/mobile/google/note5/password.png',220 confirmPassword: '../img/mobile/google/note5/confirmPassword.png',221 next: '../img/mobile/google/note5/next.png',222 phoneChoice: '../img/mobile/google/note5/phoneChoice.png',223 year: '../img/mobile/google/note5/year.png',224 date: '../img/mobile/google/note5/date.png',225 agreeServices: '../img/mobile/google/note5/agreeServices.png',226 agreeInformation: '../img/mobile/google/note5/agreeInformation.png',227 createAccount2: '../img/mobile/google/note5/createAccount2.png',228 search: '../img/mobile/google/note5/search.png'229 }230}231const a5 = {232 name: 'a5',233 typeMinInterval: 100,234 typeMaxInterval: 300,235 setup: async function (adb) {236 await adb.clearAppData('com.android.chrome');237 await Tools.waitSec(5);238 await adb.openApp('com.android.chrome');239 await adb.type('');240 await adb.tapUntilImgFound('../img/mobile/chrome/a5/check.png');241 await adb.tapUntilImgFound('../img/mobile/chrome/a5/agreeAndContinue.png');242 await adb.tapUntilImgFound('../img/mobile/chrome/a5/skip.png');243 await adb.tapUntilImgFound('../img/mobile/chrome/a5/options.png');244 await adb.tapUntilImgFound('../img/mobile/chrome/a5/settings.png');245 await adb.tapUntilImgFound('../img/mobile/chrome/a5/savePassword.png');246 await adb.tapUntilImgFound('../img/mobile/chrome/a5/toggle.png');247 await adb.tapUntilImgFound('../img/mobile/chrome/a5/toggle.png');248 await adb.tapUntilImgFound('../img/mobile/chrome/a5/back.png');249 await adb.tapUntilImgFound('../img/mobile/chrome/a5/back.png');250 await adb.tapUntilImgFound('../img/mobile/chrome/a5/urlTab.png');251 await adb.typeBasic('www.google.co.kr');252 await adb.enter();253 },254 dropdown: async function (adb) {255 await adb.tapUntilImgFound('../img/mobile/google/a5/month.png');256 await waitRandom();257 await adb.swipe(550, 1200, 550, Tools.getRandomNumberInRange(500, 1200), 200);258 await Tools.waitSec(3);259 await adb.tapLocation(550, Tools.getRandomNumberInRange(1200, 100));260 await adb.swipe(261 Tools.getRandomNumberInRange(100, 650),262 Tools.getRandomNumberInRange(1100, 1250),263 Tools.getRandomNumberInRange(100, 650),264 Tools.getRandomNumberInRange(150, 250), 500);265 await adb.tapUntilImgFound('../img/mobile/google/a5/sex.png');266 await adb.tapImage('../img/mobile/samsung/a5/dropdownDoNotShow.png');267 },268 randomScrollDown: async function (adb) {269 await adb.swipe(270 Tools.getRandomNumberInRange(100, 650),271 Tools.getRandomNumberInRange(950, 1100),272 Tools.getRandomNumberInRange(100, 650),273 Tools.getRandomNumberInRange(200, 400), 500);274 },275 googleImages: {276 login: '../img/mobile/google/a5/login.png',277 createAccount: '../img/mobile/google/a5/createAccount.png',278 myAccount: '../img/mobile/google/a5/myAccount.png',279 firstName: '../img/mobile/google/a5/firstName.png',280 lastName: '../img/mobile/google/a5/lastName.png',281 userName: '../img/mobile/google/a5/userName.png',282 // userName2: '../img/mobile/google/a5/userName2.png',283 newGmail: '../img/mobile/google/a5/newGmail.png',284 eraseName: '../img/mobile/google/a5/eraseName.png',285 password: '../img/mobile/google/a5/password.png',286 confirmPassword: '../img/mobile/google/a5/confirmPassword.png',287 next: '../img/mobile/google/a5/next.png',288 phoneChoice: '../img/mobile/google/a5/phoneChoice.png',289 year: '../img/mobile/google/a5/year.png',290 date: '../img/mobile/google/a5/date.png',291 agreeServices: '../img/mobile/google/a5/agreeServices.png',292 agreeInformation: '../img/mobile/google/a5/agreeInformation.png',293 createAccount2: '../img/mobile/google/a5/createAccount2.png',294 search: '../img/mobile/google/a5/search.png'295 }296}297const s6 = {298 name: 's6',299 typeMinInterval: 100,300 typeMaxInterval: 300,301 setup: async function (adb) {302 await adb.clearAppData('com.sec.android.app.sbrowser');303 await Tools.waitSec(5);304 await adb.openApp('com.sec.android.app.sbrowser');305 await adb.type('');306 await adb.tapUntilImgFound('../img/mobile/samsung/s6/agree.png');307 await adb.tapUntilImgFound('../img/mobile/samsung/s6/settings.png');308 await adb.tapUntilImgFound('../img/mobile/samsung/s6/options.png');309 await adb.swipe(720, 2500, 720, 0, 1000);310 await Tools.waitMilli(500);311 await adb.tapUntilImgFound('../img/mobile/samsung/s6/personalInfo.png');312 await adb.swipe(720, 2500, 720, 0, 1000);313 await Tools.waitMilli(500);314 await adb.tapUntilImgFound('../img/mobile/samsung/s6/userNameAndPassword.png');315 await adb.tapUntilImgFound('../img/mobile/samsung/s6/toggle.png');316 await adb.tapUntilImgFound('../img/mobile/samsung/s6/toggle.png');317 await adb.tapUntilImgFound('../img/mobile/samsung/s6/back.png');318 await adb.tapUntilImgFound('../img/mobile/samsung/s6/back.png');319 await adb.tapUntilImgFound('../img/mobile/samsung/s6/back.png');320 await adb.tapUntilImgFound('../img/mobile/samsung/s6/betweenUrl.png');321 await adb.typeBasic('www.google.co.kr');322 await adb.enter();323 },324 dropdown: async function (adb) {325 await adb.tapUntilImgFound('../img/mobile/google/s6/month.png');326 await waitRandom();327 await adb.swipe(720, 2400, 720, Tools.getRandomNumberInRange(1800, 2400), 200);328 await Tools.waitSec(3);329 await adb.tapLocation(550, Tools.getRandomNumberInRange(1800, 2400));330 await adb.tapImage('../img/mobile/samsung/s6/dropdownComplete.png');331 await adb.tapUntilImgFound('../img/mobile/google/s6/sex.png');332 await adb.tapImage('../img/mobile/samsung/s6/dropdownDoNotShow.png');333 await adb.tapImage('../img/mobile/samsung/s6/dropdownComplete.png');334 },335 randomScrollDown: async function (adb) {336 await adb.swipe(337 Tools.getRandomNumberInRange(300, 1200),338 Tools.getRandomNumberInRange(2200, 2400),339 Tools.getRandomNumberInRange(300, 1200),340 Tools.getRandomNumberInRange(300, 700), 500);341 },342 googleImages: {343 login: '../img/mobile/google/s6/login.png',344 createAccount: '../img/mobile/google/s6/createAccount.png',345 myAccount: '../img/mobile/google/s6/myAccount.png',346 firstName: '../img/mobile/google/s6/firstName.png',347 lastName: '../img/mobile/google/s6/lastName.png',348 userName: '../img/mobile/google/s6/userName.png',349 // userName2: '../img/mobile/google/s6/userName2.png',350 newGmail: '../img/mobile/google/s6/newGmail.png',351 eraseName: '../img/mobile/google/s6/eraseName.png',352 password: '../img/mobile/google/s6/password.png',353 confirmPassword: '../img/mobile/google/s6/confirmPassword.png',354 next: '../img/mobile/google/s6/next.png',355 phoneChoice: '../img/mobile/google/s6/phoneChoice.png',356 year: '../img/mobile/google/s6/year.png',357 date: '../img/mobile/google/s6/date.png',358 agreeServices: '../img/mobile/google/s6/agreeServices.png',359 agreeInformation: '../img/mobile/google/s6/agreeInformation.png',360 createAccount2: '../img/mobile/google/s6/createAccount2.png',361 search: '../img/mobile/google/s6/search.png'362 }363}364const pocoM3 = {365 name: 'pocoM3',366 typeMinInterval: 100,367 typeMaxInterval: 200,368 setup: async function (adb) {369 await adb.clearAppData('com.sec.android.app.sbrowser');370 await Tools.waitSec(5);371 await adb.openApp('com.sec.android.app.sbrowser');372 await adb.type('');373 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/agree.png');374 await Tools.waitMilli(2000);375 await adb.tapImage('../img/mobile/samsung/pocoM3/later.png');376 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/settings.png');377 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/options.png');378 await adb.swipe(540, 2100, 540, 0, 1000);379 await Tools.waitMilli(500);380 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/personalInfo.png');381 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/userNameAndPassword.png');382 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/toggle.png');383 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/toggle.png');384 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/back.png');385 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/back.png');386 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/back.png');387 await Tools.waitMilli(500);388 await adb.tapImage('../img/mobile/samsung/pocoM3/later.png');389 await adb.tapUntilImgFound('../img/mobile/samsung/pocoM3/betweenUrl.png');390 await adb.typeBasic('www.google.com');391 await adb.enter();392 },393 dropdown: async function (adb) {394 await adb.tapUntilImgFound('../img/mobile/google/pocoM3/month.png');395 await waitRandom();396 await adb.swipe(540, 2090, 540, Tools.getRandomNumberInRange(1800, 2090), 200);397 await Tools.waitSec(3);398 await adb.tapLocation(540, Tools.getRandomNumberInRange(1680, 2090));399 await adb.tapImage('../img/mobile/samsung/pocoM3/dropdownComplete.png');400 await adb.tapUntilImgFound('../img/mobile/google/pocoM3/sex.png');401 await adb.tapImage('../img/mobile/samsung/pocoM3/dropdownDoNotShow.png');402 await adb.tapImage('../img/mobile/samsung/pocoM3/dropdownComplete.png');403 },404 randomScrollDown: async function (adb) {405 await adb.swipe(406 Tools.getRandomNumberInRange(150, 900),407 Tools.getRandomNumberInRange(1800, 2050),408 Tools.getRandomNumberInRange(150, 900),409 Tools.getRandomNumberInRange(400, 700), 500);410 },411 googleImages: {412 login: '../img/mobile/google/pocoM3/login.png',413 createAccount: '../img/mobile/google/pocoM3/createAccount.png',414 myAccount: '../img/mobile/google/pocoM3/myAccount.png',415 firstName: '../img/mobile/google/pocoM3/firstName.png',416 lastName: '../img/mobile/google/pocoM3/lastName.png',417 userName: '../img/mobile/google/pocoM3/userName.png',418 // userName2: '../img/mobile/google/pocoM3/userName2.png',419 newGmail: '../img/mobile/google/pocoM3/newGmail.png',420 eraseName: '../img/mobile/google/pocoM3/eraseName.png',421 password: '../img/mobile/google/pocoM3/password.png',422 confirmPassword: '../img/mobile/google/pocoM3/confirmPassword.png',423 next: '../img/mobile/google/pocoM3/next.png',424 phoneChoice: '../img/mobile/google/pocoM3/phoneChoice.png',425 year: '../img/mobile/google/pocoM3/year.png',426 date: '../img/mobile/google/pocoM3/date.png',427 agreeServices: '../img/mobile/google/pocoM3/agreeServices.png',428 agreeInformation: '../img/mobile/google/pocoM3/agreeInformation.png',429 createAccount2: '../img/mobile/google/pocoM3/createAccount2.png',430 search: '../img/mobile/google/pocoM3/search.png'431 }432 // 참고433 // poco의 경우 adbkeybord를 사용하면 언어 및 입력에서 에러가 난다.434 // 직접 다시 돌려놓아야 한다.435 // await pocoAdb.setBasicKeyboard('com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME');436}437async function waitRandom() {438 await Tools.waitMilli(Tools.getRandomNumberInRange(400, 1500));439}440async function main() {441 const s10Code = 'R39M60041TD'442 const s10Adb = ADB.new(s10Code);443 const note5Code = '0915f948d3db1c05'444 const note5Adb = ADB.new(note5Code);445 // const a5Code = '4e05ca11'446 // const a5Adb = ADB.new(a5Code);447 const s6Code = '06157df644e02127'448 const s6Adb = ADB.new(s6Code);449 const pocoCode = '26b22a7d1120'450 const pocoAdb = ADB.new(pocoCode);451 for (let i = 0; i < 200; i++) {452 // await s10Adb.lteOff();453 // await s10Adb.lteOn();454 // await s10Adb.unlock('9347314da');455 // await createGoogleAccount(s10Adb, s10);456 // await s10Adb.lock();457 // await s10Adb.lteOff();458 // await s10Adb.lteOn();459 // await note5Adb.unlock();460 // await createGoogleAccount(note5Adb, note5);461 // await note5Adb.lock();462 // await s10Adb.lteOff();463 // await s10Adb.lteOn();464 // await a5Adb.unlock();465 // await createGoogleAccount(a5Adb, a5);466 // await a5Adb.lock();467 // await s10Adb.lteOff();468 // await s10Adb.lteOn();469 // await s6Adb.unlock();470 // await createGoogleAccount(s6Adb, s6);471 // await s6Adb.lock();472 await s10Adb.lteOff();473 await s10Adb.lteOn();474 await pocoAdb.unlock();475 await createGoogleAccount(pocoAdb, pocoM3);476 await pocoAdb.setBasicKeyboard('com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME');477 await pocoAdb.lock();478 console.log('waiting...');479 await Tools.waitSec(Tools.getRandomNumberInRange(5600, 6600));480 }481}482async function test() {483 const pocoCode = '26b22a7d1120'484 const pocoAdb = ADB.new(pocoCode);485 await pocoAdb.unlock();486}...

Full Screen

Full Screen

element-specs.js

Source:element-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import Bootstrap from '../../../lib/bootstrap';5import AndroidDriver from '../../..';6import ADB from 'appium-adb';7import androidHelpers from '../../../lib/android-helpers';8let driver;9let sandbox = sinon.createSandbox();10chai.should();11chai.use(chaiAsPromised);12describe('Element', function () {13 beforeEach(function () {14 driver = new AndroidDriver();15 driver.adb = new ADB();16 driver.bootstrap = new Bootstrap();17 sandbox.stub(driver.bootstrap, 'sendAction');18 sandbox.stub(androidHelpers, 'removeNullProperties');19 driver.opts = {unicodeKeyboard: true};20 });21 afterEach(function () {22 sandbox.restore();23 });24 describe('getAttribute', function () {25 it('should get element attribute', async function () {26 driver.bootstrap.sendAction.withArgs('element:getAttribute').returns('attr_value');27 await driver.getAttribute('attr', 'el1').should.become('attr_value');28 driver.bootstrap.sendAction29 .calledWithExactly('element:getAttribute', {attribute: 'attr', elementId: 'el1'})30 .should.be.true;31 });32 });33 describe('getName', function () {34 it('should get element name', async function () {35 sandbox.stub(driver, 'getAttribute');36 driver.getAttribute.returns('el_name');37 await driver.getName('el1').should.become('el_name');38 driver.getAttribute.calledWithExactly('className', 'el1').should.be.true;39 });40 });41 describe('elementDisplayed', function () {42 it('should return true if element displayed', async function () {43 sandbox.stub(driver, 'getAttribute');44 driver.getAttribute.returns('true');45 await driver.elementDisplayed('el1').should.become(true);46 driver.getAttribute.calledWithExactly('displayed', 'el1').should.be.true;47 });48 it('should return false if element not displayed', async function () {49 sandbox.stub(driver, 'getAttribute');50 driver.getAttribute.returns('false');51 await driver.elementDisplayed('el1').should.become(false);52 driver.getAttribute.calledWithExactly('displayed', 'el1').should.be.true;53 });54 });55 describe('elementEnabled', function () {56 it('should return true if element enabled', async function () {57 sandbox.stub(driver, 'getAttribute');58 driver.getAttribute.returns('true');59 await driver.elementEnabled('el1').should.become(true);60 driver.getAttribute.calledWithExactly('enabled', 'el1').should.be.true;61 });62 it('should return false if element not enabled', async function () {63 sandbox.stub(driver, 'getAttribute');64 driver.getAttribute.returns('false');65 await driver.elementEnabled('el1').should.become(false);66 driver.getAttribute.calledWithExactly('enabled', 'el1').should.be.true;67 });68 });69 describe('elementSelected', function () {70 it('should return true if element selected', async function () {71 sandbox.stub(driver, 'getAttribute');72 driver.getAttribute.returns('true');73 await driver.elementSelected('el1').should.become(true);74 driver.getAttribute.calledWithExactly('selected', 'el1').should.be.true;75 });76 it('should return false if element not selected', async function () {77 sandbox.stub(driver, 'getAttribute');78 driver.getAttribute.returns('false');79 await driver.elementSelected('el1').should.become(false);80 driver.getAttribute.calledWithExactly('selected', 'el1').should.be.true;81 });82 });83 describe('setElementValue', function () {84 const params = {85 elementId: 'el0',86 text: 'text to set',87 replace: true,88 unicodeKeyboard: true,89 };90 it('should call doSetElementValue', async function () {91 sandbox.stub(driver, 'doSetElementValue');92 await driver.setElementValue('text to set', 'el0', true);93 driver.doSetElementValue.calledWithExactly(params).should.be.true;94 });95 it('should join keys parameter if keys is instance of Array', async function () {96 sandbox.stub(driver, 'doSetElementValue');97 await driver.setElementValue(['t', 'ext', ' to ', 'se', 't'], 'el0', true);98 driver.doSetElementValue.calledWithExactly(params).should.be.true;99 });100 it('should set replace to false by default', async function () {101 params.replace = false;102 sandbox.stub(driver, 'doSetElementValue');103 await driver.setElementValue(['t', 'ext', ' to ', 'se', 't'], 'el0');104 driver.doSetElementValue.calledWithExactly(params).should.be.true;105 });106 });107 describe('doSetElementValue', function () {108 it('should call setText to set element value', async function () {109 await driver.doSetElementValue('params');110 driver.bootstrap.sendAction.calledWithExactly('element:setText',111 'params').should.be.true;112 });113 });114 describe('setValue', function () {115 it('should call setElementValue to set value', async function () {116 sandbox.stub(driver, 'setElementValue');117 await driver.setValue('keys', 'el1');118 driver.setElementValue.calledWithExactly('keys', 'el1', false).should.be.true;119 });120 });121 describe('replaceValue', function () {122 it('should call setElementValue to replace value', async function () {123 sandbox.stub(driver, 'setElementValue');124 await driver.replaceValue('keys', 'el1');125 driver.setElementValue.calledWithExactly('keys', 'el1', true).should.be.true;126 });127 });128 describe('setValueImmediate', function () {129 it('should set value via adb inputText command', async function () {130 sandbox.stub(driver, 'click');131 sandbox.stub(driver.adb, 'inputText');132 await driver.setValueImmediate('keys', 'el1');133 driver.click.calledWithExactly('el1').should.be.true;134 driver.adb.inputText.calledWithExactly('keys').should.be.true;135 });136 it('should join keys parameter if keys is instance of Array', async function () {137 sandbox.stub(driver, 'click');138 sandbox.stub(driver.adb, 'inputText');139 await driver.setValueImmediate(['k', 'ey', 's'], 'el1');140 driver.adb.inputText.calledWithExactly('keys').should.be.true;141 });142 });143 describe('getText', function () {144 it('should get element text', async function () {145 driver.bootstrap.sendAction.withArgs('element:getText').returns('el_text');146 await driver.getText('el1').should.become('el_text');147 driver.bootstrap.sendAction148 .calledWithExactly('element:getText', {elementId: 'el1'})149 .should.be.true;150 });151 });152 describe('clear', function () {153 it('should clear text of an element', async function () {154 sandbox.stub(driver, 'getText');155 sandbox.stub(driver, 'click');156 sandbox.stub(driver.adb, 'clearTextField');157 driver.getText.withArgs('el1').returns('#'.repeat(110));158 await driver.clear('el1');159 driver.getText.calledWithExactly('el1').should.be.true;160 driver.click.calledWithExactly('el1').should.be.true;161 driver.adb.clearTextField.getCall(0).args[0].should.be.equal(50);162 driver.adb.clearTextField.getCall(1).args[0].should.be.equal(50);163 driver.adb.clearTextField.getCall(2).args[0].should.be.equal(10);164 });165 it('should do five retries and then fail if clearTextField throws error', async function () {166 this.timeout(10000);167 sandbox.stub(driver, 'getText');168 sandbox.stub(driver, 'click');169 sandbox.stub(driver.adb, 'clearTextField');170 driver.adb.clearTextField.throws();171 driver.getText.withArgs('el1').returns('#'.repeat(1));172 await driver.clear('el1').should.be.rejected;173 driver.adb.clearTextField.alwaysCalledWith(1).should.be.true;174 driver.adb.clearTextField.callCount.should.be.equal(5);175 });176 it('it should assume that the text have 100 chars if getText returns empty string', async function () {177 sandbox.stub(driver, 'getText');178 sandbox.stub(driver, 'click');179 sandbox.stub(driver.adb, 'clearTextField');180 driver.getText.withArgs('el1').returns('');181 await driver.clear('el1');182 driver.adb.clearTextField.getCall(0).args[0].should.be.equal(50);183 driver.adb.clearTextField.getCall(1).args[0].should.be.equal(50);184 });185 });186 describe('click', function () {187 it('should click an element', async function () {188 await driver.click('el1');189 driver.bootstrap.sendAction.calledWithExactly('element:click', {elementId: 'el1'})190 .should.be.true;191 });192 });193 describe('getLocation', function () {194 it('should get location of an element', async function () {195 driver.bootstrap.sendAction196 .withArgs('element:getLocation').returns('loc_info');197 await driver.getLocation('el1').should.become('loc_info');198 driver.bootstrap.sendAction199 .calledWithExactly('element:getLocation', {elementId: 'el1'})200 .should.be.true;201 });202 });203 describe('getLocationInView', function () {204 it('should get location of an element', async function () {205 sandbox.stub(driver, 'getLocation');206 driver.getLocation.returns('loc_info');207 await driver.getLocationInView('el1').should.become('loc_info');208 driver.getLocation.calledWithExactly('el1').should.be.true;209 });210 });211 describe('getSize', function () {212 it('should get size of an element', async function () {213 driver.bootstrap.sendAction214 .withArgs('element:getSize').returns('size_info');215 await driver.getSize('el1').should.become('size_info');216 driver.bootstrap.sendAction217 .calledWithExactly('element:getSize', {elementId: 'el1'})218 .should.be.true;219 });220 });221 describe('getElementRect', function () {222 it('should get rect of an element', async function () {223 driver.bootstrap.sendAction224 .withArgs('element:getRect').returns('rect_info');225 await driver.getElementRect('el1').should.become('rect_info');226 driver.bootstrap.sendAction227 .calledWithExactly('element:getRect', {elementId: 'el1'})228 .should.be.true;229 });230 });231 describe('touchLongClick', function () {232 it('should do touch long click on element', async function () {233 let params = {elementId: 'el1', x: 12, y: 34, duration: 5};234 await driver.touchLongClick('el1', 12, 34, 5);235 androidHelpers.removeNullProperties.calledWithExactly(params)236 .should.be.true;237 driver.bootstrap.sendAction.calledWithExactly('element:touchLongClick', params)238 .should.be.true;239 });240 });241 describe('touchDown', function () {242 it('should do touch down on element', async function () {243 let params = {elementId: 'el1', x: 12, y: 34};244 await driver.touchDown('el1', 12, 34);245 androidHelpers.removeNullProperties.calledWithExactly(params)246 .should.be.true;247 driver.bootstrap.sendAction.calledWithExactly('element:touchDown', params)248 .should.be.true;249 });250 });251 describe('touchUp', function () {252 it('should do touch up on element', async function () {253 let params = {elementId: 'el1', x: 12, y: 34};254 await driver.touchUp('el1', 12, 34);255 androidHelpers.removeNullProperties.calledWithExactly(params)256 .should.be.true;257 driver.bootstrap.sendAction.calledWithExactly('element:touchUp', params)258 .should.be.true;259 });260 });261 describe('touchMove', function () {262 it('should get element attribute', async function () {263 let params = {elementId: 'el1', x: 12, y: 34};264 await driver.touchMove('el1', 12, 34);265 androidHelpers.removeNullProperties.calledWithExactly(params)266 .should.be.true;267 driver.bootstrap.sendAction.calledWithExactly('element:touchMove', params)268 .should.be.true;269 });270 });271 describe('complexTap', function () {272 it('should tap an element', async function () {273 await driver.complexTap(null, null, null, 12, 34);274 driver.bootstrap.sendAction.calledWithExactly('click', {x: 12, y: 34})275 .should.be.true;276 });277 });278 describe('tap', function () {279 it('should tap element with coordinates', async function () {280 await driver.tap('el1', 12, 34, 3);281 driver.bootstrap.sendAction.alwaysCalledWith('element:click',282 {elementId: 'el1', x: 12, y: 34}).should.be.true;283 driver.bootstrap.sendAction.calledThrice.should.be.true;284 });285 it('should tap without an element', async function () {286 await driver.tap(null, 12, 34, 3);287 driver.bootstrap.sendAction.alwaysCalledWith('click', {x: 12, y: 34})288 .should.be.true;289 driver.bootstrap.sendAction.calledThrice.should.be.true;290 });291 it('should perform single tap on element if x, y and count are not passed', async function () {292 await driver.tap('el1');293 driver.bootstrap.sendAction.alwaysCalledWith('element:click').should.be.true;294 driver.bootstrap.sendAction.calledOnce.should.be.true;295 });296 });...

Full Screen

Full Screen

account.js

Source:account.js Github

copy

Full Screen

...261 , reply.fail('Add account failed: account was already added')262 ])263 })264 .catch(function() {265 return adb.clear(options.serial, 'com.google.android.gsf.login')266 .catch(function() {267 // The package name is different in 2.3, so let's try the old name268 // if the new name fails.269 return adb.clear(options.serial, 'com.google.android.gsf')270 })271 .then(function() {272 return service.addAccountMenu()273 })274 .delay(5000)275 .then(function() {276 // Just in case the add account menu has any button focused277 return touch.tap({x: 0, y: 0.9})278 })279 .delay(500)280 .then(function() {281 return automation()282 })283 .delay(3000)...

Full Screen

Full Screen

lock-mgmt-e2e-specs.js

Source:lock-mgmt-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import ADB from '../../lib/adb.js';4chai.use(chaiAsPromised);5describe('Lock Management', function () {6 let adb;7 before(async function () {8 adb = await ADB.createADB();9 if (!await adb.isLockManagementSupported()) {10 return this.skip();11 }12 });13 it('lock credential cleanup should work', async function () {14 await adb.clearLockCredential();15 await adb.verifyLockCredential().should.eventually.be.true;16 await adb.isLockEnabled().should.eventually.be.false;17 });18 describe('Lock and unlock life cycle', function () {19 const password = '1234';20 before(function () {21 if (process.env.CI) {22 // We don't want to lock the device for all other tests if this test fails23 return this.skip();24 }25 });26 afterEach(async function () {27 await adb.clearLockCredential(password);28 });29 it('device lock and unlock scenario should work', async function () {30 await adb.setLockCredential('password', password);31 await adb.keyevent(26);32 await adb.isLockEnabled().should.eventually.be.true;33 await adb.isScreenLocked().should.eventually.be.true;34 await adb.clearLockCredential(password);35 await adb.cycleWakeUp();36 await adb.dismissKeyguard();37 await adb.isLockEnabled().should.eventually.be.false;38 await adb.isScreenLocked().should.eventually.be.false;39 });40 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .getTitle().then(function(title) {20 console.log('Title was: ' + title);21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .getTitle().then(function(title) {31 console.log('Title was: ' + title);32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .getTitle().then(function(title) {42 console.log('Title was: ' + title);43 })44 .end();45var webdriverio = require('webdriverio');46var options = {47 desiredCapabilities: {48 }49};50 .remote(options)

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome'}).build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var Appium = require('appium');4var AndroidDriver = require('appium-android-driver');5var ADB = require('appium-adb');6var server = Appium.main;7var port = 4723;8var driver = null;9server.start({10}, function (err) {11 if (err) {12 console.log(err);13 }14 console.log('Appium server started on port ' + port);15});16driver = new AndroidDriver({17});18var adb = new ADB();19adb.clear('com.android.calculator2', function (err, data) {20 if (err) {21 console.log(err);22 }23 console.log('Data cleared successfully');24});25server.stop(function (err) {26 if (err) {27 console.log(err);28 }29 console.log('Appium server stopped');30});

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.clear('com.android.calculator2:id/formula');2driver.clear('com.android.calculator2:id/result');3driver.pressKeyCode(66);4driver.longPressKeyCode(66);5driver.isKeyboardShown();6driver.hideKeyboard();7driver.pushFile('/sdcard/test.txt', 'Hello World');8driver.pullFile('/sdcard/test.txt');9driver.pullFolder('/sdcard/DCIM/Camera');10driver.lock(10);11driver.unlock();12driver.isLocked();13driver.toggleData();14driver.toggleWiFi();15driver.toggleAirplaneMode();16driver.toggleLocationServices();17driver.getSettings();18driver.updateSettings({ignoreUnimportantViews: true});19driver.startActivity('com.android.calculator2', 'com.android.calculator2.Calculator');20driver.startActivity('com.android.calculator2', 'com.android.calculator2.Calculator', 'com.android.calculator2', '.Calculator', 'android.intent.action.MAIN', 'android.intent.category.LAUNCHER', 'android.intent.category.DEFAULT');21driver.getCurrentActivity();22driver.getDeviceTime();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .elementByClassName('android.widget.EditText').clear().type('Hello World')9 .end();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful