|
| 1 | +const assert = require('assert'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +const Appium = require('../../lib/helper/Appium'); |
| 5 | +const AssertionFailedError = require('../../lib/assert/error'); |
| 6 | +const fileExists = require('../../lib/utils').fileExists; |
| 7 | +global.codeceptjs = require('../../lib'); |
| 8 | + |
| 9 | +let app; |
| 10 | +// iOS test app is built from https://github.com/appium/ios-test-app and uploaded to Saucelabs |
| 11 | +const apk_path = 'storage:filename=TestApp-iphonesimulator.zip'; |
| 12 | +const smallWait = 3; |
| 13 | + |
| 14 | +describe('Appium iOS Tests', function () { |
| 15 | + this.timeout(0); |
| 16 | + |
| 17 | + before(async () => { |
| 18 | + global.codecept_dir = path.join(__dirname, '/../data'); |
| 19 | + app = new Appium({ |
| 20 | + app: apk_path, |
| 21 | + appiumV2: true, |
| 22 | + desiredCapabilities: { |
| 23 | + 'sauce:options': { |
| 24 | + appiumVersion: '2.0.0', |
| 25 | + }, |
| 26 | + browserName: '', |
| 27 | + recordVideo: 'false', |
| 28 | + recordScreenshots: 'false', |
| 29 | + platformName: 'iOS', |
| 30 | + platformVersion: '12.2', |
| 31 | + deviceName: 'iPhone 8 Simulator', |
| 32 | + androidInstallTimeout: 90000, |
| 33 | + appWaitDuration: 300000, |
| 34 | + }, |
| 35 | + restart: true, |
| 36 | + protocol: 'http', |
| 37 | + host: 'ondemand.saucelabs.com', |
| 38 | + port: 80, |
| 39 | + user: process.env.SAUCE_USERNAME, |
| 40 | + key: process.env.SAUCE_ACCESS_KEY, |
| 41 | + }); |
| 42 | + await app._beforeSuite(); |
| 43 | + app.isWeb = false; |
| 44 | + await app._before(); |
| 45 | + }); |
| 46 | + |
| 47 | + after(async () => { |
| 48 | + await app._after(); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('app installation : #removeApp', () => { |
| 52 | + describe( |
| 53 | + '#grabAllContexts, #grabContext, #grabOrientation, #grabSettings', |
| 54 | + () => { |
| 55 | + it('should grab all available contexts for screen', async () => { |
| 56 | + await app.resetApp(); |
| 57 | + const val = await app.grabAllContexts(); |
| 58 | + assert.deepEqual(val, ['NATIVE_APP']); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should grab current context', async () => { |
| 62 | + const val = await app.grabContext(); |
| 63 | + assert.equal(val, 'NATIVE_APP'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should grab custom settings', async () => { |
| 67 | + const val = await app.grabSettings(); |
| 68 | + assert.deepEqual(val, { imageElementTapStrategy: 'w3cActions' }); |
| 69 | + }); |
| 70 | + }, |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('device orientation : #seeOrientationIs #setOrientation', () => { |
| 75 | + it('should return correct status about device orientation', async () => { |
| 76 | + await app.seeOrientationIs('PORTRAIT'); |
| 77 | + try { |
| 78 | + await app.seeOrientationIs('LANDSCAPE'); |
| 79 | + } catch (e) { |
| 80 | + e.should.be.instanceOf(AssertionFailedError); |
| 81 | + e.inspect().should.include('expected orientation to be LANDSCAPE'); |
| 82 | + } |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('#hideDeviceKeyboard', () => { |
| 87 | + it('should hide device Keyboard @quick', async () => { |
| 88 | + await app.resetApp(); |
| 89 | + await app.click('~IntegerA'); |
| 90 | + try { |
| 91 | + await app.click('~locationStatus'); |
| 92 | + } catch (e) { |
| 93 | + e.message.should.include('element'); |
| 94 | + } |
| 95 | + await app.hideDeviceKeyboard('pressKey', 'Done'); |
| 96 | + await app.click('~locationStatus'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should assert if no keyboard', async () => { |
| 100 | + try { |
| 101 | + await app.hideDeviceKeyboard('pressKey', 'Done'); |
| 102 | + } catch (e) { |
| 103 | + e.message.should.include('An unknown server-side error occurred while processing the command. Original error: Soft keyboard not present, cannot hide keyboard'); |
| 104 | + } |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('see text : #see', () => { |
| 109 | + it('should work inside elements @second', async () => { |
| 110 | + await app.resetApp(); |
| 111 | + await app.see('Compute Sum', '~ComputeSumButton'); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + describe('#appendField', () => { |
| 116 | + it('should be able to send special keys to element @second', async () => { |
| 117 | + await app.resetApp(); |
| 118 | + await app.waitForElement('~IntegerA', smallWait); |
| 119 | + await app.click('~IntegerA'); |
| 120 | + await app.appendField('~IntegerA', '1'); |
| 121 | + await app.hideDeviceKeyboard('pressKey', 'Done'); |
| 122 | + await app.see('1', '~IntegerA'); |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + describe('#waitForText', () => { |
| 127 | + it('should return error if not present', async () => { |
| 128 | + try { |
| 129 | + await app.waitForText('Nothing here', 1, '~IntegerA'); |
| 130 | + } catch (e) { |
| 131 | + e.message.should.contain('element (~IntegerA) is not in DOM or there is no element(~IntegerA) with text "Nothing here" after 1 sec'); |
| 132 | + } |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + describe('#seeNumberOfElements @second', () => { |
| 137 | + it('should return 1 as count', async () => { |
| 138 | + await app.resetApp(); |
| 139 | + await app.seeNumberOfElements('~IntegerA', 1); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + describe('see element : #seeElement, #dontSeeElement', () => { |
| 144 | + it('should check visible elements on page @quick', async () => { |
| 145 | + await app.resetApp(); |
| 146 | + await app.seeElement('~IntegerA'); |
| 147 | + await app.dontSeeElement('#something-beyond'); |
| 148 | + await app.dontSeeElement('//input[@id="something-beyond"]'); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + describe('#click @quick', () => { |
| 153 | + it('should click by accessibility id', async () => { |
| 154 | + await app.resetApp(); |
| 155 | + await app.tap('~ComputeSumButton'); |
| 156 | + await app.see('0'); |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
| 160 | + describe('#fillField @second', () => { |
| 161 | + it('should fill field by accessibility id', async () => { |
| 162 | + await app.resetApp(); |
| 163 | + await app.waitForElement('~IntegerA', smallWait); |
| 164 | + await app.click('~IntegerA'); |
| 165 | + await app.fillField('~IntegerA', '1'); |
| 166 | + await app.hideDeviceKeyboard('pressKey', 'Done'); |
| 167 | + await app.see('1', '~IntegerA'); |
| 168 | + }); |
| 169 | + }); |
| 170 | + |
| 171 | + describe('#grabTextFrom, #grabValueFrom, #grabAttributeFrom @quick', () => { |
| 172 | + it('should grab text from page', async () => { |
| 173 | + await app.resetApp(); |
| 174 | + const val = await app.grabTextFrom('~ComputeSumButton'); |
| 175 | + assert.equal(val, 'Compute Sum'); |
| 176 | + }); |
| 177 | + |
| 178 | + it('should grab attribute from element', async () => { |
| 179 | + await app.resetApp(); |
| 180 | + const val = await app.grabAttributeFrom('~ComputeSumButton', 'label'); |
| 181 | + assert.equal(val, 'Compute Sum'); |
| 182 | + }); |
| 183 | + |
| 184 | + it('should be able to grab elements', async () => { |
| 185 | + await app.resetApp(); |
| 186 | + const id = await app.grabNumberOfVisibleElements('~ComputeSumButton'); |
| 187 | + assert.strictEqual(1, id); |
| 188 | + }); |
| 189 | + }); |
| 190 | + |
| 191 | + describe('#saveScreenshot', () => { |
| 192 | + beforeEach(() => { |
| 193 | + global.output_dir = path.join(global.codecept_dir, 'output'); |
| 194 | + }); |
| 195 | + |
| 196 | + it('should create a screenshot file in output dir', async () => { |
| 197 | + const sec = (new Date()).getUTCMilliseconds(); |
| 198 | + await app.saveScreenshot(`screenshot_${sec}.png`); |
| 199 | + assert.ok(fileExists(path.join(global.output_dir, `screenshot_${sec}.png`)), null, 'file does not exists'); |
| 200 | + }); |
| 201 | + }); |
| 202 | +}); |
0 commit comments