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