How to use this.getLocationInView method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

cocoObj.js

Source:cocoObj.js Github

copy

Full Screen

1var cocoCommands = {2    add: function (num1, num2, num3) {3        this4        return num1 + num2 + num35    },6    menuItems: function (data) {7        this8            .click(data.menu)9            .verify.urlEquals(data.url)10    },11    shopSubItems: function (data) {12        this13            .moveToElement('@shopMenu', 5, 5)14            .pause(1000)15            .click(data.link)16            .verify.urlEquals(data.url)17    },18    productContents: function (data) {19        this20            .moveToElement('@shopMenu', 5, 5)21            .moveToElement(data.link, 5, 5)22            .click(data.link)23            .verify.urlEquals(data.url)24            // .expect.element('[itemprop="name"]').text.to.equal(itemName2.toUpperCase())25            .verify.elementPresent('@prodName')26            .verify.elementPresent('@prodRating')27            .verify.elementPresent('@prodDescription')28            .verify.elementPresent('@prodGallery')29            .verify.elementPresent('@prodQuantity')30            .verify.elementPresent('@prodCart')31    },32    treatCart: function (data) {33        //For 4-Piece Set34        var itemName = 'cocofloss ' + data.set + ' set'35        //For Watermelon Flavor36        // var watermelonName = 'Limited-Edition Summer Watermelon Cocofloss'       //**Flavor No Longer Available */37        //For 3-Piece38        var darkChocName = 'DARK CHOCOLATE COCOFLOSS'39        var itemName2 = 'cocofloss ' + data.set40        this41            .getLocationInView('@allReviews')42        if (data.set === '4-Piece' && data.flavor === 'Mixed') {43            this44                .click('@treatFragrance1')45                .click('@mixed')46                .click('@treatAddCart1')47                .expect.element('.label-3.cart-item__details__heading').text.to.equal(itemName.toUpperCase())48            this49                .expect.element('.p4.cart-item__details__description').text.to.equal(data.flavor + ' Fragrances')50            this51                .pause(1000)52                .click('@remove')53                .pause(1000)54                .click('@closeCart')55        }56        else if (data.set === '4-Piece' && data.flavor === 'Strawberry') {57            this58                .click('@treatFragrance1')59                .click('@strawberry')60                .click('@treatAddCart1')61                .expect.element('.label-3.cart-item__details__heading').text.to.equal(itemName.toUpperCase())62            this63                .expect.element('.p4.cart-item__details__description').text.to.equal(data.flavor + ' Fragrances')64            this65                .pause(1000)66                .click('@remove')67                .pause(1000)68                .click('@closeCart')69        }70        else if (data.set === '4-Piece' && data.flavor === 'Orange') {71            this72                .click('@treatFragrance1')73                .click('@orange')74                .click('@treatAddCart1')75                .expect.element('.label-3.cart-item__details__heading').text.to.equal(itemName.toUpperCase())76            this77                .expect.element('.p4.cart-item__details__description').text.to.equal(data.flavor + ' Fragrances')78            this79                .pause(1000)80                .click('@remove')81                .pause(1000)82                .click('@closeCart')83        }84        //** FLAVOR NO LONGER AVAILABLE */85        // else if (data.set === 'Watermelon' && data.count === 'one') {86        //     this87        //         .click('@selectQuantity')88        //         .click(`@${data.count}Quantity`)89        //         .click('@treatAddCart3')90        //         .expect.element('.label-3.cart-item__details__heading').text.to.equal(darkChocName)91        //     this92        //         .expect.element('.p4.cart-item__details__description').text.to.equal('Single')93        //     this94        //         .click('@remove')95        //         .click('@closeCart')96        // }97        // else if (data.set === 'Watermelon' && data.count === 'two') {98        //     this99        //         .click('@selectQuantity')100        //         .click(`@${data.count}Quantity`)101        //         .click('@treatAddCart3')102        //         .expect.element('.label-3.cart-item__details__heading').text.to.equal(darkChocName)103        //     this104        //         .expect.element('.p4.cart-item__details__description').text.to.equal('2-Piece Set')105        //     this106        //         .click('@remove')107        //         .click('@closeCart')108        // }109        // else if (data.set === 'Watermelon' && data.count === 'three') {110        //     this111        //         .click('@selectQuantity')112        //         .click(`@${data.count}Quantity`)113        //         .click('@treatAddCart3')114        //         .expect.element('.label-3.cart-item__details__heading').text.to.equal(darkChocName)115        //     this116        //         .expect.element('.p4.cart-item__details__description').text.to.equal('3-Piece Set')117        //     this118        //         .click('@remove')119        //         .click('@closeCart')120        // }121        else if (data.set === 'Dark Chocolate' && data.count === 'one') {122            this123                .click('@selectQuantity')124                .click(`@${data.count}Quantity`)125                .click('@treatAddCart3')126                .expect.element('.label-3.cart-item__details__heading').text.to.equal(darkChocName)127            this128                .expect.element('.p4.cart-item__details__description').text.to.equal('Single')129            this130                .pause(1000)131                .click('@remove')132                .pause(1000)133                .click('@closeCart')134        }135        else if (data.set === 'Dark Chocolate' && data.count === 'two') {136            this137                .click('@selectQuantity')138                .click(`@${data.count}Quantity`)139                .click('@treatAddCart3')140                .expect.element('.label-3.cart-item__details__heading').text.to.equal(darkChocName)141            this142                .expect.element('.p4.cart-item__details__description').text.to.equal('2-Piece Set')143            this144                .pause(1000)145                .click('@remove')146                .pause(1000)147                .click('@closeCart')148        }149        else if (data.set === 'Dark Chocolate' && data.count === 'three') {150            this151                .click('@selectQuantity')152                .click(`@${data.count}Quantity`)153                .click('@treatAddCart3')154                .expect.element('.label-3.cart-item__details__heading').text.to.equal(darkChocName)155            this156                .expect.element('.p4.cart-item__details__description').text.to.equal('3-Piece Set')157            this158                .pause(1000)159                .click('@remove')160                .pause(1000)161                .click('@closeCart')162        }163        else if (data.set === '3-Piece' && data.flavor === 'Mixed') {164            this165                .click('@treatFragrance2')166                .click('@mixed2')167                .click('@treatAddCart2')168                .expect.element('.label-3.cart-item__details__heading').text.to.equal(itemName2.toUpperCase())169            this170                .expect.element('.p4.cart-item__details__description').text.to.equal('Mixed fruits')171            this172                .pause(1000)173                .click('@remove')174                .pause(1000)175                .click('@closeCart')176        }177        else if (data.set === '3-Piece' && data.flavor === 'Strawberry') {178            this179                .click('@treatFragrance2')180                .click('@strawberry2')181                .click('@treatAddCart2')182                .expect.element('.label-3.cart-item__details__heading').text.to.equal(itemName2.toUpperCase())183            this184                .expect.element('.p4.cart-item__details__description').text.to.equal('Strawberries')185            this186                .pause(1000)187                .click('@remove')188                .pause(1000)189                .click('@closeCart')190        }191        else if (data.set === '3-Piece' && data.flavor === 'Orange') {192            this193                .click('@treatFragrance2')194                .click('@orange2')195                .click('@treatAddCart2')196                .expect.element('.label-3.cart-item__details__heading').text.to.equal(itemName2.toUpperCase())197            this198                .expect.element('.p4.cart-item__details__description').text.to.equal('Cara cara orange')199            this200                .pause(1000)201                .click('@remove')202                .pause(1000)203                .click('@closeCart')204            return this205        }206    },207    reviewPopup: function () {208        this209            .click('@star')210            .pause(1000)211            .verify.elementPresent('.yotpo-modal-content')212            .click('@nextPage')213            .pause(2000)214            .click('@nextPage')215            .pause(2000)216            .click('@prevPage')217            .pause(2000)218            .click('@writeReview')219            .verify.elementPresent('@reviewTitle')220            .verify.elementPresent('@reviewContent')221            .verify.elementPresent('@reviewUser')222            .verify.elementPresent('@reviewEmail')223            .click('@closeReview')224        return this225    },226    cuSisters: function () {227        this228            .moveToElement('@ourStoryBtn', 5, 5)229            .verify.visible('@cuTitle')230            .verify.visible('@cuContent')231            .verify.visible('@ourStoryBtn')232            .click('@ourStoryBtn')233            .verify.urlEquals('https://cocofloss.com/pages/our-story')234        return this235    },236    getCocofloss: function () {237        this238            .getLocationInView('@footer')239            .verify.elementPresent('@igSectionTitle')240            .verify.elementPresent('@igGallery')241        return this242    },243    footerVisibility: function () {244        this245            .getLocationInView('@footer')246            .verify.elementPresent('@footer')247            .verify.visible('@joinTeamTitle')248            .verify.visible('@joinTeamContent')249            .verify.visible('@newsletterInput')250    },251    footerLinks: function (data) {252        this253            .getLocationInView('@footer')254            .click(data.footer)255            .verify.urlEquals(data.url)256            .navigate('https://cocofloss.com/')257        return this258    },259    socialMedia: function () {260        this261            .getLocationInView('@footer')262            .assert.attributeContains('@facebook', 'href', 'http://www.facebook.com/lovecocofloss')263            .assert.attributeContains('@instagram', 'href', 'http://instagram.com/getcocofloss')264            .assert.attributeContains('@email', 'href', 'mailto:help@cocofloss.com')265        return this266    },267    checkout: function (data) {268        this269            //First item added to cart270            .click('@treatFragrance1')271            .pause(1000)272            .click('@mixed')273            .pause(1000)274            .click('@treatAddCart1')275            .pause(1000)276            .click('@closeCart')277            .pause(1000)278            //Second item added to cart279            .click('@selectQuantity')280            .pause(1000)281            .click('@twoQuantity')282            .pause(1000)283            .click('@treatAddCart3')284            .pause(1000)285            .click('@closeCart')286            //Third item added to cart287            .click('@treatFragrance2')288            .pause(1000)289            .click('@orange2')290            .pause(1000)291            .click('@treatAddCart2')292            .pause(1000)293            //Checkout294            .click('@checkout')295            .verify.urlEquals('https://cocofloss.com/cart')296            .verify.visible('#note')297            .pause(1000)298            //Verify then Checkout299            .click('@checkoutCheckout')300            //Contact and Shipping Info Page301            .verify.elementPresent('@emailHolder')302            .verify.elementPresent('@firstNameHolder')303            .verify.elementPresent('@lastNameHolder')304            .verify.elementPresent('@addressHolder')305            .verify.elementPresent('@address2Holder')306            .verify.elementPresent('@cityHolder')307            .verify.elementPresent('@countryDropdown')308            .verify.elementPresent('@stateDropdown')309            .verify.elementPresent('@zipHolder')310            .verify.elementPresent('@codeHolder')311            //Information Input312            .setValue('@emailHolder', data.email)313            .pause(500)314            .setValue('@firstNameHolder', data.firstName)315            .pause(500)316            .setValue('@lastNameHolder', data.lastName)317            .pause(1000)318            .setValue('@addressHolder', data.address1)319            .pause(2000)320            .api.keys(this.api.Keys.ENTER)321            .pause(1000)322        this323            .setValue('@address2Holder', data.address2)324            .click('#continue_button')325            //Shipping Options326            .assert.containsText('@confirmationEmail', data.email)327            .pause(1000)328            .assert.containsText('@confirmationAddress', data.address1 + ', ' + data.address2 + ', Cupertino CA 95014, United States')329            .pause(1000)330            .verify.elementPresent('@shippingOptions')331            .pause(1000)332            .click('#continue_button')333            .pause(1000)334            //Payment Informtion335            .assert.containsText('@confirmationEmail', data.email)336            .assert.containsText('@confirmationAddress', data.address1 + ', ' + data.address2 + ', Cupertino CA 95014, United States')337            .pause(1000)338            .verify.elementPresent('@payPal')339            .verify.elementPresent('@amazonPay')340        return this341    },342    contactSection: function () {343        this344        .getLocationInView('@footer')345        .assert.elementPresent('@contactTitle')346        .assert.attributeContains('@marketingEmail', 'href', 'mailto:marketing@cocofloss.com')347        .assert.attributeContains('@wholeSaleEmail', 'href', 'mailto:wholesale@cocofloss.com')348    }349}350module.exports = {351    url: 'https://cocofloss.com/',352    commands: [cocoCommands],353    elements: {354        //PopUp Window355        closePopup: '#closeIconContainer',356        //Menu Items357        cocoMenu: '[title="Cocofloss"]',358        shopMenu: '[data-subnav=".js-menu-subnav"]',359        subSaveMenu: {360            selector: '//*[text()="Subscribe & Save"]',361            locateStrategy: 'xpath'362        },363        whyCocoMenu: {364            selector: '//*[text()="Why Cocofloss"]',365            locateStrategy: 'xpath'366        },367        blogMenu: {368            selector: '//*[text()="Blog"]',369            locateStrategy: 'xpath'370        },371        signInMenu: {372            selector: '//*[text()="Sign In"]',373            locateStrategy: 'xpath'374        },375        //Shop SubMenu Items376        //Floss SubMenu377        fourPiece: {378            selector: '//*[text()="4-Piece Set"]',379            locateStrategy: 'xpath'380        },381        threePiece: {382            selector: '(//*[text()="3-Piece Set"])[1]',383            locateStrategy: 'xpath'384        },385        threeRefill: {386            selector: '//*[text()="Refill 3-Piece Set"]',387            locateStrategy: 'xpath'388        },389        susClean: {390            selector: '//*[text()="Sustainably Clean Pack"]',391            locateStrategy: 'xpath'392        },393        shopAll1: {394            selector: '(//*[text()="Shop All"])[1]',395            locateStrategy: 'xpath'396        },397        //Gifts SubMenu398        gratitude: {399            selector: '//*[text()="Gratitude Set"]',400            locateStrategy: 'xpath'401        },402        soothing: {403            selector: '//*[text()="Soothing Sets"]',404            locateStrategy: 'xpath'405        },406        pinaColada: {407            selector: '//*[text()="Piña Colada Totes"]',408            locateStrategy: 'xpath'409        },410        balBliss: {411            selector: '//*[text()="Balance & Bliss Journal"]',412            locateStrategy: 'xpath'413        },414        flossParty: {415            selector: '//*[text()="How to Floss Party Book"]',416            locateStrategy: 'xpath'417        },418        giftCard: {419            selector: '//*[text()="Gift Card"]',420            locateStrategy: 'xpath'421        },422        shopAll2: {423            selector: '(//*[text()="Shop All"])[2]',424            locateStrategy: 'xpath'425        },426        //Shop by Fragrance427        // watermelon: {428        //     selector: '//*[text()="Summer Watermelon"]',     //**Flavor No Longer Available */429        //     locateStrategy: 'xpath'430        // },431        darkChoc: {432            selector: '//*[text()="Dark Chocolate"]',433            locateStrategy: 'xpath'434        },435        deliciousMint: {436            selector: '//*[text()="Delicious Mint"]',437            locateStrategy: 'xpath'438        },439        freshCoconut: {440            selector: '//*[text()="Fresh Coconut"]',441            locateStrategy: 'xpath'442        },443        pureStrawberry: {444            selector: '//*[text()="Pure Strawberry"]',445            locateStrategy: 'xpath'446        },447        caraCaraOrange: {448            selector: '//*[text()="Cara Cara Orange"]',449            locateStrategy: 'xpath'450        },451        shopAll3: {452            selector: '(//*[text()="Shop All"])[3]',453            locateStrategy: 'xpath'454        },455        //Product Pages456        prodName: '[itemprop="name"]',457        prodRating: '.yotpo-bottomline.pull-left.star-clickable',458        prodDescription: '[itemprop="description"]',459        prodGallery: '.nine.columns.alpha',460        prodQuantity: {461            selector: '(//*[@class="left product-quantity-box"])[1]',462            locateStrategy: 'xpath'463        },464        prodCart: '.purchase.inline_purchase',465        //Treat Your Teeth466        //4-Piece Set467        treatFragrance1: {468            selector: '(//*[text()="Select A Fragrance"])[1]',469            locateStrategy: 'xpath'470        },471        //4-Piece Options472        mixed: '[for="swatch-0-mixed-fragrances-273101094939"]',473        strawberry: '[for="swatch-0-pure-strawberry-273101094939"]',474        orange: '[for="swatch-0-cara-cara-orange-273101094939"]',475        //** FLAVOR NO LONGER AVAILABLE*/476        // //Watermelon477        // selectQuantity: {478        //     selector: '//*[text()="Select A Quantity"]',479        //     locateStrategy: 'xpath'480        // },481        // //Watermelon Quantities482        // oneQuantity: '[for="swatch-0-single-1324978569310"]',483        // twoQuantity: '[for="swatch-0-2-piece-set-1324978569310"]',484        // threeQuantity: '[for="swatch-0-3-piece-set-1324978569310"]',485        // treatAddCart2: {486        //     selector: '(//*[text()="Add to Cart"])[2]',487        //     locateStrategy: 'xpath'488        // },489        //Dark Chocolate490        selectQuantity: {491            selector: '//*[text()="Select A set"]',492            locateStrategy: 'xpath'493        },494        //Dark Chocolate Quantities495        oneQuantity: '[data-value="Single"]',496        twoQuantity: '[data-value="2-Piece Set"]',497        threeQuantity: '[data-value="3-Piece Set"]',498        //3-Piece Set499        treatFragrance2: {500            selector: '(//*[text()="Select A Fragrance"])[2]',501            locateStrategy: 'xpath'502        },503        //3-Piece Options504        strawberry2: '[for="swatch-0-strawberries-246013624347"]',505        orange2: '[for="swatch-0-cara-cara-orange-246013624347"]',506        mixed2: '[for="swatch-0-mixed-fruits-246013624347"]',507        //Treat Section Add to Cart Buttons508        treatAddCart1: {509            selector: '(//*[text()="Add to Cart"])[1]',510            locateStrategy: 'xpath'511        },512        treatAddCart2: {513            selector: '(//*[text()="Add to Cart"])[2]',514            locateStrategy: 'xpath'515        },516        treatAddCart3: {517            selector: '(//*[text()="Add to Cart"])[3]',518            locateStrategy: 'xpath'519        },520        //Cart521        cart: '.cart-count.header__cart-count',522        closeCart: '.mini-cart__close',523        remove: '.p-small-2.underline.cart-item__remove', //remove item from cart524        //See All Customer Reviews525        allReviews: {526            selector: '//*[text()="See all Customer Reviews"]',527            locateStrategy: 'xpath'528        },529        //★ Reviews530        star: '[href="#yotpo-testimonials"]',531        starWindow: '.yotpo-modal-content',532        nextPage: '[rel="next"]',533        prevPage: '[rel="prev"]',534        writeReview: '[value="write a review"]',535        reviewTitle: '#yotpo_input_review_title',536        reviewContent: '#yotpo_input_review_content',537        reviewUser: '#yotpo_input_review_username',538        reviewEmail: '#yotpo_input_review_email',539        closeReview: {540            selector: '(//*[@class="yotpo-icon yotpo-icon-cross"])[1]',541            locateStrategy: 'xpath'542        },543        //Meet The Cu Sisters544        cuTitle: '.landing-sister__title.h2.mb1',545        cuContent: '.landing-sister__text.text-max.mha.p1.mb2',546        ourStoryBtn: {547            selector: '(//*[@href="/pages/our-story"])[1]',548            locateStrategy: 'xpath'549        },550        //@COCOFLOSS551        igSectionTitle: '.h2.landing-social__title.mb1.align-c',552        igGallery: '.landing-social__grid',553        //Footer554        footer: '#shopify-section-landing-footer',555        joinTeamTitle: {556            selector: '//*[text() = "Join the floss team"]',557            locateStrategy: 'xpath'558        },559        joinTeamContent: {560            selector: '//*[text() = "Keep in touch for special offers and self-care tips for everyday bliss."]',561            locateStrategy: 'xpath'562        },563        newsletterInput: '.newsletter',564        //Footer Links565        blogFooter: {566            selector: '//*[text()="Our Blog"]',567            locateStrategy: 'xpath'568        },569        ourStoryFooter: {570            selector: '(//*[text()="Our Story"])[2]',571            locateStrategy: 'xpath'572        },573        pressFooter: {574            selector: '//*[text()="Press"]',575            locateStrategy: 'xpath'576        },577        dentalProsFooter: {578            selector: '//*[text()="Dental Pros"]',579            locateStrategy: 'xpath'580        },581        manageMySubscriptionFooter: {582            selector: '//*[text()="Manage My Subscription"]',583            locateStrategy: 'xpath'584        },585        storeLocatorFooter: {586            selector: '//*[text()="Store Locator"]',587            locateStrategy: 'xpath'588        },589        jobsFooter: {590            selector: '//*[text()="Jobs"]',591            locateStrategy: 'xpath'592        },593        helpFaqFooter: {594            selector: '//*[text()="Help & FAQ"]',595            locateStrategy: 'xpath'596        },597        //Footer Social Media Links598        facebook: '.icon-facebook',599        instagram: '.icon-instagram',600        email: '.icon-mail',601        //Cart Items602        item1: '.p-small-2.cart-item__total-inner.align-r',603        item2: {604            selector: '(//*[@class="p-small-2 cart-item__total-inner align-r"])[2]',605            locateStrategy: 'xpath'606        },607        item3: {608            selector: '(//*[@class="p-small-2 cart-item__total-inner align-r"])[3]',609            locateStrategy: 'xpath'610        },611        subTotal: '.p-medium2',612        //Checkout Button613        checkout: {614            selector: '//*[text()="Checkout"]',615            locateStrategy: 'xpath'616        },617        checkoutCheckout: {618            selector: '(//*[@type="submit"])[1]',619            locateStrategy: 'xpath'620        },621        emailHolder: '[placeholder="Email"]',622        firstNameHolder: '[placeholder="First name (optional)"]',623        lastNameHolder: '[placeholder="Last name"]',624        addressHolder: '[placeholder="Address"]',625        address2Holder: '[placeholder="Apartment, suite, etc. (optional)"]',626        cityHolder: '[placeholder="City"]',627        countryDropdown: {628            selector: '(//*[@class="field__input-wrapper field__input-wrapper--select"])[1]',629            locateStrategy: 'xpath'630        },631        stateDropdown: {632            selector: '(//*[@class="field__input-wrapper field__input-wrapper--select"])[2]',633            locateStrategy: 'xpath'634        },635        zipHolder: '[placeholder="ZIP code"]',636        codeHolder: '[placeholder="Gift card or discount code"]',637        confirmationEmail: '[dir="ltr"]',638        confirmationAddress: '.address.address--tight',639        shippingOptions: {640            selector: '(//*[@class="content-box"])[2]',641            locateStrategy: 'xpath'642        },643        selectedShipping: '.radio__label__primary',644        payPal: '[alt="PayPal"]',645        amazonPay: '[alt="Amazon Pay"]', 646        //Contact Section647        contactTitle: {648            selector: '//*[text()="Contact"]',649            locateStrategy: 'xpath'650        },651        marketingEmail: '[href="mailto:marketing@cocofloss.com"]',652        wholeSaleEmail: '[href="mailto:wholesale@cocofloss.com"]'653    }...

Full Screen

Full Screen

imdbObj.js

Source:imdbObj.js Github

copy

Full Screen

...26        return this27    },28    explStream: function (browser, option) {29        this.useXpath()30        this.getLocationInView(`(//li[@tabindex="0"])[${option.sel}]`)31        this.pause(500)32        this.click(`(//li[@tabindex="0"])[${option.sel}]`)33        this.verify.containsText(`//p[contains(text(), "${option.conf}")]`, option.conf)34        return this35    },36    bottomLinksExt: function (browser, option) {37        var originalWindow = ""38        this.api.windowHandle(result=>{39            originalWindow = result.value40        })41        this.getLocationInView('@copy')42        this.pause(2000)43        this.getLocationInView('@copy')44        this.pause(2000)45        this.click(option.sel)46        this.api.windowHandles(function(result){47            var handle= result.value[1]48            browser.switchWindow (handle)49        })50        this.verify.elementPresent(option.conf)51        this.closeWindow()52        this.switchWindow(originalWindow)53        return this54    },55    bottomLinksInt: function (browser, option) {56        this.getLocationInView(option.sel)57        this.pause(1000)58        this.getLocationInView(option.sel)59        this.pause(1000)60        this.click(option.sel)61        this.verify.elementPresent(option.conf)62        this.navigate()63        return this64    }65}66module.exports = {67    url: 'https://www.imdb.com/?ref_=nv_home',68    commands: [imdbCommands],69    elements: {70        //Home Page71        menu: {72            selector: '//label[@id="imdbHeader-navDrawerOpen--desktop"]',...

Full Screen

Full Screen

touch.js

Source:touch.js Github

copy

Full Screen

...59      startY = longPress.options.y || 0,60      endX = moveTo.options.x || 0,61      endY = moveTo.options.y || 0;62  if (longPress.options.element) {63    let {x, y} = await this.getLocationInView(longPress.options.element);64    startX += x || 0;65    startY += y || 0;66  }67  if (moveTo.options.element) {68    let {x, y} = await this.getLocationInView(moveTo.options.element);69    endX += x || 0;70    endY += y || 0;71  }72  let apiLevel = await this.adb.getApiLevel();73  // lollipop takes a little longer to get things rolling74  let duration = apiLevel >= 5 ? 2 : 1;75  // make sure that if the long press has a duration, we use it.76  if (longPress.options && longPress.options.duration) {77    duration = Math.max(longPress.options.duration / 1000, duration);78  }79  // `drag` will take care of whether there is an element or not at that level80  return await this.drag(startX, startY, endX, endY, duration, 1, longPress.options.element, moveTo.options.element);81};82// Release gesture needs element or co-ordinates to release it from that position83// or else release gesture is performed from center of the screen, so to fix it84// This method sets co-ordinates/element to release gesture if it has no options set already.85helpers.fixRelease = async function fixRelease (gestures) {86  let release = _.last(gestures);87  // sometimes there are no options88  release.options = release.options || {};89  // nothing to do if release options are already set90  if (release.options.element || (release.options.x && release.options.y)) {91    return;92  }93  // without coordinates, `release` uses the center of the screen, which,94  // generally speaking, is not what we want95  // therefore: loop backwards and use the last command with an element and/or96  // offset coordinates97  gestures = _.clone(gestures);98  let ref = null;99  for (let gesture of gestures.reverse()) {100    let opts = gesture.options;101    if (opts.element || (opts.x && opts.y)) {102      ref = gesture;103      break;104    }105  }106  if (ref) {107    let opts = ref.options;108    if (opts.element) {109      let loc = await this.getLocationInView(opts.element);110      if (opts.x && opts.y) {111        // this is an offset from the element112        release.options = {113          x: loc.x + opts.x,114          y: loc.y + opts.y115        };116      } else {117        // this is the center of the element118        let size = await this.getSize(opts.element);119        release.options = {120          x: loc.x + size.width / 2,121          y: loc.y + size.height / 2122        };123      }124    } else {125      release.options = _.pick(opts, 'x', 'y');126    }127  }128  return release;129};130// Perform one gesture131helpers.performGesture = async function performGesture (gesture) {132  try {133    return await this.doTouchAction(gesture.action, gesture.options || {});134  } catch (e) {135    // sometime the element is not available when releasing, retry without it136    if (isErrorType(e, errors.NoSuchElementError) && gesture.action === 'release' &&137        gesture.options.element) {138      delete gesture.options.element;139      this.log.debug(`retrying release without element opts: ${gesture.options}.`);140      return await this.doTouchAction(gesture.action, gesture.options || {});141    }142    throw e;143  }144};145commands.getSwipeOptions = async function getSwipeOptions (gestures, touchCount = 1) {146  let startX = getCoordDefault(gestures[0].options.x),147      startY = getCoordDefault(gestures[0].options.y),148      endX = getCoordDefault(gestures[2].options.x),149      endY = getCoordDefault(gestures[2].options.y),150      duration = getSwipeTouchDuration(gestures[1]),151      element = gestures[0].options.element,152      destElement = gestures[2].options.element || gestures[0].options.element;153  // there's no destination element handling in bootstrap and since it applies to all platforms, we handle it here154  if (util.hasValue(destElement)) {155    let locResult = await this.getLocationInView(destElement);156    let sizeResult = await this.getSize(destElement);157    let offsetX = (Math.abs(endX) < 1 && Math.abs(endX) > 0) ? sizeResult.width * endX : endX;158    let offsetY = (Math.abs(endY) < 1 && Math.abs(endY) > 0) ? sizeResult.height * endY : endY;159    endX = locResult.x + offsetX;160    endY = locResult.y + offsetY;161    // if the target element was provided, the coordinates for the destination need to be relative to it.162    if (util.hasValue(element)) {163      let firstElLocation = await this.getLocationInView(element);164      endX -= firstElLocation.x;165      endY -= firstElLocation.y;166    }167  }168  // clients are responsible to use these options correctly169  return {startX, startY, endX, endY, duration, touchCount, element};170};171commands.performTouch = async function performTouch (gestures) {172  // press-wait-moveTo-release is `swipe`, so use native method173  if (gestures.length === 4 &&174      gestures[0].action === 'press' &&175      gestures[1].action === 'wait' &&176      gestures[2].action === 'moveTo' &&177      gestures[3].action === 'release') {178    let swipeOpts = await this.getSwipeOptions(gestures);179    return await this.swipe(swipeOpts.startX, swipeOpts.startY, swipeOpts.endX,180        swipeOpts.endY, swipeOpts.duration, swipeOpts.touchCount,181        swipeOpts.element);182  }183  let actions = _.map(gestures, 'action');184  if (actions[0] === 'longPress' && actions[1] === 'moveTo' && actions[2] === 'release') {185    // some things are special186    return await this.doTouchDrag(gestures);187  } else {188    if (actions.length === 2) {189      // `press` without a wait is too slow and gets interpretted as a `longPress`190      if (_.head(actions) === 'press' && _.last(actions) === 'release') {191        actions[0] = 'tap';192        gestures[0].action = 'tap';193      }194      // the `longPress` and `tap` methods release on their own195      if ((_.head(actions) === 'tap' || _.head(actions) === 'longPress') && _.last(actions) === 'release') {196        gestures.pop();197        actions.pop();198      }199    } else {200      // longpress followed by anything other than release should become a press and wait201      if (actions[0] === 'longPress') {202        actions = ['press', 'wait', ...actions.slice(1)];203        let press = gestures.shift();204        press.action = 'press';205        let wait = {206          action: 'wait',207          options: {ms: press.options.duration || 1000}208        };209        delete press.options.duration;210        gestures = [press, wait, ...gestures];211      }212    }213    let fixedGestures = await this.parseTouch(gestures, false);214    // fix release action then perform all actions215    if (actions[actions.length - 1] === 'release') {216      actions[actions.length - 1] = await this.fixRelease(gestures);217    }218    for (let g of fixedGestures) {219      await this.performGesture(g);220    }221  }222};223helpers.parseTouch = async function parseTouch (gestures, multi) {224  // because multi-touch releases at the end by default225  if (multi && _.last(gestures).action === 'release') {226    gestures.pop();227  }228  let touchStateObjects = await asyncmap(gestures, async (gesture) => {229    let options = gesture.options || {};230    if (_.includes(['press', 'moveTo', 'tap', 'longPress'], gesture.action)) {231      options.offset = false;232      let elementId = gesture.options.element;233      if (elementId) {234        let pos = await this.getLocationInView(elementId);235        if (gesture.options.x || gesture.options.y) {236          options.x = pos.x + (gesture.options.x || 0);237          options.y = pos.y + (gesture.options.y || 0);238        } else {239          const {width, height} = await this.getSize(elementId);240          options.x = pos.x + (width / 2);241          options.y = pos.y + (height / 2);242        }243        let touchStateObject = {244          action: gesture.action,245          options,246          timeOffset: 0.005,247        };248        return touchStateObject;...

Full Screen

Full Screen

element.js

Source:element.js Github

copy

Full Screen

...179      return null;180    }181  }182  const size = await this.getSize(el);183  const topLeftCoord = await this.getLocationInView(el);184  return JSON.stringify({185    width: size.width,186    height: size.height,187    top: topLeftCoord.y,188    left: topLeftCoord.x,189    scrollableOffset: contentHeight190  });191};192Object.assign(extensions, commands, helpers);193export { commands, helpers };...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

