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
fe1a46b6
Commit
fe1a46b6
authored
Nov 18, 2023
by
高源
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
5448e173
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
38 deletions
+88
-38
collectionTable.vue
src/components/collectionTable.vue
+45
-2
sdk-table.js
src/sdk-table.js
+43
-36
No files found.
src/components/collectionTable.vue
View file @
fe1a46b6
...
...
@@ -59,7 +59,50 @@ export default {
data
()
{
return
{
tableColumn
:
[],
tableData
:
[],
tableData
:
[
{
"0"
:
[
{
"content"
:
"/HTML/BODY/DIV[3]/DIV[1]/DIV[1]/DIV[1]/DIV[1]/SPAN[1]/A[1]"
,
"name"
:
""
,
"value"
:
"根据type获取到的值"
},
{
"content"
:
"/HTML/BODY/DIV[3]/DIV[1]/DIV[1]/DIV[1]/DIV[2]/SPAN[1]"
,
"name"
:
""
,
"value"
:
"根据type获取到的值"
}
]
},
{
"1"
:
[
{
"content"
:
"/HTML/BODY/DIV[3]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/SPAN[1]/A[1]"
,
"name"
:
""
,
"value"
:
"根据type获取到的值"
},
{
"content"
:
"/HTML/BODY/DIV[3]/DIV[2]/DIV[1]/DIV[1]/DIV[2]/SPAN[1]"
,
"name"
:
""
,
"value"
:
"根据type获取到的值"
}
]
},
{
"2"
:
[
{
"content"
:
"/HTML/BODY/DIV[3]/DIV[3]/DIV[1]/DIV[1]/DIV[1]/SPAN[1]/A[1]"
,
"name"
:
""
,
"value"
:
"根据type获取到的值"
},
{
"content"
:
"/HTML/BODY/DIV[3]/DIV[3]/DIV[1]/DIV[1]/DIV[2]/SPAN[1]"
,
"name"
:
""
,
"value"
:
"根据type获取到的值"
}
]
}
],
SelectTableData
:
[],
isSelectTable
:
true
,
firstXpath
:
[],
...
...
@@ -85,7 +128,7 @@ export default {
_table
.
newCell
(
_this
.
Xpaths
[
i
])
}
_table
.
verify
()
_table
.
getData
(
)
console
.
log
(
_table
.
getData
()
)
console
.
log
(
_table
)
// console.log(_this.table)
//----------------------
...
...
src/sdk-table.js
View file @
fe1a46b6
...
...
@@ -27,9 +27,7 @@ function table () {
_isVerified
=
false
;
this
.
xpath
=
null
;
//防止反复验证,需要清空XPath
if
(
this
.
cells
.
length
<
1
)
return
_isVerified
;
let
tableXpathArray
=
[];
{
//获取所有单元格共同的父节点路径
let
allCellXpaths
=
this
.
cells
.
map
(
cell
=>
cell
.
xpath
.
split
(
'/'
));
// 分割每个路径为组成部分
for
(
let
i
=
0
;
i
<
allCellXpaths
[
0
].
length
;
i
++
)
{
...
...
@@ -39,11 +37,17 @@ function table () {
}
else
{
break
;
}
//如果发现不同的,直接就可以退出了
}
//判断下tableXPathArray不能和某一个元素的路径完全相同,如果相同就应该去掉一级
// 当 cells 数组只包含一个单元格时,需要特别处理
if
(
this
.
cells
.
length
===
1
)
{
let
singleCellPath
=
this
.
cells
[
0
].
xpath
.
split
(
'/'
);
if
(
tableXpathArray
.
length
===
singleCellPath
.
length
)
{
// 如果共同父节点路径与单个单元格的路径完全相同,去掉最后一个元素
tableXpathArray
.
pop
();
}
}
}
if
(
tableXpathArray
.
length
<
1
)
return
_isVerified
;
//如果没有共同父节点,返回false
while
(
tableXpath
.
length
>
0
)
{
while
(
tableXpathArray
.
length
>
0
)
{
this
.
cells
.
forEach
(
cell
=>
cell
.
updateRelativePath
(
tableXpathArray
));
//先对所有的Cell更新下相对路径
if
(
this
.
cells
.
every
(
cell
=>
cell
.
isExist
()))
break
;
//如果每个cell都存在,成功
tableXpathArray
.
pop
();
//向上一级找
...
...
@@ -60,12 +64,11 @@ function table () {
this
.
getData
=
function
()
{
let
rtns
=
[];
//定义返回值
if
(
!
_isVerified
)
return
null
;
//如果还没通过验证不返回数据
console
.
log
(
this
.
cells
)
let
rowIndex
=
0
;
while
(
true
)
{
let
result
=
{}
this
.
cells
.
forEach
(
cell
=>
cell
.
getData
(
result
,
rowIndex
));
if
(
result
===
{}
)
break
;
//不断的根据rowIndex取值,直到取不到值就退出,需要注意如果第0行是表头,也不一定可以取到值
if
(
Object
.
keys
(
result
).
length
===
0
)
break
;
//不断的根据rowIndex取值,直到取不到值就退出,需要注意如果第0行是表头,也不一定可以取到值
rtns
.
push
(
result
);
//把值推入返回值中
rowIndex
++
;
}
...
...
@@ -90,19 +93,16 @@ function cell (xpath, name = "", type = "", title = "") {
this
.
types
=
[];
/** 单元格在表上的表头信息*/
this
.
title
=
title
;
/**当表结构验证成功后,正确的表绝对路径,不包含下标 */
this
.
tableXpath
=
null
;
/**当表结构验证成功后,正确的单元格相对路径 */
this
.
relativeXpath
=
null
;
/**当前XPath的数组结构 */
let
_xpathArray
=
this
.
xpath
.
split
(
'/'
);
/**当前表路径的数组结构 */
let
_tableXpathArray
=
null
;
/**当前单元格的相对路径的数组结构 */
let
_relativeXpathArray
=
null
;
/**
* 根据父路径更新当前的相对路径
* @param {string[]} parentXpath 父路径
...
...
@@ -110,27 +110,28 @@ function cell (xpath, name = "", type = "", title = "") {
this
.
updateRelativePath
=
function
(
parentXpath
)
{
_tableXpathArray
=
parentXpath
;
//其实这边严谨的来说要验证一下XPath是否真的有相同的根
_relativeXpathArray
=
_xpathArray
.
slice
(
_tableXpathArray
.
length
);
// this.relativeXpath = this._relativeXpathArray
// this.tableXpath = _tableXpathArray
// console.log(this._relativeXpathArray)
// 移除最后一个元素的下标
if
(
_tableXpathArray
.
length
>
0
)
{
let
lastElement
=
_tableXpathArray
[
_tableXpathArray
.
length
-
1
];
let
lastElementWithoutIndex
=
lastElement
.
split
(
'['
)[
0
];
_tableXpathArray
[
_tableXpathArray
.
length
-
1
]
=
lastElementWithoutIndex
;
}
}
/**
* 单元格是否存在
* @returns {boolean}
*/
this
.
isExist
=
function
()
{
let
existCount
=
0
;
let
_tableXpathArray
=
[...
_tableXpathArray
]
//深拷贝,值修改不影响原数组
let
_relativeXpathArray
=
[...
_relativeXpathArray
]
//深拷贝,值修改不影响原数组
_tableXpathArray
=
_tableXpathArray
.
join
(
'/'
)
_relativeXpathArray
=
_relativeXpathArray
.
join
(
'/'
)
//table[0]+relativeXpath,可以不存在,因为可能是表头,1,2
//let result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
//return !!result.singleNodeValue;
let
_tableXpathArrays
=
[...
_tableXpathArray
];
//深拷贝,值修改不影响原数组
let
_relativeXpathArrays
=
[...
_relativeXpathArray
];
//深拷贝,值修改不影响原数组
_tableXpathArrays
=
_tableXpathArray
.
join
(
'/'
)
_relativeXpathArrays
=
_relativeXpathArray
.
join
(
'/'
)
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
let
isGetElement
=
elementExists
(
_tableXpathArray
+
'['
+
(
i
+
1
)
+
']'
+
'/'
+
_relativeXpathArray
)
if
(
isGetElement
)
{
// 验证是否能找到元素
let
_xpath
=
_tableXpathArrays
+
'['
+
(
i
+
1
)
+
']'
+
'/'
+
_relativeXpathArrays
;
let
result
=
document
.
evaluate
(
_xpath
,
document
,
null
,
XPathResult
.
FIRST_ORDERED_NODE_TYPE
,
null
);
if
(
!!
result
.
singleNodeValue
)
{
existCount
++
;
}
}
...
...
@@ -138,14 +139,8 @@ function cell (xpath, name = "", type = "", title = "") {
}
/**当所有单元格验证成功后,由表发起确认动作 */
this
.
confirm
=
function
()
{
// 移除最后一个元素的下标
if
(
_tableXpathArray
.
length
>
0
)
{
let
lastElement
=
_tableXpathArray
[
_tableXpathArray
.
length
-
1
];
let
lastElementWithoutIndex
=
lastElement
.
split
(
'['
)[
0
];
_tableXpathArray
[
_tableXpathArray
.
length
-
1
]
=
lastElementWithoutIndex
;
}
this
.
tableXpath
=
_tableXpathArray
.
join
(
"/"
);
//处理下标的事
this
.
relative
P
ath
=
_relativeXpathArray
.
join
(
"/"
);
this
.
relative
Xp
ath
=
_relativeXpathArray
.
join
(
"/"
);
}
/**
* 根据索引获取值,返回{name:value}格式
...
...
@@ -153,10 +148,22 @@ function cell (xpath, name = "", type = "", title = "") {
* @param {int} index 索引号
*/
this
.
getData
=
function
(
result
,
index
)
{
let
realXpath
=
tableXpath
+
"["
+
index
+
"]"
+
this
.
relativeXpath
;
document
.
getElementById
();
this
.
type
result
[
this
.
name
]
=
"根据type获取到的值"
;
}
let
realXpath
=
this
.
tableXpath
+
"["
+
(
index
+
1
)
+
"]"
+
'/'
+
this
.
relativeXpath
;
let
results
=
document
.
evaluate
(
realXpath
,
document
,
null
,
XPathResult
.
FIRST_ORDERED_NODE_TYPE
,
null
);
if
(
!!
results
.
singleNodeValue
)
{
// 后续处理type类型事件
let
data
=
{
content
:
realXpath
,
name
:
this
.
name
,
value
:
"根据type获取到的值"
//
};
// 检查是否已存在该下标的数据
if
(
!
result
[
'content'
])
{
result
[
'content'
]
=
[];
// 如果不存在,创建新数组
}
result
[
'content'
].
push
(
data
);
// 添加数据到对应下标的数组中
}
};
return
this
;
//返回当前对象
}
export
{
cell
,
checkTableFromXpaths
,
table
}
\ No newline at end of file
export
{
cell
,
table
}
\ 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