MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / swipeTo

Method swipeTo

lib/helper/Appium.js:1319–1375  ·  view source on GitHub ↗

* Perform a swipe in selected direction on an element to searchable element. * * ```js * I.swipeTo( * "android.widget.CheckBox", // searchable element * "//android.widget.ScrollView/android.widget.LinearLayout", // scroll element * "up", // direction * 30, * 100,

(searchableLocator, scrollLocator, direction, timeout, offset, speed)

Source from the content-addressed store, hash-verified

1317 * Appium: support Android and iOS
1318 */
1319 async swipeTo(searchableLocator, scrollLocator, direction, timeout, offset, speed) {
1320 onlyForApps.call(this)
1321 direction = direction || 'down'
1322 switch (direction) {
1323 case 'down':
1324 direction = 'swipeDown'
1325 break
1326 case 'up':
1327 direction = 'swipeUp'
1328 break
1329 case 'left':
1330 direction = 'swipeLeft'
1331 break
1332 case 'right':
1333 direction = 'swipeRight'
1334 break
1335 }
1336 timeout = timeout || this.options.waitForTimeoutInSeconds
1337
1338 const errorMsg = `element ("${searchableLocator}") still not visible after ${timeout}seconds`
1339 const browser = this.browser
1340 let err = false
1341 let currentSource
1342 return browser
1343 .waitUntil(
1344 async () => {
1345 if (err) {
1346 return new Error(`Scroll to the end and element ${searchableLocator} was not found`)
1347 }
1348 const els = await browser.$$(parseLocator.call(this, searchableLocator))
1349 if (els.length) {
1350 const displayed = await this._isDisplayedSafe(els[0])
1351 if (displayed) {
1352 return true
1353 }
1354 }
1355
1356 await this[direction](scrollLocator, offset, speed)
1357 const source = await this.browser.getPageSource()
1358 if (source === currentSource) {
1359 err = true
1360 } else {
1361 currentSource = source
1362 return false
1363 }
1364 },
1365 timeout * 1000,
1366 errorMsg,
1367 )
1368 .catch(e => {
1369 if (e.message.indexOf('timeout') && e.type !== 'NoSuchElement') {
1370 throw new AssertionFailedError({ customMessage: `Scroll to the end and element ${searchableLocator} was not found` }, '')
1371 } else {
1372 throw e
1373 }
1374 })
1375 }
1376

Callers 3

Appium_test.jsFile · 0.80
AppiumTs.types.tsFile · 0.80
Appium.types.tsFile · 0.80

Calls 2

_isDisplayedSafeMethod · 0.95
$$Method · 0.80

Tested by

no test coverage detected