Skip to content

Commit

Permalink
自动化测试:初步完成账号交叉测试
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Jan 1, 2020
1 parent 1751d72 commit 7e21128
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 36 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 0)">数据库类型Database: {{ database || '点击设置' }}</a>
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 1)">数据库模式Schema: {{ schema || '点击设置' }}</a>
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 2)">生成代码(封装,解析): {{ language || '点击设置' }}</a>
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(! isDelegateEnabled, 9)">{{ isDelegateEnabled ? '关闭' : '开启' }}托管服务器代理: {{ isDelegateEnabled ? '代理中' : '直接访问' }}</a>
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(! isDelegateEnabled, 9)">服务器代理: {{ isDelegateEnabled ? '已开启,点击关闭' : '已关闭,点击开启' }}</a>
<a v-show="User.id == null || User.id <= 0" style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(true, 7)">使用的请求类型: {{ types == null || types.length <= 0 ? '点击设置' : types.join() }}</a>
<a style="border-bottom: #DDD 1px solid;width: 100%" href="javascript:void(0)" @click="showConfig(StringUtil.isEmpty(host, true), 3)">{{ StringUtil.isEmpty(host, true) ? '隐藏(固定)URL Host: 可用空格隔开' : '显示(编辑)URL Host: \n' + host }}</a>
<a style="border-bottom: #DDD 1px solid;width: 100%;display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden;" href="javascript:void(0)" @click="showConfig(! isRandomShow, 5)">{{ isRandomShow ? '隐藏(固定)随机测试 Random Test' : '显示(编辑)随机测试 Random Test' }}</a>
Expand Down Expand Up @@ -133,6 +133,7 @@

<a style="display: flex;flex-grow: 1;font-size: medium;color: black" class="hint--top save-tool" data-hint="点击切换" href="javascript:void(0)" @click="showTestCase(true, ! isLocalShow)">测试用例:{{ (isLocalShow ? '本地历史(' : '远程共享(') + (testCases == null ? 0 : testCases.length) + ')' }}</a>

<a v-show="! isLocalShow" class="hint--top save-tool" data-hint="点击切换" href="javascript:void(0)" @click="enableCross(! isCrossEnabled)">{{ crossProcess }}</a>
<a v-show="! isLocalShow" class="hint--top save-tool" data-hint="点击切换" href="javascript:void(0)" @click="enableML(! isMLEnabled)">{{ testProcess }}</a>
<a v-show="! isLocalShow" class="hint--top @cli-tool" data-hint="回归测试" href="javascript:void(0)" @click="test()">
<img class="icon" src="img/refresh.png"/>
Expand All @@ -147,7 +148,7 @@
<ul v-show="isTestCaseShow" class="historys" style="width: 100%;height: 100%;overflow: hidden;overflow-y: scroll;padding-bottom: 50px">
<li v-for="(item, index) in testCases" >
<div style="display: inline-table">
<button v-show="types != null && types.length > 1" style="width: 48px;margin-right: 6px;position: relative" id="vDocType" @click="restoreRemoteAndTest(item)">{{ getTypeName(item.Document.type) }}</button>
<button v-show="types != null && types.length > 1" style="width: 48px;margin-right: 6px;padding: 0px;position: relative" id="vDocType" @click="restoreRemoteAndTest(item)">{{ getTypeName(item.Document.type) }}</button>
<a class="hint--rounded hint--no-animate" ref="testCaseTexts" @mouseover="setRequestHint(index, item)" href="javascript:void(0)" @click="restoreRemote(item)" > {{(item.Document.version > 0 ? 'V' + item.Document.version : 'V*') + ' ' + item.Document.name + ' ' + item.Document.url}}</a>
<div :style="{ background: item.compareColor }" v-show="item.compareType != null" style="position: absolute;top: 8px;right: 36px;display: inline-block;">
<button class="hint--left" ref="testResultButtons" @mouseover="setTestHint(index, item)" v-show="item.compareType != null" @click="handleTest(false, index, item)" style="position: relative;">{{ item.compareMessage + (item.showType == 'before' ? '-前' : '-后') }}</button>
Expand Down
123 changes: 89 additions & 34 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@
],
currentAccountIndex: 0,
tests: [],
crossProcess: '交叉账号:已关闭',
testProcess: '机器学习:已关闭',
randomTestTitle: null,
testRandomProcess: '',
Expand All @@ -529,6 +530,7 @@
loginType: 'login',
isExportRemote: false,
isRegister: false,
isCrossEnabled: false,
isMLEnabled: false,
isDelegateEnabled: false,
isLocalShow: false,
Expand Down Expand Up @@ -1505,7 +1507,12 @@



