You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
61 lines
1.9 KiB
5 years ago
|
const EventEmitter = require('events')
|
||
|
const deepequal = require('deep-equal')
|
||
|
|
||
|
class TestFunction extends EventEmitter {
|
||
5 years ago
|
command (txHash, expectedValue) {
|
||
5 years ago
|
const browser = this.api
|
||
|
const logs = {}
|
||
5 years ago
|
const setLog = (index, value) => { logs[Object.keys(logs)[index]] = value }
|
||
5 years ago
|
|
||
5 years ago
|
browser.waitForElementVisible(`*[data-id="txLogger${txHash}"]`)
|
||
5 years ago
|
.click(`*[data-id="txLogger${txHash}"]`)
|
||
|
.waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`)
|
||
|
.click(`*[data-id="txLoggerTable${txHash}"]`)
|
||
|
|
||
|
// fetch and format transaction logs as key => pair object
|
||
|
.elements('css selector', `*[data-shared="key_${txHash}"]`, (res) => {
|
||
|
res.value.forEach(function (jsonWebElement) {
|
||
|
const jsonWebElementId = jsonWebElement.ELEMENT
|
||
|
|
||
|
browser.elementIdText(jsonWebElementId, (jsonElement) => {
|
||
|
const key = jsonElement.value.trim()
|
||
|
|
||
|
logs[key] = null
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
.elements('css selector', `*[data-shared="pair_${txHash}"]`, (res) => {
|
||
|
res.value.forEach(function (jsonWebElement, index) {
|
||
|
const jsonWebElementId = jsonWebElement.ELEMENT
|
||
|
|
||
|
browser.elementIdText(jsonWebElementId, (jsonElement) => {
|
||
|
let value = jsonElement.value
|
||
|
|
||
5 years ago
|
try {
|
||
5 years ago
|
value = JSON.parse(jsonElement.value)
|
||
|
setLog(index, value)
|
||
5 years ago
|
} catch (e) {
|
||
5 years ago
|
setLog(index, value)
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
|
||
|
browser.perform(() => {
|
||
5 years ago
|
Object.keys(expectedValue).forEach(key => {
|
||
|
const equal = deepequal(logs[key], expectedValue[key])
|
||
5 years ago
|
|
||
|
if (!equal) {
|
||
5 years ago
|
browser.assert.fail(`Expected ${expectedValue[key]} but got ${logs[key]}`)
|
||
5 years ago
|
} else {
|
||
5 years ago
|
browser.assert.ok(true, `Expected value matched returned value ${expectedValue[key]}`)
|
||
5 years ago
|
}
|
||
|
})
|
||
|
this.emit('complete')
|
||
|
})
|
||
|
return this
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
module.exports = TestFunction
|