...8    selectImg: function(elements, callback) {9        var x;10        var y;11        this.waitForElementVisible(elements);12        this.getLocationInView(elements, function(result) {13                x = result.value.x;14                y = result.value.y;15            })16            .moveToElement(elements, x, y)17            .api.pause(5000);18        return this;19    }20};21module.exports = {22    url: 'http://google.com',23    commands: [searchCommands],24    elements: {25        searchBar: { selector: 'input[type=text]' },26        submitButton: {...

Full Screen

Full Screen

RentSettings.js

Source:RentSettings.js Github

copy

Full Screen

...20          .api.pause(waitForModalAnimationsToFinishIGuess);21      return this;22    },23    nextPage: function () {24      return this.getLocationInView('@nextButtonPage')25          .click("@nextButtonPage")26    }27  }]...

Full Screen

Full Screen

waitUntilAnimEnd.js

Source:waitUntilAnimEnd.js Github

copy

Full Screen

...13    var checkInterval = interval || 250;14    var initialLoc = { x: -1, y: -1 };15    this.waitForVisible(selector, timeOut);16    return this.waitUntil(function () {17        var loc = this.getLocationInView(selector);18        if (loc.x === initialLoc.x && loc.y === initialLoc.y) {19            return true;20        }21        initialLoc = loc;22        return false;23    }, timeOut, checkInterval);...

