parent
9806a205d4
commit
cf2632c3b7
@ -0,0 +1,73 @@ |
||||
const EventEmitter = require('events') |
||||
const deepequal = require('deep-equal') |
||||
|
||||
class TestFunction extends EventEmitter { |
||||
command (fnFullName, txHash, expectedReturn, input) { |
||||
const browser = this.api |
||||
const logs = {} |
||||
const setLog = (index, value) => logs[Object.keys(logs)[index]] = value; |
||||
|
||||
browser.waitForElementPresent(`*[data-id="${fnFullName}"]`) |
||||
.perform(function (client, done) { |
||||
client.execute(function () { |
||||
document.querySelector('*[data-id="runTabView"]').scrollTop = document.querySelector('*[data-id="runTabView"]').scrollHeight |
||||
}, [], function () { |
||||
if (input) { |
||||
client.setValue(`*[data-id="multiParamManagerBasicInputField${input.types}"]`, input.values, function () {}) |
||||
} |
||||
done() |
||||
}) |
||||
}) |
||||
.click(`*[data-id="${fnFullName}"]`) |
||||
.pause(500) |
||||
.waitForElementVisible(`*[data-id="txLogger${txHash}"]`) |
||||
.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 |
||||
|
||||
try{ |
||||
value = JSON.parse(jsonElement.value) |
||||
setLog(index, value) |
||||
}catch(e){ |
||||
setLog(index, value) |
||||
} |
||||
}) |
||||
}) |
||||
}) |
||||
|
||||
browser.perform(() => { |
||||
Object.keys(expectedReturn).forEach(key => { |
||||
const equal = deepequal(logs[key], expectedReturn[key]) |
||||
|
||||
if (!equal) { |
||||
browser.assert.fail(`Expected ${expectedReturn[key]} but got ${logs[key]}`) |
||||
}else{ |
||||
browser.assert.ok(true, `Expected value matched returned value ${expectedReturn[key]}`) |
||||
} |
||||
}) |
||||
this.emit('complete') |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = TestFunction |
Loading…
Reference in new issue