Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kivii.Test.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
示例代码
Kivii.Test.WebDriver
Commits
12b38543
Commit
12b38543
authored
Nov 07, 2023
by
施晓雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新示例
parent
5cd2df7c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
290 additions
and
152 deletions
+290
-152
MyAction.cs
Actions/MyAction.cs
+1
-2
FrmMain.Designer.cs
FrmMain.Designer.cs
+149
-83
FrmMain.cs
FrmMain.cs
+134
-62
Kivii.Test.WebDriver.csproj
Kivii.Test.WebDriver.csproj
+2
-2
AssemblyInfo.cs
Properties/AssemblyInfo.cs
+3
-2
packages.config
packages.config
+1
-1
No files found.
Actions/MyAction.cs
View file @
12b38543
...
@@ -8,8 +8,7 @@ using System.Threading.Tasks;
...
@@ -8,8 +8,7 @@ using System.Threading.Tasks;
namespace
Kivii.Test.WebDriver
namespace
Kivii.Test.WebDriver
{
{
[
Action
(
"test.js"
,
"测试"
)]
[
Action
(
"my.jsExecuter"
,
"自定义的JS动作"
)]
//这个加了是让服务器端能识别动作的类型和描述
internal
class
MyJsAction
:
ActionBase
internal
class
MyJsAction
:
ActionBase
{
{
public
string
Js
{
get
;
set
;
}
public
string
Js
{
get
;
set
;
}
...
...
FrmMain.Designer.cs
View file @
12b38543
...
@@ -40,7 +40,6 @@
...
@@ -40,7 +40,6 @@
this
.
lnkVncUrl
=
new
System
.
Windows
.
Forms
.
LinkLabel
();
this
.
lnkVncUrl
=
new
System
.
Windows
.
Forms
.
LinkLabel
();
this
.
panel2
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
panel2
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
groupBox3
=
new
System
.
Windows
.
Forms
.
GroupBox
();
this
.
groupBox3
=
new
System
.
Windows
.
Forms
.
GroupBox
();
this
.
btnTestBaidu
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
groupBox2
=
new
System
.
Windows
.
Forms
.
GroupBox
();
this
.
groupBox2
=
new
System
.
Windows
.
Forms
.
GroupBox
();
this
.
btnInjection
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnInjection
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnHandlers
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnHandlers
=
new
System
.
Windows
.
Forms
.
Button
();
...
@@ -59,27 +58,34 @@
...
@@ -59,27 +58,34 @@
this
.
tabScripts
=
new
System
.
Windows
.
Forms
.
TabControl
();
this
.
tabScripts
=
new
System
.
Windows
.
Forms
.
TabControl
();
this
.
tpEngineScript
=
new
System
.
Windows
.
Forms
.
TabPage
();
this
.
tpEngineScript
=
new
System
.
Windows
.
Forms
.
TabPage
();
this
.
rtbEngineScript
=
new
System
.
Windows
.
Forms
.
RichTextBox
();
this
.
rtbEngineScript
=
new
System
.
Windows
.
Forms
.
RichTextBox
();
this
.
panel4
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
pnlEngineToolBar
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
btnAutoAppendScript
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnExecuteEngine
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
cbScriptTip
=
new
System
.
Windows
.
Forms
.
ComboBox
();
this
.
cbScriptTip
=
new
System
.
Windows
.
Forms
.
ComboBox
();
this
.
label5
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label5
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
btnAutoAppendScript
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
tpWebScript
=
new
System
.
Windows
.
Forms
.
TabPage
();
this
.
tpWebScript
=
new
System
.
Windows
.
Forms
.
TabPage
();
this
.
rtbWebScript
=
new
System
.
Windows
.
Forms
.
RichTextBox
();
this
.
rtbWebScript
=
new
System
.
Windows
.
Forms
.
RichTextBox
();
this
.
panel1
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
panel1
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
btnClearMsg
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnExecuteScript
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnExecuteScript
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
tpActionJson
=
new
System
.
Windows
.
Forms
.
TabPage
();
this
.
rtbActionsJson
=
new
System
.
Windows
.
Forms
.
RichTextBox
();
this
.
panel4
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
btnActionsDemo
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnActionsJson
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnShowActionsTip
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
groupBox1
.
SuspendLayout
();
this
.
groupBox1
.
SuspendLayout
();
this
.
panel2
.
SuspendLayout
();
this
.
panel2
.
SuspendLayout
();
this
.
groupBox3
.
SuspendLayout
();
this
.
groupBox2
.
SuspendLayout
();
this
.
groupBox2
.
SuspendLayout
();
this
.
panel3
.
SuspendLayout
();
this
.
panel3
.
SuspendLayout
();
this
.
gbMsg
.
SuspendLayout
();
this
.
gbMsg
.
SuspendLayout
();
this
.
gbScript
.
SuspendLayout
();
this
.
gbScript
.
SuspendLayout
();
this
.
tabScripts
.
SuspendLayout
();
this
.
tabScripts
.
SuspendLayout
();
this
.
tpEngineScript
.
SuspendLayout
();
this
.
tpEngineScript
.
SuspendLayout
();
this
.
p
anel4
.
SuspendLayout
();
this
.
p
nlEngineToolBar
.
SuspendLayout
();
this
.
tpWebScript
.
SuspendLayout
();
this
.
tpWebScript
.
SuspendLayout
();
this
.
panel1
.
SuspendLayout
();
this
.
panel1
.
SuspendLayout
();
this
.
tpActionJson
.
SuspendLayout
();
this
.
panel4
.
SuspendLayout
();
this
.
SuspendLayout
();
this
.
SuspendLayout
();
//
//
// btnOpen
// btnOpen
...
@@ -204,30 +210,19 @@
...
@@ -204,30 +210,19 @@
this
.
panel2
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
panel2
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
panel2
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
panel2
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
panel2
.
Name
=
"panel2"
;
this
.
panel2
.
Name
=
"panel2"
;
this
.
panel2
.
Size
=
new
System
.
Drawing
.
Size
(
287
,
545
);
this
.
panel2
.
Size
=
new
System
.
Drawing
.
Size
(
287
,
632
);
this
.
panel2
.
TabIndex
=
10
;
this
.
panel2
.
TabIndex
=
10
;
//
//
// groupBox3
// groupBox3
//
//
this
.
groupBox3
.
Controls
.
Add
(
this
.
btnTestBaidu
);
this
.
groupBox3
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Top
;
this
.
groupBox3
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Top
;
this
.
groupBox3
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
277
);
this
.
groupBox3
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
277
);
this
.
groupBox3
.
Name
=
"groupBox3"
;
this
.
groupBox3
.
Name
=
"groupBox3"
;
this
.
groupBox3
.
Size
=
new
System
.
Drawing
.
Size
(
287
,
1
00
);
this
.
groupBox3
.
Size
=
new
System
.
Drawing
.
Size
(
287
,
1
36
);
this
.
groupBox3
.
TabIndex
=
12
;
this
.
groupBox3
.
TabIndex
=
12
;
this
.
groupBox3
.
TabStop
=
false
;
this
.
groupBox3
.
TabStop
=
false
;
this
.
groupBox3
.
Text
=
"自动化测试"
;
this
.
groupBox3
.
Text
=
"自动化测试"
;
//
//
// btnTestBaidu
//
this
.
btnTestBaidu
.
Location
=
new
System
.
Drawing
.
Point
(
8
,
20
);
this
.
btnTestBaidu
.
Name
=
"btnTestBaidu"
;
this
.
btnTestBaidu
.
Size
=
new
System
.
Drawing
.
Size
(
119
,
23
);
this
.
btnTestBaidu
.
TabIndex
=
12
;
this
.
btnTestBaidu
.
Text
=
"执行百度查询"
;
this
.
btnTestBaidu
.
UseVisualStyleBackColor
=
true
;
this
.
btnTestBaidu
.
Click
+=
new
System
.
EventHandler
(
this
.
btnTestBaidu_Click_1
);
//
// groupBox2
// groupBox2
//
//
this
.
groupBox2
.
Controls
.
Add
(
this
.
btnInjection
);
this
.
groupBox2
.
Controls
.
Add
(
this
.
btnInjection
);
...
@@ -260,7 +255,7 @@
...
@@ -260,7 +255,7 @@
//
//
// btnHandlers
// btnHandlers
//
//
this
.
btnHandlers
.
Location
=
new
System
.
Drawing
.
Point
(
8
,
101
);
this
.
btnHandlers
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
101
);
this
.
btnHandlers
.
Name
=
"btnHandlers"
;
this
.
btnHandlers
.
Name
=
"btnHandlers"
;
this
.
btnHandlers
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
23
);
this
.
btnHandlers
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
23
);
this
.
btnHandlers
.
TabIndex
=
4
;
this
.
btnHandlers
.
TabIndex
=
4
;
...
@@ -346,7 +341,7 @@
...
@@ -346,7 +341,7 @@
this
.
panel3
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
panel3
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
panel3
.
Location
=
new
System
.
Drawing
.
Point
(
287
,
0
);
this
.
panel3
.
Location
=
new
System
.
Drawing
.
Point
(
287
,
0
);
this
.
panel3
.
Name
=
"panel3"
;
this
.
panel3
.
Name
=
"panel3"
;
this
.
panel3
.
Size
=
new
System
.
Drawing
.
Size
(
8
07
,
545
);
this
.
panel3
.
Size
=
new
System
.
Drawing
.
Size
(
8
40
,
632
);
this
.
panel3
.
TabIndex
=
12
;
this
.
panel3
.
TabIndex
=
12
;
//
//
// gbMsg
// gbMsg
...
@@ -355,7 +350,7 @@
...
@@ -355,7 +350,7 @@
this
.
gbMsg
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
gbMsg
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
gbMsg
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
gbMsg
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
gbMsg
.
Name
=
"gbMsg"
;
this
.
gbMsg
.
Name
=
"gbMsg"
;
this
.
gbMsg
.
Size
=
new
System
.
Drawing
.
Size
(
8
07
,
31
9
);
this
.
gbMsg
.
Size
=
new
System
.
Drawing
.
Size
(
8
40
,
34
9
);
this
.
gbMsg
.
TabIndex
=
14
;
this
.
gbMsg
.
TabIndex
=
14
;
this
.
gbMsg
.
TabStop
=
false
;
this
.
gbMsg
.
TabStop
=
false
;
this
.
gbMsg
.
Text
=
"输出"
;
this
.
gbMsg
.
Text
=
"输出"
;
...
@@ -366,18 +361,18 @@
...
@@ -366,18 +361,18 @@
this
.
rtbMsg
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
17
);
this
.
rtbMsg
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
17
);
this
.
rtbMsg
.
Name
=
"rtbMsg"
;
this
.
rtbMsg
.
Name
=
"rtbMsg"
;
this
.
rtbMsg
.
ReadOnly
=
true
;
this
.
rtbMsg
.
ReadOnly
=
true
;
this
.
rtbMsg
.
Size
=
new
System
.
Drawing
.
Size
(
8
01
,
29
9
);
this
.
rtbMsg
.
Size
=
new
System
.
Drawing
.
Size
(
8
34
,
32
9
);
this
.
rtbMsg
.
TabIndex
=
5
;
this
.
rtbMsg
.
TabIndex
=
5
;
this
.
rtbMsg
.
Text
=
""
;
this
.
rtbMsg
.
Text
=
""
;
this
.
rtbMsg
.
DoubleClick
+=
new
System
.
EventHandler
(
this
.
rtbMsg_DoubleClick
);
//
//
// gbScript
// gbScript
//
//
this
.
gbScript
.
Controls
.
Add
(
this
.
tabScripts
);
this
.
gbScript
.
Controls
.
Add
(
this
.
tabScripts
);
this
.
gbScript
.
Controls
.
Add
(
this
.
panel1
);
this
.
gbScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
gbScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
gbScript
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
3
1
9
);
this
.
gbScript
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
3
4
9
);
this
.
gbScript
.
Name
=
"gbScript"
;
this
.
gbScript
.
Name
=
"gbScript"
;
this
.
gbScript
.
Size
=
new
System
.
Drawing
.
Size
(
8
07
,
226
);
this
.
gbScript
.
Size
=
new
System
.
Drawing
.
Size
(
8
40
,
283
);
this
.
gbScript
.
TabIndex
=
13
;
this
.
gbScript
.
TabIndex
=
13
;
this
.
gbScript
.
TabStop
=
false
;
this
.
gbScript
.
TabStop
=
false
;
this
.
gbScript
.
Text
=
"执行Javascript脚本"
;
this
.
gbScript
.
Text
=
"执行Javascript脚本"
;
...
@@ -386,21 +381,22 @@
...
@@ -386,21 +381,22 @@
//
//
this
.
tabScripts
.
Controls
.
Add
(
this
.
tpEngineScript
);
this
.
tabScripts
.
Controls
.
Add
(
this
.
tpEngineScript
);
this
.
tabScripts
.
Controls
.
Add
(
this
.
tpWebScript
);
this
.
tabScripts
.
Controls
.
Add
(
this
.
tpWebScript
);
this
.
tabScripts
.
Controls
.
Add
(
this
.
tpActionJson
);
this
.
tabScripts
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
tabScripts
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
tabScripts
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
17
);
this
.
tabScripts
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
17
);
this
.
tabScripts
.
Name
=
"tabScripts"
;
this
.
tabScripts
.
Name
=
"tabScripts"
;
this
.
tabScripts
.
SelectedIndex
=
0
;
this
.
tabScripts
.
SelectedIndex
=
0
;
this
.
tabScripts
.
Size
=
new
System
.
Drawing
.
Size
(
8
01
,
181
);
this
.
tabScripts
.
Size
=
new
System
.
Drawing
.
Size
(
8
34
,
263
);
this
.
tabScripts
.
TabIndex
=
8
;
this
.
tabScripts
.
TabIndex
=
8
;
//
//
// tpEngineScript
// tpEngineScript
//
//
this
.
tpEngineScript
.
Controls
.
Add
(
this
.
rtbEngineScript
);
this
.
tpEngineScript
.
Controls
.
Add
(
this
.
rtbEngineScript
);
this
.
tpEngineScript
.
Controls
.
Add
(
this
.
p
anel4
);
this
.
tpEngineScript
.
Controls
.
Add
(
this
.
p
nlEngineToolBar
);
this
.
tpEngineScript
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
22
);
this
.
tpEngineScript
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
22
);
this
.
tpEngineScript
.
Name
=
"tpEngineScript"
;
this
.
tpEngineScript
.
Name
=
"tpEngineScript"
;
this
.
tpEngineScript
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
tpEngineScript
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
tpEngineScript
.
Size
=
new
System
.
Drawing
.
Size
(
793
,
155
);
this
.
tpEngineScript
.
Size
=
new
System
.
Drawing
.
Size
(
826
,
237
);
this
.
tpEngineScript
.
TabIndex
=
0
;
this
.
tpEngineScript
.
TabIndex
=
0
;
this
.
tpEngineScript
.
Tag
=
"engine"
;
this
.
tpEngineScript
.
Tag
=
"engine"
;
this
.
tpEngineScript
.
Text
=
"引擎执行(driver为变量名)"
;
this
.
tpEngineScript
.
Text
=
"引擎执行(driver为变量名)"
;
...
@@ -412,24 +408,45 @@
...
@@ -412,24 +408,45 @@
this
.
rtbEngineScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
rtbEngineScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
rtbEngineScript
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
3
);
this
.
rtbEngineScript
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
3
);
this
.
rtbEngineScript
.
Name
=
"rtbEngineScript"
;
this
.
rtbEngineScript
.
Name
=
"rtbEngineScript"
;
this
.
rtbEngineScript
.
Size
=
new
System
.
Drawing
.
Size
(
787
,
129
);
this
.
rtbEngineScript
.
Size
=
new
System
.
Drawing
.
Size
(
820
,
211
);
this
.
rtbEngineScript
.
TabIndex
=
10
;
this
.
rtbEngineScript
.
TabIndex
=
10
;
this
.
rtbEngineScript
.
Text
=
""
;
this
.
rtbEngineScript
.
Text
=
""
;
//
//
// p
anel4
// p
nlEngineToolBar
//
//
this
.
panel4
.
Controls
.
Add
(
this
.
cbScriptTip
);
this
.
pnlEngineToolBar
.
Controls
.
Add
(
this
.
btnAutoAppendScript
);
this
.
panel4
.
Controls
.
Add
(
this
.
label5
);
this
.
pnlEngineToolBar
.
Controls
.
Add
(
this
.
btnExecuteEngine
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnAutoAppendScript
);
this
.
pnlEngineToolBar
.
Controls
.
Add
(
this
.
cbScriptTip
);
this
.
panel4
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
pnlEngineToolBar
.
Controls
.
Add
(
this
.
label5
);
this
.
panel4
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
132
);
this
.
pnlEngineToolBar
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
panel4
.
Name
=
"panel4"
;
this
.
pnlEngineToolBar
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
214
);
this
.
panel4
.
Size
=
new
System
.
Drawing
.
Size
(
787
,
20
);
this
.
pnlEngineToolBar
.
Name
=
"pnlEngineToolBar"
;
this
.
panel4
.
TabIndex
=
9
;
this
.
pnlEngineToolBar
.
Size
=
new
System
.
Drawing
.
Size
(
820
,
20
);
this
.
pnlEngineToolBar
.
TabIndex
=
9
;
//
// btnAutoAppendScript
//
this
.
btnAutoAppendScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
btnAutoAppendScript
.
Location
=
new
System
.
Drawing
.
Point
(
689
,
0
);
this
.
btnAutoAppendScript
.
Name
=
"btnAutoAppendScript"
;
this
.
btnAutoAppendScript
.
Size
=
new
System
.
Drawing
.
Size
(
56
,
20
);
this
.
btnAutoAppendScript
.
TabIndex
=
5
;
this
.
btnAutoAppendScript
.
Text
=
"选择 ↑ "
;
this
.
btnAutoAppendScript
.
UseVisualStyleBackColor
=
true
;
//
// btnExecuteEngine
//
this
.
btnExecuteEngine
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
btnExecuteEngine
.
Location
=
new
System
.
Drawing
.
Point
(
745
,
0
);
this
.
btnExecuteEngine
.
Name
=
"btnExecuteEngine"
;
this
.
btnExecuteEngine
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
20
);
this
.
btnExecuteEngine
.
TabIndex
=
4
;
this
.
btnExecuteEngine
.
Text
=
"执行脚本"
;
this
.
btnExecuteEngine
.
UseVisualStyleBackColor
=
true
;
this
.
btnExecuteEngine
.
Click
+=
new
System
.
EventHandler
(
this
.
btnExecuteEngine_Click
);
//
//
// cbScriptTip
// cbScriptTip
//
//
this
.
cbScriptTip
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
cbScriptTip
.
FormattingEnabled
=
true
;
this
.
cbScriptTip
.
FormattingEnabled
=
true
;
this
.
cbScriptTip
.
Items
.
AddRange
(
new
object
[]
{
this
.
cbScriptTip
.
Items
.
AddRange
(
new
object
[]
{
"driver.LoadScript(\"\");//在当前页面加载一个JS路径"
,
"driver.LoadScript(\"\");//在当前页面加载一个JS路径"
,
...
@@ -457,7 +474,7 @@
...
@@ -457,7 +474,7 @@
"driver.Sleep(1000);//睡眠1000毫秒"
});
"driver.Sleep(1000);//睡眠1000毫秒"
});
this
.
cbScriptTip
.
Location
=
new
System
.
Drawing
.
Point
(
59
,
0
);
this
.
cbScriptTip
.
Location
=
new
System
.
Drawing
.
Point
(
59
,
0
);
this
.
cbScriptTip
.
Name
=
"cbScriptTip"
;
this
.
cbScriptTip
.
Name
=
"cbScriptTip"
;
this
.
cbScriptTip
.
Size
=
new
System
.
Drawing
.
Size
(
6
72
,
20
);
this
.
cbScriptTip
.
Size
=
new
System
.
Drawing
.
Size
(
6
45
,
20
);
this
.
cbScriptTip
.
TabIndex
=
3
;
this
.
cbScriptTip
.
TabIndex
=
3
;
//
//
// label5
// label5
...
@@ -470,24 +487,14 @@
...
@@ -470,24 +487,14 @@
this
.
label5
.
Text
=
"脚本提示:"
;
this
.
label5
.
Text
=
"脚本提示:"
;
this
.
label5
.
TextAlign
=
System
.
Drawing
.
ContentAlignment
.
MiddleLeft
;
this
.
label5
.
TextAlign
=
System
.
Drawing
.
ContentAlignment
.
MiddleLeft
;
//
//
// btnAutoAppendScript
//
this
.
btnAutoAppendScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
btnAutoAppendScript
.
Location
=
new
System
.
Drawing
.
Point
(
731
,
0
);
this
.
btnAutoAppendScript
.
Name
=
"btnAutoAppendScript"
;
this
.
btnAutoAppendScript
.
Size
=
new
System
.
Drawing
.
Size
(
56
,
20
);
this
.
btnAutoAppendScript
.
TabIndex
=
0
;
this
.
btnAutoAppendScript
.
Text
=
"选择 ↑ "
;
this
.
btnAutoAppendScript
.
UseVisualStyleBackColor
=
true
;
this
.
btnAutoAppendScript
.
Click
+=
new
System
.
EventHandler
(
this
.
btnAutoAppendScript_Click
);
//
// tpWebScript
// tpWebScript
//
//
this
.
tpWebScript
.
Controls
.
Add
(
this
.
rtbWebScript
);
this
.
tpWebScript
.
Controls
.
Add
(
this
.
rtbWebScript
);
this
.
tpWebScript
.
Controls
.
Add
(
this
.
panel1
);
this
.
tpWebScript
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
22
);
this
.
tpWebScript
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
22
);
this
.
tpWebScript
.
Name
=
"tpWebScript"
;
this
.
tpWebScript
.
Name
=
"tpWebScript"
;
this
.
tpWebScript
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
tpWebScript
.
Padding
=
new
System
.
Windows
.
Forms
.
Padding
(
3
);
this
.
tpWebScript
.
Size
=
new
System
.
Drawing
.
Size
(
793
,
155
);
this
.
tpWebScript
.
Size
=
new
System
.
Drawing
.
Size
(
826
,
237
);
this
.
tpWebScript
.
TabIndex
=
1
;
this
.
tpWebScript
.
TabIndex
=
1
;
this
.
tpWebScript
.
Tag
=
"web"
;
this
.
tpWebScript
.
Tag
=
"web"
;
this
.
tpWebScript
.
Text
=
"网页内执行"
;
this
.
tpWebScript
.
Text
=
"网页内执行"
;
...
@@ -499,47 +506,100 @@
...
@@ -499,47 +506,100 @@
this
.
rtbWebScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
rtbWebScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
rtbWebScript
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
3
);
this
.
rtbWebScript
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
3
);
this
.
rtbWebScript
.
Name
=
"rtbWebScript"
;
this
.
rtbWebScript
.
Name
=
"rtbWebScript"
;
this
.
rtbWebScript
.
Size
=
new
System
.
Drawing
.
Size
(
787
,
149
);
this
.
rtbWebScript
.
Size
=
new
System
.
Drawing
.
Size
(
820
,
211
);
this
.
rtbWebScript
.
TabIndex
=
9
;
this
.
rtbWebScript
.
TabIndex
=
11
;
this
.
rtbWebScript
.
Text
=
""
;
this
.
rtbWebScript
.
Text
=
""
;
//
//
// panel1
// panel1
//
//
this
.
panel1
.
Controls
.
Add
(
this
.
btnClearMsg
);
this
.
panel1
.
Controls
.
Add
(
this
.
btnExecuteScript
);
this
.
panel1
.
Controls
.
Add
(
this
.
btnExecuteScript
);
this
.
panel1
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
panel1
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
panel1
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
198
);
this
.
panel1
.
Location
=
new
System
.
Drawing
.
Point
(
3
,
214
);
this
.
panel1
.
Name
=
"panel1"
;
this
.
panel1
.
Name
=
"panel1"
;
this
.
panel1
.
Size
=
new
System
.
Drawing
.
Size
(
801
,
25
);
this
.
panel1
.
Size
=
new
System
.
Drawing
.
Size
(
820
,
20
);
this
.
panel1
.
TabIndex
=
2
;
this
.
panel1
.
TabIndex
=
10
;
//
// btnClearMsg
//
this
.
btnClearMsg
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
btnClearMsg
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
btnClearMsg
.
Name
=
"btnClearMsg"
;
this
.
btnClearMsg
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
25
);
this
.
btnClearMsg
.
TabIndex
=
2
;
this
.
btnClearMsg
.
Text
=
"清除输出"
;
this
.
btnClearMsg
.
UseVisualStyleBackColor
=
true
;
this
.
btnClearMsg
.
Click
+=
new
System
.
EventHandler
(
this
.
btnClearMsg_Click
);
//
//
// btnExecuteScript
// btnExecuteScript
//
//
this
.
btnExecuteScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
btnExecuteScript
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
btnExecuteScript
.
Location
=
new
System
.
Drawing
.
Point
(
7
26
,
0
);
this
.
btnExecuteScript
.
Location
=
new
System
.
Drawing
.
Point
(
7
45
,
0
);
this
.
btnExecuteScript
.
Name
=
"btnExecuteScript"
;
this
.
btnExecuteScript
.
Name
=
"btnExecuteScript"
;
this
.
btnExecuteScript
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
2
5
);
this
.
btnExecuteScript
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
2
0
);
this
.
btnExecuteScript
.
TabIndex
=
1
;
this
.
btnExecuteScript
.
TabIndex
=
5
;
this
.
btnExecuteScript
.
Text
=
"执行脚本"
;
this
.
btnExecuteScript
.
Text
=
"执行脚本"
;
this
.
btnExecuteScript
.
UseVisualStyleBackColor
=
true
;
this
.
btnExecuteScript
.
UseVisualStyleBackColor
=
true
;
this
.
btnExecuteScript
.
Click
+=
new
System
.
EventHandler
(
this
.
btnExecuteScript_Click
);
this
.
btnExecuteScript
.
Click
+=
new
System
.
EventHandler
(
this
.
btnExecuteScript_Click
);
//
//
// tpActionJson
//
this
.
tpActionJson
.
Controls
.
Add
(
this
.
rtbActionsJson
);
this
.
tpActionJson
.
Controls
.
Add
(
this
.
panel4
);
this
.
tpActionJson
.
Location
=
new
System
.
Drawing
.
Point
(
4
,
22
);
this
.
tpActionJson
.
Name
=
"tpActionJson"
;
this
.
tpActionJson
.
Size
=
new
System
.
Drawing
.
Size
(
826
,
237
);
this
.
tpActionJson
.
TabIndex
=
2
;
this
.
tpActionJson
.
Text
=
"Action自动化测试"
;
this
.
tpActionJson
.
UseVisualStyleBackColor
=
true
;
//
// rtbActionsJson
//
this
.
rtbActionsJson
.
BorderStyle
=
System
.
Windows
.
Forms
.
BorderStyle
.
None
;
this
.
rtbActionsJson
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
rtbActionsJson
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
rtbActionsJson
.
Name
=
"rtbActionsJson"
;
this
.
rtbActionsJson
.
Size
=
new
System
.
Drawing
.
Size
(
826
,
217
);
this
.
rtbActionsJson
.
TabIndex
=
13
;
this
.
rtbActionsJson
.
Text
=
""
;
//
// panel4
//
this
.
panel4
.
Controls
.
Add
(
this
.
btnShowActionsTip
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnActionsDemo
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnActionsJson
);
this
.
panel4
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
panel4
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
217
);
this
.
panel4
.
Name
=
"panel4"
;
this
.
panel4
.
Size
=
new
System
.
Drawing
.
Size
(
826
,
20
);
this
.
panel4
.
TabIndex
=
12
;
//
// btnActionsDemo
//
this
.
btnActionsDemo
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
btnActionsDemo
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
this
.
btnActionsDemo
.
Name
=
"btnActionsDemo"
;
this
.
btnActionsDemo
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
20
);
this
.
btnActionsDemo
.
TabIndex
=
13
;
this
.
btnActionsDemo
.
Text
=
"加载示例"
;
this
.
btnActionsDemo
.
UseVisualStyleBackColor
=
true
;
this
.
btnActionsDemo
.
Click
+=
new
System
.
EventHandler
(
this
.
btnActionsDemo_Click
);
//
// btnActionsJson
//
this
.
btnActionsJson
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
btnActionsJson
.
Location
=
new
System
.
Drawing
.
Point
(
751
,
0
);
this
.
btnActionsJson
.
Name
=
"btnActionsJson"
;
this
.
btnActionsJson
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
20
);
this
.
btnActionsJson
.
TabIndex
=
5
;
this
.
btnActionsJson
.
Text
=
"执行脚本"
;
this
.
btnActionsJson
.
UseVisualStyleBackColor
=
true
;
this
.
btnActionsJson
.
Click
+=
new
System
.
EventHandler
(
this
.
btnActionsJson_Click
);
//
// btnShowActionsTip
//
this
.
btnShowActionsTip
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
btnShowActionsTip
.
Location
=
new
System
.
Drawing
.
Point
(
72
,
0
);
this
.
btnShowActionsTip
.
Name
=
"btnShowActionsTip"
;
this
.
btnShowActionsTip
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
20
);
this
.
btnShowActionsTip
.
TabIndex
=
14
;
this
.
btnShowActionsTip
.
Text
=
"显示动作类型"
;
this
.
btnShowActionsTip
.
UseVisualStyleBackColor
=
true
;
this
.
btnShowActionsTip
.
Click
+=
new
System
.
EventHandler
(
this
.
btnShowActionsTip_Click
);
//
// FrmMain
// FrmMain
//
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1
094
,
545
);
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1
127
,
632
);
this
.
Controls
.
Add
(
this
.
panel3
);
this
.
Controls
.
Add
(
this
.
panel3
);
this
.
Controls
.
Add
(
this
.
panel2
);
this
.
Controls
.
Add
(
this
.
panel2
);
this
.
Name
=
"FrmMain"
;
this
.
Name
=
"FrmMain"
;
...
@@ -547,7 +607,6 @@
...
@@ -547,7 +607,6 @@
this
.
groupBox1
.
ResumeLayout
(
false
);
this
.
groupBox1
.
ResumeLayout
(
false
);
this
.
groupBox1
.
PerformLayout
();
this
.
groupBox1
.
PerformLayout
();
this
.
panel2
.
ResumeLayout
(
false
);
this
.
panel2
.
ResumeLayout
(
false
);
this
.
groupBox3
.
ResumeLayout
(
false
);
this
.
groupBox2
.
ResumeLayout
(
false
);
this
.
groupBox2
.
ResumeLayout
(
false
);
this
.
groupBox2
.
PerformLayout
();
this
.
groupBox2
.
PerformLayout
();
this
.
panel3
.
ResumeLayout
(
false
);
this
.
panel3
.
ResumeLayout
(
false
);
...
@@ -555,9 +614,11 @@
...
@@ -555,9 +614,11 @@
this
.
gbScript
.
ResumeLayout
(
false
);
this
.
gbScript
.
ResumeLayout
(
false
);
this
.
tabScripts
.
ResumeLayout
(
false
);
this
.
tabScripts
.
ResumeLayout
(
false
);
this
.
tpEngineScript
.
ResumeLayout
(
false
);
this
.
tpEngineScript
.
ResumeLayout
(
false
);
this
.
p
anel4
.
ResumeLayout
(
false
);
this
.
p
nlEngineToolBar
.
ResumeLayout
(
false
);
this
.
tpWebScript
.
ResumeLayout
(
false
);
this
.
tpWebScript
.
ResumeLayout
(
false
);
this
.
panel1
.
ResumeLayout
(
false
);
this
.
panel1
.
ResumeLayout
(
false
);
this
.
tpActionJson
.
ResumeLayout
(
false
);
this
.
panel4
.
ResumeLayout
(
false
);
this
.
ResumeLayout
(
false
);
this
.
ResumeLayout
(
false
);
}
}
...
@@ -583,18 +644,13 @@
...
@@ -583,18 +644,13 @@
private
System
.
Windows
.
Forms
.
GroupBox
gbMsg
;
private
System
.
Windows
.
Forms
.
GroupBox
gbMsg
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbMsg
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbMsg
;
private
System
.
Windows
.
Forms
.
GroupBox
gbScript
;
private
System
.
Windows
.
Forms
.
GroupBox
gbScript
;
private
System
.
Windows
.
Forms
.
Panel
panel1
;
private
System
.
Windows
.
Forms
.
Button
btnExecuteScript
;
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Button
btnHandlers
;
private
System
.
Windows
.
Forms
.
Button
btnHandlers
;
private
System
.
Windows
.
Forms
.
TabControl
tabScripts
;
private
System
.
Windows
.
Forms
.
TabControl
tabScripts
;
private
System
.
Windows
.
Forms
.
TabPage
tpEngineScript
;
private
System
.
Windows
.
Forms
.
TabPage
tpEngineScript
;
private
System
.
Windows
.
Forms
.
TabPage
tpWebScript
;
private
System
.
Windows
.
Forms
.
TabPage
tpWebScript
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbWebScript
;
private
System
.
Windows
.
Forms
.
Button
btnClearMsg
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbEngineScript
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbEngineScript
;
private
System
.
Windows
.
Forms
.
Panel
panel4
;
private
System
.
Windows
.
Forms
.
Panel
pnlEngineToolBar
;
private
System
.
Windows
.
Forms
.
Button
btnAutoAppendScript
;
private
System
.
Windows
.
Forms
.
ComboBox
cbScriptTip
;
private
System
.
Windows
.
Forms
.
ComboBox
cbScriptTip
;
private
System
.
Windows
.
Forms
.
Label
label5
;
private
System
.
Windows
.
Forms
.
Label
label5
;
private
System
.
Windows
.
Forms
.
LinkLabel
lnkVncUrl
;
private
System
.
Windows
.
Forms
.
LinkLabel
lnkVncUrl
;
...
@@ -603,7 +659,17 @@
...
@@ -603,7 +659,17 @@
private
System
.
Windows
.
Forms
.
Label
label6
;
private
System
.
Windows
.
Forms
.
Label
label6
;
private
System
.
Windows
.
Forms
.
TextBox
tbxVarName
;
private
System
.
Windows
.
Forms
.
TextBox
tbxVarName
;
private
System
.
Windows
.
Forms
.
GroupBox
groupBox3
;
private
System
.
Windows
.
Forms
.
GroupBox
groupBox3
;
private
System
.
Windows
.
Forms
.
Button
btnTestBaidu
;
private
System
.
Windows
.
Forms
.
Button
btnAutoAppendScript
;
private
System
.
Windows
.
Forms
.
Button
btnExecuteEngine
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbWebScript
;
private
System
.
Windows
.
Forms
.
Panel
panel1
;
private
System
.
Windows
.
Forms
.
Button
btnExecuteScript
;
private
System
.
Windows
.
Forms
.
TabPage
tpActionJson
;
private
System
.
Windows
.
Forms
.
RichTextBox
rtbActionsJson
;
private
System
.
Windows
.
Forms
.
Panel
panel4
;
private
System
.
Windows
.
Forms
.
Button
btnActionsJson
;
private
System
.
Windows
.
Forms
.
Button
btnActionsDemo
;
private
System
.
Windows
.
Forms
.
Button
btnShowActionsTip
;
}
}
}
}
FrmMain.cs
View file @
12b38543
using
Kivii.WebDriver
;
using
Kivii.WebDriver
;
using
Kivii.WebDriver.Actions
;
using
Kivii.WebDriver.Actions
;
using
Newtonsoft.Json
;
using
OpenQA.Selenium.Firefox
;
using
OpenQA.Selenium.Firefox
;
using
OpenQA.Selenium.Remote
;
using
OpenQA.Selenium.Remote
;
using
OpenQA.Selenium.Support.Events
;
using
OpenQA.Selenium.Support.Events
;
...
@@ -147,6 +148,11 @@ namespace Kivii.Test.WebDriver
...
@@ -147,6 +148,11 @@ namespace Kivii.Test.WebDriver
#
endregion
#
endregion
#
region
交互事件
#
region
交互事件
/// <summary>
/// 初始化管理器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnOpen_Click
(
object
sender
,
EventArgs
e
)
private
void
btnOpen_Click
(
object
sender
,
EventArgs
e
)
{
{
if
(
_manager
!=
null
)
return
;
if
(
_manager
!=
null
)
return
;
...
@@ -173,12 +179,21 @@ namespace Kivii.Test.WebDriver
...
@@ -173,12 +179,21 @@ namespace Kivii.Test.WebDriver
appendMsg
(
"初始化失败,可能是未能成功连接WebDriver驱动!"
);
appendMsg
(
"初始化失败,可能是未能成功连接WebDriver驱动!"
);
}
}
}
}
/// <summary>
/// 关闭管理器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnClose_Click
(
object
sender
,
EventArgs
e
)
private
void
btnClose_Click
(
object
sender
,
EventArgs
e
)
{
{
_manager
?.
Dispose
();
_manager
?.
Dispose
();
_manager
=
null
;
_manager
=
null
;
}
}
/// <summary>
/// 浏览器截图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnScreenshot_Click
(
object
sender
,
EventArgs
e
)
private
void
btnScreenshot_Click
(
object
sender
,
EventArgs
e
)
{
{
//if (_driver == null) return;
//if (_driver == null) return;
...
@@ -187,18 +202,31 @@ namespace Kivii.Test.WebDriver
...
@@ -187,18 +202,31 @@ namespace Kivii.Test.WebDriver
if
(
sfd
.
ShowDialog
()
!=
DialogResult
.
OK
)
return
;
if
(
sfd
.
ShowDialog
()
!=
DialogResult
.
OK
)
return
;
_manager
?.
Screenshot
(
sfd
.
FileName
);
_manager
?.
Screenshot
(
sfd
.
FileName
);
}
}
/// <summary>
/// 向网页加载一个脚本路径
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnLoadScript_Click
(
object
sender
,
EventArgs
e
)
private
void
btnLoadScript_Click
(
object
sender
,
EventArgs
e
)
{
{
_manager
?.
LoadScript
(
tbxScriptPath
.
Text
);
_manager
?.
LoadScript
(
tbxScriptPath
.
Text
);
}
}
/// <summary>
/// 使用远程WebDriver选择框发生变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
cbxRemote_CheckedChanged
(
object
sender
,
EventArgs
e
)
private
void
cbxRemote_CheckedChanged
(
object
sender
,
EventArgs
e
)
{
{
lnkVncUrl
.
Enabled
=
cbxRemote
.
Checked
;
lnkVncUrl
.
Enabled
=
cbxRemote
.
Checked
;
cbUseHub
.
Enabled
=
cbxRemote
.
Checked
;
cbUseHub
.
Enabled
=
cbxRemote
.
Checked
;
cbxBrowserType_SelectedIndexChanged
(
null
,
null
);
cbxBrowserType_SelectedIndexChanged
(
null
,
null
);
}
}
/// <summary>
/// 浏览器类型选择发生变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
cbxBrowserType_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
private
void
cbxBrowserType_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
{
{
if
(!
cbxRemote
.
Checked
)
if
(!
cbxRemote
.
Checked
)
...
@@ -222,6 +250,11 @@ namespace Kivii.Test.WebDriver
...
@@ -222,6 +250,11 @@ namespace Kivii.Test.WebDriver
}
}
}
}
}
}
/// <summary>
/// 点击了远程浏览器VNC
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
lnkVncUrl_LinkClicked
(
object
sender
,
LinkLabelLinkClickedEventArgs
e
)
private
void
lnkVncUrl_LinkClicked
(
object
sender
,
LinkLabelLinkClickedEventArgs
e
)
{
{
if
(
cbUseHub
.
Checked
)
if
(
cbUseHub
.
Checked
)
...
@@ -233,27 +266,21 @@ namespace Kivii.Test.WebDriver
...
@@ -233,27 +266,21 @@ namespace Kivii.Test.WebDriver
System
.
Diagnostics
.
Process
.
Start
(
$"
{
lnkVncUrl
.
Text
}
/?autoconnect=1&resize=scale&password=secret"
);
System
.
Diagnostics
.
Process
.
Start
(
$"
{
lnkVncUrl
.
Text
}
/?autoconnect=1&resize=scale&password=secret"
);
}
}
}
}
/// <summary>
/// 导航至某个网页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnNavigate_Click
(
object
sender
,
EventArgs
e
)
private
void
btnNavigate_Click
(
object
sender
,
EventArgs
e
)
{
{
_manager
?.
NavigateTo
(
tbxUrl
.
Text
);
_manager
?.
NavigateTo
(
tbxUrl
.
Text
);
}
}
private
void
btnExecuteScript_Click
(
object
sender
,
EventArgs
e
)
{
if
(
tabScripts
.
SelectedTab
.
Tag
.
ToString
()
==
"engine"
)
//网页内执行
{
var
result
=
_manager
.
Execute
(
rtbEngineScript
.
Text
);
rtbEngineScript
.
Clear
();
appendMsg
(
$"Result:
{
result
}
"
);
}
else
if
(
tabScripts
.
SelectedTab
.
Tag
.
ToString
()
==
"web"
)
{
var
result
=
_manager
?.
ExecuteScript
(
rtbWebScript
.
Text
);
rtbWebScript
.
Clear
();
appendMsg
(
$"Result:
{
result
}
"
);
}
}
/// <summary>
/// 显示当前浏览器中所有的窗口信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnHandlers_Click
(
object
sender
,
EventArgs
e
)
private
void
btnHandlers_Click
(
object
sender
,
EventArgs
e
)
{
{
foreach
(
var
handler
in
_manager
.
AllWindowHandles
)
foreach
(
var
handler
in
_manager
.
AllWindowHandles
)
...
@@ -262,37 +289,20 @@ namespace Kivii.Test.WebDriver
...
@@ -262,37 +289,20 @@ namespace Kivii.Test.WebDriver
}
}
}
}
private
void
btnClearMsg_Click
(
object
sender
,
EventArgs
e
)
/// <summary>
{
/// 向执行器加入一段代码
rtbMsg
.
Clear
();
/// </summary>
}
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnAutoAppendScript_Click
(
object
sender
,
EventArgs
e
)
private
void
btnAutoAppendScript_Click
(
object
sender
,
EventArgs
e
)
{
{
rtbEngineScript
.
AppendText
(
$"
{
cbScriptTip
.
Text
}{
Environment
.
NewLine
}
"
);
rtbEngineScript
.
AppendText
(
$"
{
cbScriptTip
.
Text
}{
Environment
.
NewLine
}
"
);
}
}
/// <summary>
/// 向管理器引擎注入一个变量
/// </summary>
private
void
btnTest_Click
(
object
sender
,
EventArgs
e
)
/// <param name="sender"></param>
{
/// <param name="e"></param>
RemoteWebDriver
driver
=
null
;
try
{
driver
=
new
RemoteWebDriver
(
new
FirefoxOptions
().
ToCapabilities
());
//System.Diagnostics.Process.Start($"http://viewer.firefox.selenium.kivii.org/?autoconnect=1&resize=scale&password=secret");
//driver.Navigate().GoToUrl("https://www.baidu.com");
driver
.
ExecuteScript
(
"console.log(1);"
);
driver
.
ExecuteScript
(
"document.getElementByTagName('head');"
);
driver
.
ExecuteScript
(
"alert('1')"
,
""
);
}
catch
(
Exception
ex
)
{
appendMsg
(
$"Ex:
{
Environment
.
NewLine
}{
ex
.
Message
}
"
);
}
driver
.
Quit
();
}
private
void
btnInjection_Click
(
object
sender
,
EventArgs
e
)
private
void
btnInjection_Click
(
object
sender
,
EventArgs
e
)
{
{
//向Manager中注入一个变量,可以在引擎执行代码中调用,变量名为tbxVarName中配置的
//向Manager中注入一个变量,可以在引擎执行代码中调用,变量名为tbxVarName中配置的
...
@@ -302,44 +312,80 @@ namespace Kivii.Test.WebDriver
...
@@ -302,44 +312,80 @@ namespace Kivii.Test.WebDriver
appendMsg
(
$"注入了变量名为
{
tbxVarName
.
Text
}
,可在引擎代码中执行
{
tbxVarName
.
Text
}
.
{
nameof
(
InjectionTest
.
MessageBox
)}
(\"消息\");或
{
tbxVarName
.
Text
}
.
{
nameof
(
InjectionTest
.
GetValue
)}
(\"内容\")"
);
appendMsg
(
$"注入了变量名为
{
tbxVarName
.
Text
}
,可在引擎代码中执行
{
tbxVarName
.
Text
}
.
{
nameof
(
InjectionTest
.
MessageBox
)}
(\"消息\");或
{
tbxVarName
.
Text
}
.
{
nameof
(
InjectionTest
.
GetValue
)}
(\"内容\")"
);
}
}
#
endregion
#
endregion
/// <summary>
/// 双击输出消息,清除内容
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
rtbMsg_DoubleClick
(
object
sender
,
EventArgs
e
)
{
rtbMsg
.
Clear
();
}
private
void
btnTestBaidu_Click_1
(
object
sender
,
EventArgs
e
)
#
region
三个脚本执行功能
/// <summary>
/// 执行内置脚本引擎
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnExecuteEngine_Click
(
object
sender
,
EventArgs
e
)
{
{
if
(
_manager
==
null
)
return
;
var
result
=
_manager
.
Execute
(
rtbEngineScript
.
Text
);
_manager
.
Maximize
();
//最大化网页
rtbEngineScript
.
Clear
();
var
baidu
=
new
WebPage
(
_manager
);
appendMsg
(
$"Result:
{
result
}
"
);
baidu
.
Url
=
"https://www.baidu.com"
;
}
/// <summary>
/// 执行网页内的Javascript
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnExecuteScript_Click
(
object
sender
,
EventArgs
e
)
{
var
result
=
_manager
?.
ExecuteScript
(
rtbWebScript
.
Text
);
rtbWebScript
.
Clear
();
appendMsg
(
$"Result:
{
result
}
"
);
}
/// <summary>
/// 加载一段演示动作的Actions代码,JSON格式
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnActionsDemo_Click
(
object
sender
,
EventArgs
e
)
{
var
autoPage
=
new
WebPage
(
null
);
//autoPage.Url = "https://www.baidu.com";//生成DEMO时不需要
#
region
第一步,在输入框内输入内容
#
region
第一步,在输入框内输入内容
var
inputAction
=
new
InputAction
();
var
inputAction
=
new
InputAction
();
inputAction
.
Name
=
"输入查询内容"
;
inputAction
.
Name
=
"输入查询内容"
;
inputAction
.
InputValue
=
"最近天气"
;
inputAction
.
InputValue
=
"最近天气"
;
inputAction
.
ElementFinder
=
new
ElementFinder
(
"kw"
,
"id"
);
inputAction
.
ElementFinder
=
new
ElementFinder
(
"kw"
,
"id"
);
baidu
.
Actions
.
Add
(
inputAction
);
autoPage
.
Actions
.
Add
(
inputAction
);
#
endregion
#
endregion
#
region
第二步点击百度一下查询按键
#
region
第二步点击百度一下查询按键
var
clickAction
=
new
ClickAction
();
var
clickAction
=
new
ClickAction
();
clickAction
.
Name
=
"百度一下"
;
clickAction
.
Name
=
"百度一下"
;
clickAction
.
ElementFinder
=
new
ElementFinder
(
"su"
,
"id"
);
clickAction
.
ElementFinder
=
new
ElementFinder
(
"su"
,
"id"
);
baidu
.
Actions
.
Add
(
clickAction
);
autoPage
.
Actions
.
Add
(
clickAction
);
#
endregion
#
endregion
#
region
第三步从界面上取一些值
#
region
第三步从界面上取一些值
var
outputAction
=
new
OutputAction
();
var
outputAction
=
new
OutputAction
();
outputAction
.
Name
=
"取当前城市"
;
outputAction
.
Name
=
"取当前城市"
;
//使用XPath
//使用XPath
outputAction
.
ElementFinder
=
new
ElementFinder
(
"/html/body/div[3]/div[3]/div[1]/div[3]/div[1]/div/div/div[1]/div/div[1]/div[2]/div[1]/div[1]/div/div[1]"
);
outputAction
.
ElementFinder
=
new
ElementFinder
(
"/html/body/div[3]/div[3]/div[1]/div[3]/div[1]/div/div/div[1]/div/div[1]/div[2]/div[1]/div[1]/div/div[1]"
);
outputAction
.
Attributes
.
Add
(
"innerText"
,
"所在城市"
);
outputAction
.
Attributes
.
Add
(
"innerText"
,
"所在城市"
);
baidu
.
Actions
.
Add
(
outputAction
);
autoPage
.
Actions
.
Add
(
outputAction
);
#
endregion
#
endregion
#
region
第四步从界面上取天气
#
region
第四步从界面上取天气
var
outputAction2
=
new
OutputAction
();
var
outputAction2
=
new
OutputAction
();
outputAction2
.
Name
=
"取天气"
;
outputAction2
.
Name
=
"取天气"
;
//使用XPath
//使用XPath
outputAction2
.
ElementFinder
=
new
ElementFinder
(
".weather-main-temp_6CEpK > span:nth-child(1)"
,
"css"
);
outputAction2
.
ElementFinder
=
new
ElementFinder
(
".weather-main-temp_6CEpK > span:nth-child(1)"
,
"css"
);
outputAction2
.
Attributes
.
Add
(
"innerText"
,
"天气"
);
outputAction2
.
Attributes
.
Add
(
"innerText"
,
"天气"
);
baidu
.
Actions
.
Add
(
outputAction2
);
autoPage
.
Actions
.
Add
(
outputAction2
);
#
endregion
#
endregion
#
region
第五步:测试下本地
Action
#
region
第五步:测试下本地
Action
...
@@ -347,11 +393,37 @@ namespace Kivii.Test.WebDriver
...
@@ -347,11 +393,37 @@ namespace Kivii.Test.WebDriver
jsAction
.
Name
=
"测试JS返回"
;
jsAction
.
Name
=
"测试JS返回"
;
//使用XPath
//使用XPath
jsAction
.
Js
=
"return '测试JS返回';"
;
jsAction
.
Js
=
"return '测试JS返回';"
;
baidu
.
Actions
.
Add
(
jsAction
);
autoPage
.
Actions
.
Add
(
jsAction
);
var
json
=
autoPage
.
ExportActions
(
true
);
rtbActionsJson
.
Text
=
json
;
#
endregion
}
/// <summary>
/// 将Actions的JSON代码加载进WebPage中执行,URL的起始页使用界面上的tbxUrl中的值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnActionsJson_Click
(
object
sender
,
EventArgs
e
)
{
if
(
_manager
==
null
)
return
;
_manager
.
Maximize
();
//最大化网页
var
autoPage
=
new
WebPage
(
_manager
);
autoPage
.
Url
=
tbxUrl
.
Text
;
//生成DEMO时不需要
autoPage
.
ImportActions
(
rtbActionsJson
.
Text
);
var
rtns
=
autoPage
.
Execute
();
appendMsg
(
$"执行结果:
{
Environment
.
NewLine
}{
rtns
}
"
);
}
#
endregion
#
endregion
var
result
=
baidu
.
Execute
();
appendMsg
(
$"执行结果:
{
Environment
.
NewLine
}{
result
}
"
);
private
void
btnShowActionsTip_Click
(
object
sender
,
EventArgs
e
)
{
foreach
(
var
actionAttribute
in
ActionBase
.
GetActionAttributes
())
{
appendMsg
(
$"
{
actionAttribute
.
Type
.
FullName
}{
Environment
.
NewLine
}
别名:\"
{
actionAttribute
.
Alias
}
\" 描述:
{
actionAttribute
.
Description
}
"
);
}
}
}
}
}
#
region
注入的对象
#
region
注入的对象
...
...
Kivii.Test.WebDriver.csproj
View file @
12b38543
...
@@ -35,8 +35,8 @@
...
@@ -35,8 +35,8 @@
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"Kivii.WebDriver.V4.7, Version=4.15.2023.110
1
0, Culture=neutral, processorArchitecture=MSIL"
>
<Reference
Include=
"Kivii.WebDriver.V4.7, Version=4.15.2023.110
2
0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
packages\Kivii.WebDriver.4.15.2023.110
1
0\lib\net47\Kivii.WebDriver.V4.7.dll
</HintPath>
<HintPath>
packages\Kivii.WebDriver.4.15.2023.110
2
0\lib\net47\Kivii.WebDriver.V4.7.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
>
<Reference
Include=
"Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
>
<HintPath>
packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
</HintPath>
<HintPath>
packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
</HintPath>
...
...
Properties/AssemblyInfo.cs
View file @
12b38543
using
System.Reflection
;
using
Kivii.WebDriver.Actions
;
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
...
@@ -13,7 +14,7 @@ using System.Runtime.InteropServices;
...
@@ -13,7 +14,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyCulture("")]
[assembly:AssemblyContainsAction]
// 将 ComVisible 设置为 false 会使此程序集中的类型
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
//请将此类型的 ComVisible 特性设置为 true。
...
...
packages.config
View file @
12b38543
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"Kivii.WebDriver"
version
=
"4.15.2023.110
1
0"
targetFramework
=
"net472"
/>
<
package
id
=
"Kivii.WebDriver"
version
=
"4.15.2023.110
2
0"
targetFramework
=
"net472"
/>
<
package
id
=
"Newtonsoft.Json"
version
=
"13.0.1"
targetFramework
=
"net472"
/>
<
package
id
=
"Newtonsoft.Json"
version
=
"13.0.1"
targetFramework
=
"net472"
/>
<
package
id
=
"Selenium.Support"
version
=
"4.15.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Selenium.Support"
version
=
"4.15.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Selenium.WebDriver"
version
=
"4.15.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Selenium.WebDriver"
version
=
"4.15.0"
targetFramework
=
"net472"
/>
...
...
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