onClickAccount: function (index, item) {
onClickAccount: function (index, item, callback) {
if (index < 0 || item == null) {
callback(false)
return
}

if (this.currentAccountIndex == index) {
this.setRememberLogin(item.remember)
vAccount.value = item.phone
Expand All @@ -1519,6 +1526,10 @@
item.isLoggedIn = false
App.saveCache(App.getBaseUrl(), 'currentAccountIndex', App.currentAccountIndex)
App.saveCache(App.getBaseUrl(), 'accounts', App.accounts)

if (callback != null) {
callback(false)
}
});
}
else {
Expand All @@ -1536,6 +1547,10 @@

App.saveCache(App.getBaseUrl(), 'currentAccountIndex', App.currentAccountIndex)
App.saveCache(App.getBaseUrl(), 'accounts', App.accounts)

if (callback != null) {
callback(true)
}
}
});
}
Expand All @@ -1555,7 +1570,7 @@

//目前还没做到同一标签页下测试账号切换后,session也跟着切换,所以干脆每次切换tab就重新登录
item.isLoggedIn = false
this.onClickAccount(index, item)
this.onClickAccount(index, item, callback)
},

removeAccountTab: function () {
Expand Down Expand Up @@ -2876,6 +2891,12 @@
return doc
},

enableCross: function (enable) {
this.isCrossEnabled = enable
this.crossProcess = enable ? '交叉账号:已开启' : '交叉账号:已关闭'
this.saveCache(App.server, 'isCrossEnabled', enable)
},

