Skip to content

Commit

Permalink
Merge pull request #925 from zebrunner/develop
Browse files Browse the repository at this point in the history
2.6.4 hotfixes
  • Loading branch information
vdelendik authored Mar 12, 2024
2 parents efbdb23 + 15480e0 commit 423d179
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 79 deletions.
10 changes: 1 addition & 9 deletions lib/units/api/controllers/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,11 @@ function getDeviceType (req, res) {
var serial = req.swagger.params.serial.value
dbapi.getDeviceType(serial)
.then(response => {
if (!response) {
return res.status(404).json({
success: false,
description: 'Device not found'
})
}
return res.status(200).json(response)
})
.catch(function(err) {
log.info('Failed to get device type: ', err.stack)
res.status(500).json({
success: false
})
return res.status(200).json({deviceType: null})
})
}

Expand Down
142 changes: 75 additions & 67 deletions lib/units/ios-device/plugins/wda/WdaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = syrup.serial()
.define((options, notifier, push) => {
const log = logger.createLogger('wdaClient')
log.info("WdaClient.js initializing...")

const socket = new net.Socket()
const WdaClient = {
baseUrl: iosutil.getUri(options.wdaHost, options.wdaPort),
Expand All @@ -34,37 +34,43 @@ module.exports = syrup.serial()
isRotating: false,
deviceType: null,

setDeviceTypeInDB: function() {
this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/wda/device/info`,
json: true
}).then((deviceInfo) => {
log.info('Storing device type value: ' + deviceInfo.value.model)
this.deviceType = deviceInfo.value.model

return push.send([
wireutil.global,
wireutil.envelope(new wire.DeviceTypeMessage(
options.serial,
deviceInfo.value.model
))
])
})
},
getDeviceType: function() {
const setDeviceTypeInDB = () => {
this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/wda/device/info`,
json: true
}).then((deviceInfo) => {
log.info('Setting device type value: ' + deviceInfo.value.model)
this.deviceType = deviceInfo.value.model

return push.send([
wireutil.global,
wireutil.envelope(new wire.DeviceTypeMessage(
options.serial,
deviceInfo.value.model
))
])
})
if (this.deviceType != null) {
return this.deviceType
}

return this.handleRequest({
method: 'GET',
uri: `${options.storageUrl}api/v1/devices/${options.serial}/type`,
}).then((response) => {
let deviceType = JSON.parse(response).deviceType

if (!deviceType) {
return setDeviceTypeInDB()
return this.setDeviceTypeInDB()
}

log.info('Reusing device type value: ', deviceType)
this.deviceType = deviceType
})},
})
},
startSession: function() {
log.info('verifying wda session status...')

Expand Down Expand Up @@ -93,15 +99,12 @@ module.exports = syrup.serial()
log.info(`reusing existing wda session: ${this.sessionId}`)

this.setStatus(3)
this.getDeviceType().then((response) => {
if (this.deviceType !== 'Apple TV') {
if (this.deviceType !== 'Apple TV') {
this.getOrientation()
}

this.setVersion(sessionResponse)

return this.size()
})
}

this.setVersion(sessionResponse)
return this.size()
}

log.info('starting wda session...')
Expand All @@ -124,17 +127,12 @@ module.exports = syrup.serial()
// #284 send info about battery to STF db
log.info(`sessionId: ${this.sessionId}`)

