-
-
Notifications
You must be signed in to change notification settings - Fork 756
Expand file tree
/
Copy pathAppium_networkConnection_test.js
More file actions
108 lines (96 loc) · 4.39 KB
/
Copy pathAppium_networkConnection_test.js
File metadata and controls
108 lines (96 loc) · 4.39 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
import { expect } from 'chai'
import sinon from 'sinon'
import Appium from '../../../lib/helper/Appium.js'
function createApp(deviceInfo = { carrierName: 'T-Mobile' }) {
const app = new Appium({
platform: 'Android',
desiredCapabilities: {
platformName: 'Android',
},
})
app.browser = { execute: sinon.stub() }
app.browser.execute.withArgs('mobile: deviceInfo').resolves(deviceInfo)
return app
}
describe('Appium #setNetworkConnection, #grabNetworkConnection', () => {
it('should call mobile: setConnectivity with airplane mode only for value 1', async () => {
const app = createApp()
await app.setNetworkConnection(1)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: true, wifi: false, data: false })).to.be.true
})
it('should call mobile: setConnectivity with wifi only for value 2', async () => {
const app = createApp()
await app.setNetworkConnection(2)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: false, wifi: true, data: false })).to.be.true
})
it('should call mobile: setConnectivity with data only for value 4', async () => {
const app = createApp()
await app.setNetworkConnection(4)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: false, wifi: false, data: true })).to.be.true
})
it('should call mobile: setConnectivity with wifi and data for value 6', async () => {
const app = createApp()
await app.setNetworkConnection(6)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: false, wifi: true, data: true })).to.be.true
})
it('should call mobile: setConnectivity with everything off for value 0', async () => {
const app = createApp()
await app.setNetworkConnection(0)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: false, wifi: false, data: false })).to.be.true
})
it('should omit data on devices without telephony', async () => {
const app = createApp({ carrierName: '' })
await app.setNetworkConnection(1)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: true, wifi: false })).to.be.true
})
it('should probe telephony again while no carrier was seen yet', async () => {
const app = createApp({ carrierName: '' })
await app.setNetworkConnection(1)
app.browser.execute.withArgs('mobile: deviceInfo').resolves({ carrierName: 'T-Mobile' })
await app.setNetworkConnection(2)
expect(app.browser.execute.withArgs('mobile: deviceInfo').callCount).to.equal(2)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: false, wifi: true, data: false })).to.be.true
})
it('should probe telephony only once after a carrier was seen', async () => {
const app = createApp()
await app.setNetworkConnection(1)
await app.setNetworkConnection(6)
expect(app.browser.execute.withArgs('mobile: deviceInfo').callCount).to.equal(1)
expect(app.browser.execute.calledWith('mobile: setConnectivity', { airplaneMode: false, wifi: true, data: true })).to.be.true
})
it('should grab network connection using mobile: getConnectivity and map to legacy bitmask shape', async () => {
const app = createApp()
app.browser.execute.resolves({ airplaneMode: false, wifi: false, data: true })
const val = await app.grabNetworkConnection()
expect(app.browser.execute.calledWith('mobile: getConnectivity')).to.be.true
expect(val.value).to.equal(4)
expect(val.inAirplaneMode).to.equal(false)
expect(val.hasWifi).to.equal(false)
expect(val.hasData).to.equal(true)
})
it('should grab network connection with wifi and airplane mode combined', async () => {
const app = createApp()
app.browser.execute.resolves({ airplaneMode: true, wifi: true, data: false })
const val = await app.grabNetworkConnection()
expect(val.value).to.equal(3)
expect(val.inAirplaneMode).to.equal(true)
expect(val.hasWifi).to.equal(true)
expect(val.hasData).to.equal(false)
})
it('should throw when used outside android platform', async () => {
const app = new Appium({
platform: 'iOS',
desiredCapabilities: {
platformName: 'iOS',
},
})
app.browser = { execute: sinon.stub() }
let error
try {
await app.setNetworkConnection(1)
} catch (err) {
error = err
}
expect(error).to.be.instanceOf(Error)
})
})