enableML: function (enable) {
this.isMLEnabled = enable
this.testProcess = enable ? '机器学习:已开启' : '机器学习:已关闭'
Expand Down Expand Up @@ -3159,7 +3180,22 @@
3-对象缺少字段/整数变小数,黄色;
4-code/值类型 改变,红色;
*/
test: function (isRandom) {
test: function (isRandom, accountIndex) {
var accounts = this.accounts || []
alert('test accountIndex = ' + accountIndex)
var isCrossEnabled = this.isCrossEnabled
if (accountIndex == null) {
accountIndex = -1 //isCrossEnabled ? -1 : 0
}
if (isCrossEnabled) {
var isCrossDone = accountIndex >= accounts.length
this.crossProcess = isCrossDone ? (isCrossEnabled ? '交叉账号:已开启' : '交叉账号:已关闭') : ('交叉账号: ' + accountIndex + '/' + accounts.length)
if (isCrossDone) {
alert('test isCrossDone')
return
}
}

var baseUrl = StringUtil.trim(App.getBaseUrl())
if (baseUrl == '') {
alert('请先输入有效的URL!')
Expand All @@ -3183,46 +3219,59 @@
alert('请先获取测试用例文档\n点击[查看共享]图标按钮')
return
}
App.testProcess = '正在测试: ' + 0 + '/' + allCount

for (var i = 0; i < allCount; i ++) {
const item = list[i]
const document = item == null ? null : item.Document
if (document == null || document.name == null) {
doneCount ++
continue
}
if (document.url == '/login' || document.url == '/logout') { //login会导致登录用户改变为默认的但UI上还显示原来的,单独测试OWNER权限时能通过很困惑
App.log('test document.url == "/login" || document.url == "/logout" >> continue')
doneCount ++
continue
}
App.log('test document = ' + JSON.stringify(document, null, ' '))

const index = i
if (accountIndex < 0 && isCrossEnabled) { //退出登录已登录的账号
accounts[this.currentAccountIndex].isLoggedIn = true
}

var header = null
try {
header = App.getHeader(document.header)
} catch (e) {
App.log('test for ' + i + ' >> try { header = App.getHeader(document.header) } catch (e) { \n' + e.message)
}
var index = accountIndex < 0 && isCrossEnabled ? this.currentAccountIndex : accountIndex
this.onClickAccount(index, accounts[index], function(isLoggedIn) {
App.showTestCase(true, false)

App.testProcess = '正在测试: ' + 0 + '/' + allCount

for (var i = 0; i < allCount; i++) {
const item = list[i]
const document = item == null ? null : item.Document
if (document == null || document.name == null) {
doneCount++
continue
}
if (document.url == '/login' || document.url == '/logout') { //login会导致登录用户改变为默认的但UI上还显示原来的,单独测试OWNER权限时能通过很困惑
App.log('test document.url == "/login" || document.url == "/logout" >> continue')
doneCount++
continue
}
App.log('test document = ' + JSON.stringify(document, null, ' '))

App.request(false, document.type, baseUrl + document.url, App.getRequest(document.request), header, function (url, res, err) {
const index = i

var header = null
try {
App.onResponse(url, res, err)
App.log('test App.request >> res.data = ' + JSON.stringify(res.data, null, ' '))
header = App.getHeader(document.header)
} catch (e) {
App.log('test App.request >> } catch (e) {\n' + e.message)
App.log('test for ' + i + ' >> try { header = App.getHeader(document.header) } catch (e) { \n' + e.message)
}

App.compareResponse(allCount, index, item, res.data, isRandom)
})
}
App.request(false, document.type, baseUrl + document.url, App.getRequest(document.request), header, function (url, res, err) {

try {
App.onResponse(url, res, err)
App.log('test App.request >> res.data = ' + JSON.stringify(res.data, null, ' '))
} catch (e) {
App.log('test App.request >> } catch (e) {\n' + e.message)
}

App.compareResponse(allCount, index, item, res.data, isRandom, accountIndex)
})
}

})

},

compareResponse: function (allCount, index, item, response, isRandom) {
compareResponse: function (allCount, index, item, response, isRandom, accountIndex) {
var it = item || {} //请求异步
var d = (isRandom ? App.currentRemoteItem.Document : it.Document) || {} //请求异步
var r = isRandom ? it.Random : null//请求异步
Expand All @@ -3233,10 +3282,10 @@
var standardKey = App.isMLEnabled != true ? 'response' : 'standard'
var standard = StringUtil.isEmpty(tr[standardKey], true) ? null : JSON.parse(tr[standardKey]);
tr.compare = JSONResponse.compareResponse(standard, releaseResponse, '', App.isMLEnabled) || {}
App.onTestResponse(allCount, index, it, d, r, tr, response, tr.compare || {}, isRandom);
App.onTestResponse(allCount, index, it, d, r, tr, response, tr.compare || {}, isRandom, accountIndex);
},

onTestResponse: function(allCount, index, it, d, r, tr, response, cmp, isRandom) {
onTestResponse: function(allCount, index, it, d, r, tr, response, cmp, isRandom, accountIndex) {

doneCount ++
App.testProcess = doneCount >= allCount ? (App.isMLEnabled ? '机器学习:已开启' : '机器学习:已关闭') : '正在测试: ' + doneCount + '/' + allCount
Expand Down Expand Up @@ -3295,6 +3344,10 @@
console.log('tests = ' + JSON.stringify(tests, null, ' '))
// App.showTestCase(true)

if (doneCount >= allCount && App.isCrossEnabled) {
alert('onTestResponse accountIndex = ' + accountIndex)
App.test(false, accountIndex + 1)
}
},

/**移除调试字段
Expand Down Expand Up @@ -3600,7 +3653,9 @@

try { //可能URL_BASE是const类型,不允许改,这里是初始化,不能出错
this.User = this.getCache(this.server, 'User') || {}
this.isCrossEnabled = this.getCache(this.server, 'isCrossEnabled') || this.isCrossEnabled
this.isMLEnabled = this.getCache(this.server, 'isMLEnabled') || this.isMLEnabled
this.crossProcess = this.isCrossEnabled ? '交叉账号:已开启' : '交叉账号:已关闭'
this.testProcess = this.isMLEnabled ? '机器学习:已开启' : '机器学习:已关闭'
} catch (e) {
console.log('created try { ' +
Expand Down

0 comments on commit 7e21128

Please sign in to comment.