this.getDeviceType().then((response) => {
// Prevent Apple TV disconnection
if (this.deviceType !== 'Apple TV') {
this.getOrientation()
this.batteryIosEvent()
}

this.setStatus(3)

return this.size()
})
if (this.deviceType !== 'Apple TV') {
this.getOrientation()
this.batteryIosEvent()
}
this.setStatus(3)
return this.size()
})
.catch((err) => {
log.error('"startSession" No valid response from web driver!', err)
Expand All @@ -157,7 +155,6 @@ module.exports = syrup.serial()
method: 'DELETE',
uri: `${this.baseUrl}/session/${currentSessionId}`
})

},
setStatus: function(status) {
push.send([
Expand Down Expand Up @@ -212,9 +209,9 @@ module.exports = syrup.serial()

if (this.deviceType !== 'Apple TV') {
return this.handleRequest(requestParams)
}
}

// Apple TV keys
// Apple TV keys

switch (true) {
case value === '\v':
Expand Down Expand Up @@ -315,7 +312,7 @@ module.exports = syrup.serial()
id: 'finger1',
parameters: {pointerType: 'touch'},
actions: [
{type: 'pointerMove', duration: 0, x: scale.fromX, y: scale.fromY},
{type: 'pointerMove', duration: 0, x: scale.fromX, y: scale.fromY},
{type: 'pointerMove', duration: scale.duration * 1000, x: scale.toX, y: (scale.fromY < scale.toY) ? scale.toY - (scale.toY / 4) : (scale.fromY - scale.toY >= 50 ? scale.toY + (scale.toY / 4) : scale.toY)},
{type: 'pointerUp'},
],
Expand All @@ -328,7 +325,7 @@ module.exports = syrup.serial()
}

let swipeOperation = () => {
if (!this.isSwiping) {
if (!this.isSwiping) {
this.isSwiping = true
this.handleRequest({
method: 'POST',
Expand All @@ -341,7 +338,7 @@ module.exports = syrup.serial()
})
}
}

return swipeOperation()
},
touchUp: function() {
Expand Down Expand Up @@ -376,7 +373,7 @@ module.exports = syrup.serial()
body,
json: true,
})
// else if (deviceType === 'Watch_OS') {...}
// else if (deviceType === 'Watch_OS') {...}
} else {
// Avoid crash, wait until width/height values are available
if (x >= 0 && y >= 0) {
Expand Down Expand Up @@ -424,7 +421,7 @@ module.exports = syrup.serial()
body: {name: "select"},
json: true,
})
break;
break;
}
}
}
Expand Down Expand Up @@ -485,13 +482,11 @@ module.exports = syrup.serial()
})
}
},
size: function() {
log.info('getting device window size...')

const setSizeInDB = () => this.handleRequest({
setSizeInDB: function() {
return this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/session/${this.sessionId}/window/size`,
}).then((firstSessionSize) => {
}).then((firstSessionSize) => {
this.deviceSize = JSON.parse(firstSessionSize).value
let {height, width} = this.deviceSize

Expand Down Expand Up @@ -522,6 +517,12 @@ module.exports = syrup.serial()
return this.deviceSize
})
})
},
size: function() {
if (this.deviceSize != null) {
return this.deviceSize
}
log.info('getting device window size...')

// #556: Get device size from RethinkDB
return this.handleRequest({
Expand All @@ -530,16 +531,15 @@ module.exports = syrup.serial()
})
.then((windowSizeResponse) => {
let { height: dbHeight, width: dbWidth, scale: dbScale } = JSON.parse(windowSizeResponse);

// First device session:
if (!dbHeight || !dbWidth || !dbScale) {
setSizeInDB()
return this.setSizeInDB()
} else {
// Reuse DB values:
log.info('Reusing device size/scale')
// Set device size based on orientation, default is PORTRAIT
if (this.orientation === 'PORTRAIT' || !this.orientation) {
this.deviceSize = { height: dbHeight /= dbScale, width: dbWidth /= dbScale }
this.deviceSize = { height: dbHeight /= dbScale, width: dbWidth /= dbScale }
} else if (this.orientation === 'LANDSCAPE') {
this.deviceSize = { height: dbWidth /= dbScale, width: dbHeight /= dbScale }
} else if (this.deviceType === 'Apple TV') {
Expand Down Expand Up @@ -597,7 +597,6 @@ module.exports = syrup.serial()
})
},
getOrientation: function() {

return this.handleRequest({
method: 'GET',
uri: `${this.baseUrl}/session/${this.sessionId}/orientation`,
Expand Down Expand Up @@ -684,7 +683,7 @@ module.exports = syrup.serial()
json: true
})
},
switchCharset: function() {
switchCharset: function() {
this.upperCase = !this.upperCase

log.info(this.upperCase)
Expand Down Expand Up @@ -737,14 +736,18 @@ module.exports = syrup.serial()
return resolve(response)
})
.catch(err => {
let errMes = err.error.value.message ? err.error.value.message : ''
let errMes = ''

if (err.error.value.message) {
errMes = err.error.value.message
}

// #762 & #864: Skip lock/unlock error messages
// #762 & #864: Skip lock/unlock error messages
if (errMes.includes('Timed out while waiting until the screen gets locked') || errMes.includes('unlocked')) {
return
}

// #765: Skip rotation error message
// #765: Skip rotation error message
if (errMes.includes('Unable To Rotate Device')) {
return log.info('The current application does not support rotation')
}
Expand All @@ -753,7 +756,7 @@ module.exports = syrup.serial()
if (errMes.includes('Session does not exist')) {
return this.startSession()
}

// #409: capture wda/appium crash asap and exit with status 1 from stf
//notifier.setDeviceTemporaryUnavialable(err)
notifier.setDeviceAbsent(err)
Expand All @@ -767,9 +770,11 @@ module.exports = syrup.serial()
* WDA MJPEG connection is stable enough to be track status wda server itself.
* As only connection is closed or error detected we have to restart STF
*/
function connectToWdaMjpeg() {
function connectToWdaMjpeg(options) {
console.log('connecting to WdaMjpeg')
socket.connect(options.connectPort, options.wdaHost)
socket.connect(options.connectPort, options.wdaHost, () => {
console.log(`Connected to WdaMjpeg ${options.wdaHost}:${options.connectPort}`)
})

// #410: Use status 6 (preparing) on WDA startup
push.send([
Expand All @@ -779,10 +784,14 @@ module.exports = syrup.serial()
6
))
])
}

function wdaMjpegConnectEventHandler() {
console.log(`Connected to WdaMjpeg ${options.wdaHost}:${options.connectPort}`)
//TODO: handle negative case when device type not detected. Seems lifecycle.fatal(err) is ok.
WdaClient.getDeviceType()

//TODO: start session, init size/scale and stop session asap. Improve size getting info from db only
//WdaClient.startSession()
//WdaClient.setSizeInDB()
//WdaClient.stopSession()
}

async function wdaMjpegCloseEventHandler(hadError) {
Expand All @@ -799,7 +808,6 @@ module.exports = syrup.serial()
])
}

socket.on('connect', wdaMjpegConnectEventHandler)
socket.on('close', wdaMjpegCloseEventHandler)
connectToWdaMjpeg(options)

Expand Down
3 changes: 0 additions & 3 deletions res/app/components/stf/screen/screen-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ module.exports = function DeviceScreenDirective(
},
link: function($scope, $element) {
// eslint-disable-next-line prefer-destructuring
if ($scope.device.ios && $scope.device.present && (!$scope.device.display.width || !$scope.device.display.height)) {
return Promise.delay(1000).then(() => window.location.reload())
}
const element = $element[0]
const URL = window.URL || window.webkitURL
const BLANK_IMG = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
Expand Down

0 comments on commit 423d179

Please sign in to comment.