Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
Vue-WebDriver
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高源
Vue-WebDriver
Commits
2f5b0346
Commit
2f5b0346
authored
Nov 18, 2023
by
高源
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
isExist方法的验证逻辑完善
parent
e4986790
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
58 deletions
+67
-58
collectionTable.vue
src/components/collectionTable.vue
+23
-15
sdk-table.js
src/sdk-table.js
+44
-43
No files found.
src/components/collectionTable.vue
View file @
2f5b0346
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
<
script
>
<
script
>
import
VXETable
,
{
t
}
from
'vxe-table'
import
VXETable
,
{
t
}
from
'vxe-table'
// import { getTableData } from '../sdk'
// import { getTableData } from '../sdk'
import
{
cell
,
checkTableFromXpaths
}
from
'../sdk-table'
import
{
cell
,
checkTableFromXpaths
,
table
}
from
'../sdk-table'
export
default
{
export
default
{
name
:
'collectionTable'
,
name
:
'collectionTable'
,
components
:
{},
components
:
{},
...
@@ -80,21 +80,29 @@ export default {
...
@@ -80,21 +80,29 @@ export default {
methods
:
{
methods
:
{
getTable
()
{
getTable
()
{
let
_this
=
this
let
_this
=
this
console
.
log
(
_this
.
sdkXPath
)
let
_table
=
new
table
()
_this
.
checkTableFrom
=
checkTableFromXpaths
(
_this
.
sdkXPath
)
for
(
let
i
=
0
;
i
<
_this
.
Xpaths
.
length
;
i
++
)
{
console
.
log
(
_this
.
checkTableFrom
)
_table
.
newCell
(
_this
.
Xpaths
[
i
])
_this
.
tableData
=
_this
.
checkTableFrom
.
tableData
console
.
log
(
_this
.
tableData
)
this
.
tableColumn
=
[]
for
(
let
i
=
0
;
i
<
_this
.
tableData
.
length
;
i
++
)
{
let
objs
=
{}
objs
.
field
=
(
'content'
+
i
)
+
'.content'
objs
.
title
=
'请填写标题'
objs
.
width
=
145
_this
.
tableColumn
.
push
(
objs
)
}
}
_this
.
isSelectTable
=
false
_table
.
verify
()
console
.
log
(
_table
)
// console.log(_this.table)
//----------------------
// console.log(_this.sdkXPath)
// _this.checkTableFrom = checkTableFromXpaths(_this.sdkXPath)
// console.log(_this.checkTableFrom)
// _this.tableData = _this.checkTableFrom.tableData
// console.log(_this.tableData)
// this.tableColumn = []
// for (let i = 0; i
<
_this
.
tableData
.
length
;
i
++
)
{
// let objs = {}
// objs.field = ('content' + i) + '.content'
// objs.title = '请填写标题'
// objs.width = 145
// _this.tableColumn.push(objs)
// }
// _this.isSelectTable = false
return
return
//表格展示配置
//表格展示配置
...
...
src/sdk-table.js
View file @
2f5b0346
/**
/**
* 定义表格对象
* 定义表格对象
*/
*/
function
table
()
{
function
table
()
{
/**表格名称,当该表格获取完数据后,应该存储的对象名 */
/**表格名称,当该表格获取完数据后,应该存储的对象名 */
this
.
name
=
""
;
this
.
name
=
""
;
/**表格所在的XPath,由验证表格功能具体生成,如果为null,说明验证不成功 */
/**表格所在的XPath,由验证表格功能具体生成,如果为null,说明验证不成功 */
...
@@ -16,8 +16,8 @@ function table() {
...
@@ -16,8 +16,8 @@ function table() {
*/
*/
this
.
newCell
=
function
(
xpath
)
{
this
.
newCell
=
function
(
xpath
)
{
_isVerified
=
false
;
//加入了
_isVerified
=
false
;
//加入了
let
cell
=
new
cell
(
xpath
);
let
cell
d
=
new
cell
(
xpath
);
this
.
cells
.
push
(
cell
);
this
.
cells
.
push
(
cell
d
);
}
}
/**
/**
* 根据传入的cell进行验证,如果验证成功,xpath自动变化
* 根据传入的cell进行验证,如果验证成功,xpath自动变化
...
@@ -27,7 +27,7 @@ function table() {
...
@@ -27,7 +27,7 @@ function table() {
_isVerified
=
false
;
_isVerified
=
false
;
this
.
xpath
=
null
;
//防止反复验证,需要清空XPath
this
.
xpath
=
null
;
//防止反复验证,需要清空XPath
if
(
this
.
cells
.
length
<
1
)
return
_isVerified
;
if
(
this
.
cells
.
length
<
1
)
return
_isVerified
;
let
tableXpath
=
[];
let
tableXpath
=
[];
{
//获取所有单元格共同的父节点路径
{
//获取所有单元格共同的父节点路径
...
@@ -39,13 +39,14 @@ function table() {
...
@@ -39,13 +39,14 @@ function table() {
}
else
{
break
;
}
//如果发现不同的,直接就可以退出了
}
else
{
break
;
}
//如果发现不同的,直接就可以退出了
}
}
}
}
console
.
log
(
tableXpath
)
if
(
tableXpath
.
length
<
1
)
return
_isVerified
;
//如果没有共同父节点,返回false
if
(
tableXpath
.
length
<
1
)
return
_isVerified
;
//如果没有共同父节点,返回false
while
(
tableXpath
.
length
>
0
)
{
while
(
tableXpath
.
length
>
0
)
{
this
.
cells
.
forEach
(
cell
=>
cell
.
updateRelativePath
(
tableXpath
));
//先对所有的Cell更新下相对路径
this
.
cells
.
forEach
(
cell
=>
cell
.
updateRelativePath
(
tableXpath
));
//先对所有的Cell更新下相对路径
if
(
this
.
cells
.
every
(
cell
=>
cell
.
isExist
()))
break
;
//如果每个cell都存在,成功
if
(
this
.
cells
.
every
(
cell
=>
cell
.
isExist
(
cell
)))
break
;
//如果每个cell都存在,成功
tableXpath
.
pop
();
//向上一级找
tableXpath
.
pop
();
//向上一级找
if
(
tableXpath
.
length
==
0
)
return
null
}
}
if
(
tableXpath
.
length
<
1
)
return
_isVerified
;
//如果没有共同父节点,返回false
if
(
tableXpath
.
length
<
1
)
return
_isVerified
;
//如果没有共同父节点,返回false
this
.
cells
.
forEach
(
cell
=>
cell
.
confirm
());
//对所有单元格进行确认
this
.
cells
.
forEach
(
cell
=>
cell
.
confirm
());
//对所有单元格进行确认
...
@@ -67,7 +68,7 @@ function table() {
...
@@ -67,7 +68,7 @@ function table() {
* @param {string} type 元素取值类型,文本,链接,元素路径(点击动作用)
* @param {string} type 元素取值类型,文本,链接,元素路径(点击动作用)
* @param {string} title 标题信息
* @param {string} title 标题信息
*/
*/
function
cell
(
xpath
,
name
=
""
,
type
=
""
,
title
=
""
)
{
function
cell
(
xpath
,
name
=
""
,
type
=
""
,
title
=
""
)
{
/**当前单元格的绝对路径,存入Action时有用 */
/**当前单元格的绝对路径,存入Action时有用 */
this
.
xpath
=
xpath
;
this
.
xpath
=
xpath
;
/**当前单元格存储数据时的属性名 */
/**当前单元格存储数据时的属性名 */
...
@@ -87,34 +88,57 @@ function cell (xpath, name="", type="", title="") {
...
@@ -87,34 +88,57 @@ function cell (xpath, name="", type="", title="") {
/**当前XPath的数组结构 */
/**当前XPath的数组结构 */
let
_xpathArray
=
this
.
xpath
.
split
(
'/'
);
let
_xpathArray
=
this
.
xpath
.
split
(
'/'
);
/**当前表路径的数组结构 */
/**当前表路径的数组结构 */
let
_tableXpathArray
=
null
;
this
.
_tableXpathArray
=
null
;
/**当前单元格的相对路径的数组结构 */
/**当前单元格的相对路径的数组结构 */
let
_relativeXpathArray
=
null
;
this
.
_relativeXpathArray
=
null
;
/**
/**
* 根据父路径更新当前的相对路径
* 根据父路径更新当前的相对路径
* @param {string[]} parentXpath 父路径
* @param {string[]} parentXpath 父路径
*/
*/
this
.
updateRelativePath
=
function
(
parentXpath
)
{
this
.
updateRelativePath
=
function
(
parentXpath
)
{
_tableXpathArray
=
parentXpath
;
//其实这边严谨的来说要验证一下XPath是否真的有相同的根
this
.
_tableXpathArray
=
parentXpath
;
//其实这边严谨的来说要验证一下XPath是否真的有相同的根
_relativeXpathArray
=
_xpathArray
.
slice
(
_tableXpathArray
.
length
);
this
.
_relativeXpathArray
=
_xpathArray
.
slice
(
this
.
_tableXpathArray
.
length
);
// this.relativeXpath = _relativeXpathArray
// this.tableXpath = _tableXpathArray
// console.log(this._relativeXpathArray)
}
}
/**
/**
* 单元格是否存在
* 单元格是否存在
* @returns {boolean}
* @returns {boolean}
*/
*/
this
.
isExist
=
function
()
{
this
.
isExist
=
function
(
cell
)
{
console
.
log
(
cell
)
let
existCount
=
0
;
let
existCount
=
0
;
let
_tableXpathArray
=
[...
cell
.
_tableXpathArray
]
//深拷贝,值修改不影响原数组
let
_relativeXpathArray
=
[...
cell
.
_relativeXpathArray
]
//深拷贝,值修改不影响原数组
// 移除最后一个元素的下标
if
(
_tableXpathArray
.
length
>
0
)
{
let
lastElement
=
_tableXpathArray
[
_tableXpathArray
.
length
-
1
];
let
lastElementWithoutIndex
=
lastElement
.
split
(
'['
)[
0
];
_tableXpathArray
[
_tableXpathArray
.
length
-
1
]
=
lastElementWithoutIndex
;
}
_tableXpathArray
=
_tableXpathArray
.
join
(
'/'
)
_relativeXpathArray
=
_relativeXpathArray
.
join
(
'/'
)
//table[0]+relativeXpath,可以不存在,因为可能是表头,1,2
//table[0]+relativeXpath,可以不存在,因为可能是表头,1,2
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
let
isGetElement
=
elementExists
(
_tableXpathArray
+
'['
+
(
i
+
1
)
+
']'
+
'/'
+
_relativeXpathArray
)
console
.
log
(
isGetElement
)
if
(
isGetElement
)
{
existCount
=
i
}
else
{
return
false
}
}
}
return
existCount
>
1
;
return
existCount
>
1
;
}
}
/**当所有单元格验证成功后,由表发起确认动作 */
/**当所有单元格验证成功后,由表发起确认动作 */
this
.
confirm
=
function
()
{
this
.
confirm
=
function
()
{
this
.
tableXpath
=
_tableXpathArray
.
join
(
"/"
);
this
.
tableXpath
=
this
.
_tableXpathArray
.
join
(
"/"
);
this
.
relativePath
=
_relativeXpathArray
.
join
(
"/"
);
this
.
relativePath
=
this
.
_relativeXpathArray
.
join
(
"/"
);
}
}
/**
/**
* 根据索引获取值
* 根据索引获取值
...
@@ -272,32 +296,9 @@ function incrementLastIndex (xpath) {
...
@@ -272,32 +296,9 @@ function incrementLastIndex (xpath) {
* 检查XPath是否指向一个存在的元素,如果存在就返回,当父节点的最后一个下标换成第二行的下标时,组合同样的相对路径,向上查找相同的父节点并更新cell对应的父节点,保证当前选中是表结构
* 检查XPath是否指向一个存在的元素,如果存在就返回,当父节点的最后一个下标换成第二行的下标时,组合同样的相对路径,向上查找相同的父节点并更新cell对应的父节点,保证当前选中是表结构
*/
*/
function
elementExists
(
xpath
,
cells
)
{
function
elementExists
(
xpath
)
{
let
documentResult
=
document
.
evaluate
(
xpath
,
document
,
null
,
XPathResult
.
FIRST_ORDERED_NODE_TYPE
,
null
);
let
result
=
document
.
evaluate
(
xpath
,
document
,
null
,
XPathResult
.
FIRST_ORDERED_NODE_TYPE
,
null
);
if
(
!!
documentResult
.
singleNodeValue
)
{
return
!!
result
.
singleNodeValue
;
// 如果找到元素,返回 true
return
true
;
}
else
{
// 没找到元素,开始逐级向上检查
let
parts
=
xpath
.
split
(
'/'
);
// 移除最后一个节点,逐级向上检查
while
(
parts
.
length
>
1
)
{
parts
.
pop
();
// reducedXPath 这个路径以绝对xpath向上查找
let
reducedXPath
=
parts
.
join
(
'/'
);
documentResult
=
document
.
evaluate
(
reducedXPath
,
document
,
null
,
XPathResult
.
FIRST_ORDERED_NODE_TYPE
,
null
);
if
(
!!
documentResult
.
singleNodeValue
)
{
// 如果在上一级找到了元素,返回 true
let
xpathArray
=
reducedXPath
.
split
(
'/'
);
// 移除数组中的空字符串元素,这通常出现在字符串的开头
cells
.
forEach
(
o
=>
o
.
updateRelativePath
(
xpathArray
));
//更新每个cell的相对路径和父节点
return
true
;
}
}
// 如果遍历完所有节点还是没找到,返回 false
return
false
;
}
}
}
/**
/**
* // 公共部分与拆解部分组合查询 找出当前节点下所有符合条件的表数据
* // 公共部分与拆解部分组合查询 找出当前节点下所有符合条件的表数据
...
@@ -438,4 +439,4 @@ function getTableData (resultElement) {
...
@@ -438,4 +439,4 @@ function getTableData (resultElement) {
return
null
return
null
}
}
}
}
export
{
cell
,
checkTableFromXpaths
}
export
{
cell
,
checkTableFromXpaths
,
table
}
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment