Skip to content

Commit 185c759

Browse files
committed
fix: appium UTs
1 parent 8f530f6 commit 185c759

File tree

2 files changed

+61
-50
lines changed

2 files changed

+61
-50
lines changed

lib/helper/Appium.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class Appium extends Webdriver {
386386
_buildAppiumEndpoint() {
387387
const { protocol, port, hostname, path } = this.browser.options
388388
// Build path to Appium REST API endpoint
389-
return `${protocol}://${hostname}:${port}${path}`
389+
return `${protocol}://${hostname}:${port}${path}/session/${this.browser.sessionId}`
390390
}
391391

392392
/**
@@ -602,7 +602,7 @@ class Appium extends Webdriver {
602602

603603
return this.axios({
604604
method: 'post',
605-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/appium/device/remove_app`,
605+
url: `${this._buildAppiumEndpoint()}/appium/device/remove_app`,
606606
data: { appId, bundleId },
607607
})
608608
}
@@ -619,7 +619,7 @@ class Appium extends Webdriver {
619619
onlyForApps.call(this)
620620
return this.axios({
621621
method: 'post',
622-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/appium/app/reset`,
622+
url: `${this._buildAppiumEndpoint()}/appium/app/reset`,
623623
})
624624
}
625625

@@ -693,7 +693,7 @@ class Appium extends Webdriver {
693693

694694
const res = await this.axios({
695695
method: 'get',
696-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/orientation`,
696+
url: `${this._buildAppiumEndpoint()}/orientation`,
697697
})
698698

699699
const currentOrientation = res.data.value
@@ -717,7 +717,7 @@ class Appium extends Webdriver {
717717

718718
return this.axios({
719719
method: 'post',
720-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/orientation`,
720+
url: `${this._buildAppiumEndpoint()}/orientation`,
721721
data: { orientation },
722722
})
723723
}
@@ -956,21 +956,19 @@ class Appium extends Webdriver {
956956
* ```js
957957
* // taps outside to hide keyboard per default
958958
* I.hideDeviceKeyboard();
959-
* I.hideDeviceKeyboard('tapOutside');
960-
*
961-
* // or by pressing key
962-
* I.hideDeviceKeyboard('pressKey', 'Done');
963959
* ```
964960
*
965961
* Appium: support Android and iOS
966962
*
967-
* @param {'tapOutside' | 'pressKey'} [strategy] Desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’)
968-
* @param {string} [key] Optional key
969963
*/
970-
async hideDeviceKeyboard(strategy, key) {
964+
async hideDeviceKeyboard() {
971965
onlyForApps.call(this)
972-
strategy = strategy || 'tapOutside'
973-
return this.browser.hideKeyboard(strategy, key)
966+
967+
return this.axios({
968+
method: 'post',
969+
url: `${this._buildAppiumEndpoint()}/appium/device/hide_keyboard`,
970+
data: {},
971+
})
974972
}
975973

976974
/**
@@ -1046,7 +1044,13 @@ class Appium extends Webdriver {
10461044
* @param {*} locator
10471045
*/
10481046
async tap(locator) {
1049-
return this.makeTouchAction(locator, 'tap')
1047+
const { elementId } = await this.browser.$(parseLocator.call(this, locator))
1048+
1049+
return this.axios({
1050+
method: 'post',
1051+
url: `${this._buildAppiumEndpoint()}/element/${elementId}/click`,
1052+
data: {},
1053+
})
10501054
}
10511055

10521056
/**
@@ -1493,7 +1497,14 @@ class Appium extends Webdriver {
14931497
*/
14941498
async click(locator, context) {
14951499
if (this.isWeb) return super.click(locator, context)
1496-
return super.click(parseLocator.call(this, locator), parseLocator.call(this, context))
1500+
1501+
const { elementId } = await this.browser.$(parseLocator.call(this, locator), parseLocator.call(this, context))
1502+
1503+
return this.axios({
1504+
method: 'post',
1505+
url: `${this._buildAppiumEndpoint()}/element/${elementId}/click`,
1506+
data: {},
1507+
})
14971508
}
14981509

14991510
/**

test/helper/AppiumV2_test.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Appium', function () {
5858
it('should grab all available contexts for screen', async () => {
5959
await app.resetApp()
6060
await app.waitForElement('~buttonStartWebviewCD', smallWait)
61-
await app.click('~buttonStartWebviewCD')
61+
await app.tap('~buttonStartWebviewCD')
6262
const val = await app.grabAllContexts()
6363
assert.deepEqual(val, ['NATIVE_APP', 'WEBVIEW_io.selendroid.testapp'])
6464
})
@@ -164,7 +164,7 @@ describe('Appium', function () {
164164
it('should set device orientation', async () => {
165165
await app.resetApp()
166166
await app.waitForElement('~buttonStartWebviewCD', smallWait)
167-
await app.click('~buttonStartWebviewCD')
167+
await app.tap('~buttonStartWebviewCD')
168168
await app.setOrientation('LANDSCAPE')
169169
await app.seeOrientationIs('LANDSCAPE')
170170
})
@@ -174,15 +174,15 @@ describe('Appium', function () {
174174
it('should switch context', async () => {
175175
await app.resetApp()
176176
await app.waitForElement('~buttonStartWebviewCD', smallWait)
177-
await app.click('~buttonStartWebviewCD')
177+
await app.tap('~buttonStartWebviewCD')
178178
await app.switchToContext('WEBVIEW_io.selendroid.testapp')
179179
const val = await app.grabContext()
180180
return assert.equal(val, 'WEBVIEW_io.selendroid.testapp')
181181
})
182182

183183
it('should switch to native and web contexts @quick', async () => {
184184
await app.resetApp()
185-
await app.click('~buttonStartWebviewCD')
185+
await app.tap('~buttonStartWebviewCD')
186186
await app.see('WebView location')
187187
await app.switchToWeb()
188188
let val = await app.grabContext()
@@ -219,14 +219,14 @@ describe('Appium', function () {
219219
describe('#hideDeviceKeyboard', () => {
220220
it('should hide device Keyboard @quick', async () => {
221221
await app.resetApp()
222-
await app.click('~startUserRegistrationCD')
222+
await app.tap('~startUserRegistrationCD')
223223
try {
224-
await app.click('//android.widget.CheckBox')
224+
await app.tap('//android.widget.CheckBox')
225225
} catch (e) {
226-
e.message.should.include('element')
226+
e.message.should.include('Request failed with status code 404')
227227
}
228228
await app.hideDeviceKeyboard('pressKey', 'Done')
229-
await app.click('//android.widget.CheckBox')
229+
await app.tap('//android.widget.CheckBox')
230230
})
231231

232232
it('should assert if no keyboard', async () => {
@@ -268,7 +268,7 @@ describe('Appium', function () {
268268
})
269269

270270
it('should react on swipe action', async () => {
271-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
271+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
272272
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
273273
await app.swipe("//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']", 800, 1200, 1000)
274274
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -280,7 +280,7 @@ describe('Appium', function () {
280280
})
281281

282282
it('should react on swipeDown action', async () => {
283-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
283+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
284284
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
285285
await app.swipeDown("//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']", 1200, 1000)
286286
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -291,15 +291,15 @@ describe('Appium', function () {
291291

292292
it('run simplified swipeDown @quick', async () => {
293293
await app.resetApp()
294-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
294+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
295295
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
296296
await app.swipeDown("//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']", 120, 100)
297297
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
298298
assert.equal(type, 'FLICK')
299299
})
300300

301301
it('should react on swipeUp action', async () => {
302-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
302+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
303303
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
304304
await app.swipeUp("//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']", 1200, 1000)
305305
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -309,7 +309,7 @@ describe('Appium', function () {
309309
})
310310

311311
it('should react on swipeRight action', async () => {
312-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
312+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
313313
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
314314
await app.swipeRight("//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']", 800, 1000)
315315
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -319,7 +319,7 @@ describe('Appium', function () {
319319
})
320320

321321
it('should react on swipeLeft action', async () => {
322-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
322+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
323323
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
324324
await app.swipeLeft("//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']", 800, 1000)
325325
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -346,7 +346,7 @@ describe('Appium', function () {
346346
it('should assert when you dont scroll the document anymore', async () => {
347347
await app.resetApp()
348348
await app.waitForElement('~startUserRegistrationCD', smallWait)
349-
await app.click('~startUserRegistrationCD')
349+
await app.tap('~startUserRegistrationCD')
350350
try {
351351
await app.swipeTo('//android.widget.CheckBox', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 500)
352352
} catch (e) {
@@ -357,13 +357,13 @@ describe('Appium', function () {
357357
it('should react on swipeTo action', async () => {
358358
await app.resetApp()
359359
await app.waitForElement('~startUserRegistrationCD', smallWait)
360-
await app.click('~startUserRegistrationCD')
360+
await app.tap('~startUserRegistrationCD')
361361
await app.swipeTo('//android.widget.CheckBox', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 700)
362362
})
363363

364364
describe('#performTouchAction', () => {
365365
it('should react on swipeUp action @second', async () => {
366-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
366+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
367367
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
368368
await app.swipeUp("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
369369
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -374,7 +374,7 @@ describe('Appium', function () {
374374

375375
it('should react on swipeDown action @second', async () => {
376376
await app.resetApp()
377-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
377+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
378378
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
379379
await app.swipeUp("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
380380
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -384,7 +384,7 @@ describe('Appium', function () {
384384
})
385385

386386
it('should react on swipeLeft action', async () => {
387-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
387+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
388388
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
389389
await app.swipeLeft("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
390390
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -394,7 +394,7 @@ describe('Appium', function () {
394394
})
395395

396396
it('should react on swipeRight action', async () => {
397-
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
397+
await app.tap("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']")
398398
await app.waitForText('Gesture Type', 10, "//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
399399
await app.swipeRight("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
400400
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']")
@@ -423,7 +423,7 @@ describe('Appium', function () {
423423

424424
it('should work inside web view as normally @quick', async () => {
425425
await app.resetApp()
426-
await app.click('~buttonStartWebviewCD')
426+
await app.tap('~buttonStartWebviewCD')
427427
await app.switchToWeb()
428428
await app.see('Prefered Car:')
429429
})
@@ -433,12 +433,12 @@ describe('Appium', function () {
433433
it('should be able to send special keys to element @second', async () => {
434434
await app.resetApp()
435435
await app.waitForElement('~startUserRegistrationCD', smallWait)
436-
await app.click('~startUserRegistrationCD')
437-
await app.click('~email of the customer')
436+
await app.tap('~startUserRegistrationCD')
437+
await app.tap('~email of the customer')
438438
await app.appendField('~email of the customer', '1')
439439
await app.hideDeviceKeyboard('pressKey', 'Done')
440440
await app.swipeTo('//android.widget.Button', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 700)
441-
await app.click('//android.widget.Button')
441+
await app.tap('//android.widget.Button')
442442
await app.see('1', '#io.selendroid.testapp:id/label_email_data')
443443
})
444444
})
@@ -486,7 +486,7 @@ describe('Appium', function () {
486486

487487
it('should click by xpath', async () => {
488488
await app.resetApp()
489-
await app.click('//android.widget.ImageButton[@content-desc = "startUserRegistrationCD"]')
489+
await app.tap('//android.widget.ImageButton[@content-desc = "startUserRegistrationCD"]')
490490
await app.seeElement('//android.widget.TextView[@content-desc="label_usernameCD"]')
491491
})
492492
})
@@ -495,34 +495,34 @@ describe('Appium', function () {
495495
it('should fill field by accessibility id', async () => {
496496
await app.resetApp()
497497
await app.waitForElement('~startUserRegistrationCD', smallWait)
498-
await app.click('~startUserRegistrationCD')
498+
await app.tap('~startUserRegistrationCD')
499499
await app.fillField('~email of the customer', 'Nothing special')
500500
await app.hideDeviceKeyboard('pressKey', 'Done')
501501
await app.swipeTo('//android.widget.Button', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 700)
502-
await app.click('//android.widget.Button')
502+
await app.tap('//android.widget.Button')
503503
await app.see('Nothing special', '//android.widget.TextView[@resource-id="io.selendroid.testapp:id/label_email_data"]')
504504
})
505505

506506
it('should fill field by xpath', async () => {
507507
await app.resetApp()
508508
await app.waitForElement('~startUserRegistrationCD', smallWait)
509-
await app.click('~startUserRegistrationCD')
509+
await app.tap('~startUserRegistrationCD')
510510
await app.fillField('//android.widget.EditText[@content-desc="email of the customer"]', 'Nothing special')
511511
await app.hideDeviceKeyboard('pressKey', 'Done')
512512
await app.swipeTo('//android.widget.Button', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 700)
513-
await app.click('//android.widget.Button')
513+
await app.tap('//android.widget.Button')
514514
await app.see('Nothing special', '//android.widget.TextView[@resource-id="io.selendroid.testapp:id/label_email_data"]')
515515
})
516516

517517
it('should append field value @second', async () => {
518518
await app.resetApp()
519519
await app.waitForElement('~startUserRegistrationCD', smallWait)
520-
await app.click('~startUserRegistrationCD')
520+
await app.tap('~startUserRegistrationCD')
521521
await app.fillField('~email of the customer', 'Nothing special')
522522
await app.appendField('~email of the customer', 'blabla')
523523
await app.hideDeviceKeyboard('pressKey', 'Done')
524524
await app.swipeTo('//android.widget.Button', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 700)
525-
await app.click('//android.widget.Button')
525+
await app.tap('//android.widget.Button')
526526
await app.see('Nothing specialblabla', '//android.widget.TextView[@resource-id="io.selendroid.testapp:id/label_email_data"]')
527527
})
528528
})
@@ -531,7 +531,7 @@ describe('Appium', function () {
531531
it('should clear a given element', async () => {
532532
await app.resetApp()
533533
await app.waitForElement('~startUserRegistrationCD', smallWait)
534-
await app.click('~startUserRegistrationCD')
534+
await app.tap('~startUserRegistrationCD')
535535
await app.fillField('~email of the customer', 'Nothing special')
536536
await app.see('Nothing special', '~email of the customer')
537537
await app.clearField('~email of the customer')
@@ -559,7 +559,7 @@ describe('Appium', function () {
559559
await app.appendField('//android.widget.EditText[@content-desc="email of the customer"]', '1')
560560
await app.hideDeviceKeyboard('pressKey', 'Done')
561561
await app.swipeTo('//android.widget.Button', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30, 100, 700)
562-
await app.click('//android.widget.Button')
562+
await app.tap('//android.widget.Button')
563563
await app.see('1', '//android.widget.TextView[@resource-id="io.selendroid.testapp:id/label_email_data"]')
564564
const id = await app.grabNumberOfVisibleElements('//android.widget.TextView[@resource-id="io.selendroid.testapp:id/label_email_data"]', 'contentDescription')
565565
assert.strictEqual(1, id)
@@ -582,7 +582,7 @@ describe('Appium', function () {
582582
it('should use Android locators', async () => {
583583
await app.resetApp()
584584
await app.waitForElement('~startUserRegistrationCD', smallWait)
585-
await app.click({ android: '~startUserRegistrationCD', ios: 'fake-element' })
585+
await app.tap({ android: '~startUserRegistrationCD', ios: 'fake-element' })
586586
await app.see('Welcome to register a new User')
587587
})
588588

0 commit comments

Comments
 (0)