Full Screen

Full Screen

UtilObject.js

Source:UtilObject.js Github

copy

Full Screen

...3      nextButtonPage: '#next-button',4  },5  commands: [{6      nextPage: function() {7        return this.getLocationInView('@nextButtonPage')8        .click("@nextButtonPage")9      }10  }]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2const opts = {3    capabilities: {4    }5};6(async () => {7    const client = await remote(opts);8    console.log(location);9    await client.deleteSession();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {remote} = require('webdriverio');2const { execSync } = require('child_process');3(async () => {4    const browser = await remote({5        capabilities: {6        }7    });8    const location = await elem.getLocationInView();9    console.log(location);10    await browser.deleteSession();11})();12const {remote} = require('webdriverio');13const { execSync } = require('child_process');14(async () => {15    const browser = await remote({16        capabilities: {17        }18    });19    const location = await elem.getLocationInView();20    console.log(location);21    await browser.deleteSession();22})();23const {remote} = require('webdriverio');24const { execSync } = require('child_process');25(async () => {26    const browser = await remote({27        capabilities: {28        }29    });30    const location = await elem.getLocationInView();31    console.log(location);32    await browser.deleteSession();33})();

Full Screen

Using AI Code Generation

copy

Full Screen

1let location = await driver.getLocationInView(element);2let location = await driver.getLocationInView(element);3let location = await driver.getLocationInView(element);4let location = await driver.getLocationInView(element);5let location = await driver.getLocationInView(element);6let location = await driver.getLocationInView(element);7let location = await driver.getLocationInView(element);8let location = await driver.getLocationInView(element);9let location = await driver.getLocationInView(element);10let location = await driver.getLocationInView(element);11let location = await driver.getLocationInView(element);12let location = await driver.getLocationInView(element);13let location = await driver.getLocationInView(element);14let location = await driver.getLocationInView(element);15let location = await driver.getLocationInView(element);16let location = await driver.getLocationInView(element);17let location = await driver.getLocationInView(element);18let location = await driver.getLocationInView(element);19let location = await driver.getLocationInView(element);20let location = await driver.getLocationInView(element);21let location = await driver.getLocationInView(element);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var expect = chai.expect;7var desiredCaps = {8};9var driver = wd.promiseChainRemote('localhost', 4723);10driver.init(desiredCaps).then(function () {11  return driver.elementByAccessibilityId('myElement').getLocationInView();12}).then(function (location) {13  console.log(location);14  expect(location.x).to.be.a('number');15  expect(location.y).to.be.a('number');16}).fin(function () {17  return driver.quit();18}).done();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require("webdriverio");2const assert = require("assert");3const options = {4  capabilities: {5  }6};7(async function() {8  try {9    const client = await wdio.remote(options);10    let location = await client.getLocationInView("accessibility id", "1");11    await client.tap(location.x, location.y);12    location = await client.getLocationInView("accessibility id", "2");13    await client.tap(location.x, location.y);14    location = await client.getLocationInView("accessibility id", "3");15    await client.tap(location.x, location.y);16    location = await client.getLocationInView("accessibility id", "4");17    await client.tap(location.x, location.y);18    location = await client.getLocationInView("accessibility id", "5");19    await client.tap(location.x, location.y);20    location = await client.getLocationInView("accessibility id", "6");21    await client.tap(location.x, location.y);22    location = await client.getLocationInView("accessibility id", "7");23    await client.tap(location.x, location.y);24    location = await client.getLocationInView("accessibility id", "8");

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 Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful