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
b6fef2b9
Commit
b6fef2b9
authored
Nov 07, 2023
by
施晓雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新示例代码
parent
12b38543
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
215 additions
and
48 deletions
+215
-48
FrmMain.Designer.cs
FrmMain.Designer.cs
+16
-2
FrmMain.cs
FrmMain.cs
+14
-43
Kivii.Test.WebDriver.csproj
Kivii.Test.WebDriver.csproj
+4
-2
MouseTest.cs
Tests/MouseTest.cs
+110
-0
WeatherTest.cs
Tests/WeatherTest.cs
+70
-0
packages.config
packages.config
+1
-1
No files found.
FrmMain.Designer.cs
View file @
b6fef2b9
...
@@ -72,6 +72,7 @@
...
@@ -72,6 +72,7 @@
this
.
panel4
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
panel4
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
btnActionsDemo
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnActionsDemo
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnActionsJson
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnActionsJson
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnMouseDemo
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnShowActionsTip
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnShowActionsTip
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
groupBox1
.
SuspendLayout
();
this
.
groupBox1
.
SuspendLayout
();
this
.
panel2
.
SuspendLayout
();
this
.
panel2
.
SuspendLayout
();
...
@@ -554,6 +555,7 @@
...
@@ -554,6 +555,7 @@
// panel4
// panel4
//
//
this
.
panel4
.
Controls
.
Add
(
this
.
btnShowActionsTip
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnShowActionsTip
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnMouseDemo
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnActionsDemo
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnActionsDemo
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnActionsJson
);
this
.
panel4
.
Controls
.
Add
(
this
.
btnActionsJson
);
this
.
panel4
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
this
.
panel4
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Bottom
;
...
@@ -584,13 +586,24 @@
...
@@ -584,13 +586,24 @@
this
.
btnActionsJson
.
UseVisualStyleBackColor
=
true
;
this
.
btnActionsJson
.
UseVisualStyleBackColor
=
true
;
this
.
btnActionsJson
.
Click
+=
new
System
.
EventHandler
(
this
.
btnActionsJson_Click
);
this
.
btnActionsJson
.
Click
+=
new
System
.
EventHandler
(
this
.
btnActionsJson_Click
);
//
//
// btnMouseDemo
//
this
.
btnMouseDemo
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
btnMouseDemo
.
Location
=
new
System
.
Drawing
.
Point
(
72
,
0
);
this
.
btnMouseDemo
.
Name
=
"btnMouseDemo"
;
this
.
btnMouseDemo
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
20
);
this
.
btnMouseDemo
.
TabIndex
=
15
;
this
.
btnMouseDemo
.
Text
=
"鼠标示例"
;
this
.
btnMouseDemo
.
UseVisualStyleBackColor
=
true
;
this
.
btnMouseDemo
.
Click
+=
new
System
.
EventHandler
(
this
.
btnMouseDemo_Click
);
//
// btnShowActionsTip
// btnShowActionsTip
//
//
this
.
btnShowActionsTip
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
btnShowActionsTip
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Left
;
this
.
btnShowActionsTip
.
Location
=
new
System
.
Drawing
.
Point
(
72
,
0
);
this
.
btnShowActionsTip
.
Location
=
new
System
.
Drawing
.
Point
(
144
,
0
);
this
.
btnShowActionsTip
.
Name
=
"btnShowActionsTip"
;
this
.
btnShowActionsTip
.
Name
=
"btnShowActionsTip"
;
this
.
btnShowActionsTip
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
20
);
this
.
btnShowActionsTip
.
Size
=
new
System
.
Drawing
.
Size
(
72
,
20
);
this
.
btnShowActionsTip
.
TabIndex
=
1
4
;
this
.
btnShowActionsTip
.
TabIndex
=
1
6
;
this
.
btnShowActionsTip
.
Text
=
"显示动作类型"
;
this
.
btnShowActionsTip
.
Text
=
"显示动作类型"
;
this
.
btnShowActionsTip
.
UseVisualStyleBackColor
=
true
;
this
.
btnShowActionsTip
.
UseVisualStyleBackColor
=
true
;
this
.
btnShowActionsTip
.
Click
+=
new
System
.
EventHandler
(
this
.
btnShowActionsTip_Click
);
this
.
btnShowActionsTip
.
Click
+=
new
System
.
EventHandler
(
this
.
btnShowActionsTip_Click
);
...
@@ -669,6 +682,7 @@
...
@@ -669,6 +682,7 @@
private
System
.
Windows
.
Forms
.
Panel
panel4
;
private
System
.
Windows
.
Forms
.
Panel
panel4
;
private
System
.
Windows
.
Forms
.
Button
btnActionsJson
;
private
System
.
Windows
.
Forms
.
Button
btnActionsJson
;
private
System
.
Windows
.
Forms
.
Button
btnActionsDemo
;
private
System
.
Windows
.
Forms
.
Button
btnActionsDemo
;
private
System
.
Windows
.
Forms
.
Button
btnMouseDemo
;
private
System
.
Windows
.
Forms
.
Button
btnShowActionsTip
;
private
System
.
Windows
.
Forms
.
Button
btnShowActionsTip
;
}
}
}
}
...
...
FrmMain.cs
View file @
b6fef2b9
using
Kivii.WebDriver
;
using
Kivii.Test.WebDriver.Tests
;
using
Kivii.WebDriver
;
using
Kivii.WebDriver.Actions
;
using
Kivii.WebDriver.Actions
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
using
OpenQA.Selenium.Firefox
;
using
OpenQA.Selenium.Firefox
;
...
@@ -353,50 +354,9 @@ namespace Kivii.Test.WebDriver
...
@@ -353,50 +354,9 @@ namespace Kivii.Test.WebDriver
/// <param name="e"></param>
/// <param name="e"></param>
private
void
btnActionsDemo_Click
(
object
sender
,
EventArgs
e
)
private
void
btnActionsDemo_Click
(
object
sender
,
EventArgs
e
)
{
{
var
autoPage
=
new
WebPage
(
null
);
var
autoPage
=
WeatherTest
.
Get
();
//autoPage.Url = "https://www.baidu.com";//生成DEMO时不需要
#
region
第一步,在输入框内输入内容
var
inputAction
=
new
InputAction
();
inputAction
.
Name
=
"输入查询内容"
;
inputAction
.
InputValue
=
"最近天气"
;
inputAction
.
ElementFinder
=
new
ElementFinder
(
"kw"
,
"id"
);
autoPage
.
Actions
.
Add
(
inputAction
);
#
endregion
#
region
第二步点击百度一下查询按键
var
clickAction
=
new
ClickAction
();
clickAction
.
Name
=
"百度一下"
;
clickAction
.
ElementFinder
=
new
ElementFinder
(
"su"
,
"id"
);
autoPage
.
Actions
.
Add
(
clickAction
);
#
endregion
#
region
第三步从界面上取一些值
var
outputAction
=
new
OutputAction
();
outputAction
.
Name
=
"取当前城市"
;
//使用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
.
Attributes
.
Add
(
"innerText"
,
"所在城市"
);
autoPage
.
Actions
.
Add
(
outputAction
);
#
endregion
#
region
第四步从界面上取天气
var
outputAction2
=
new
OutputAction
();
outputAction2
.
Name
=
"取天气"
;
//使用XPath
outputAction2
.
ElementFinder
=
new
ElementFinder
(
".weather-main-temp_6CEpK > span:nth-child(1)"
,
"css"
);
outputAction2
.
Attributes
.
Add
(
"innerText"
,
"天气"
);
autoPage
.
Actions
.
Add
(
outputAction2
);
#
endregion
#
region
第五步:测试下本地
Action
var
jsAction
=
new
MyJsAction
();
jsAction
.
Name
=
"测试JS返回"
;
//使用XPath
jsAction
.
Js
=
"return '测试JS返回';"
;
autoPage
.
Actions
.
Add
(
jsAction
);
var
json
=
autoPage
.
ExportActions
(
true
);
var
json
=
autoPage
.
ExportActions
(
true
);
rtbActionsJson
.
Text
=
json
;
rtbActionsJson
.
Text
=
json
;
#
endregion
}
}
/// <summary>
/// <summary>
/// 将Actions的JSON代码加载进WebPage中执行,URL的起始页使用界面上的tbxUrl中的值
/// 将Actions的JSON代码加载进WebPage中执行,URL的起始页使用界面上的tbxUrl中的值
...
@@ -425,6 +385,17 @@ namespace Kivii.Test.WebDriver
...
@@ -425,6 +385,17 @@ namespace Kivii.Test.WebDriver
appendMsg
(
$"
{
actionAttribute
.
Type
.
FullName
}{
Environment
.
NewLine
}
别名:\"
{
actionAttribute
.
Alias
}
\" 描述:
{
actionAttribute
.
Description
}
"
);
appendMsg
(
$"
{
actionAttribute
.
Type
.
FullName
}{
Environment
.
NewLine
}
别名:\"
{
actionAttribute
.
Alias
}
\" 描述:
{
actionAttribute
.
Description
}
"
);
}
}
}
}
/// <summary>
/// 鼠标动作示例
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
btnMouseDemo_Click
(
object
sender
,
EventArgs
e
)
{
var
autoPage
=
MouseTest
.
Get
();
var
json
=
autoPage
.
ExportActions
(
true
);
rtbActionsJson
.
Text
=
json
;
}
}
}
#
region
注入的对象
#
region
注入的对象
internal
class
InjectionTest
internal
class
InjectionTest
...
...
Kivii.Test.WebDriver.csproj
View file @
b6fef2b9
...
@@ -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
2
0, Culture=neutral, processorArchitecture=MSIL"
>
<Reference
Include=
"Kivii.WebDriver.V4.7, Version=4.15.2023.110
3
0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
packages\Kivii.WebDriver.4.15.2023.110
2
0\lib\net47\Kivii.WebDriver.V4.7.dll
</HintPath>
<HintPath>
packages\Kivii.WebDriver.4.15.2023.110
3
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>
...
@@ -68,6 +68,8 @@
...
@@ -68,6 +68,8 @@
</Compile>
</Compile>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Tests\MouseTest.cs"
/>
<Compile
Include=
"Tests\WeatherTest.cs"
/>
<EmbeddedResource
Include=
"FrmMain.resx"
>
<EmbeddedResource
Include=
"FrmMain.resx"
>
<DependentUpon>
FrmMain.cs
</DependentUpon>
<DependentUpon>
FrmMain.cs
</DependentUpon>
</EmbeddedResource>
</EmbeddedResource>
...
...
Tests/MouseTest.cs
0 → 100644
View file @
b6fef2b9
using
Kivii.WebDriver
;
using
Kivii.WebDriver.Actions
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Kivii.Test.WebDriver.Tests
{
internal
class
MouseTest
{
public
static
WebPage
Get
()
{
var
rtns
=
new
WebPage
(
null
);
//rtns.Url = "https://www.baidu.com";//这个配置可通过NavigateAction进行
#
region
打开网站,放在
Action
中执行了,不需要设
autoPage
.
Url
了
{
var
action
=
new
NavigateAction
();
action
.
Name
=
"跳转网站"
;
action
.
Url
=
"http://www.cacs.mofcom.gov.cn/cacscms/view/notice/zhtbomrasff#"
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
暂停
2
秒
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Pause
;
action
.
DurationMilliseconds
=
2000
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
移动鼠标至第
1
个元素上点击
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Click
;
action
.
Target
=
new
ElementFinder
(
"//*[@id=\"zhtbomrasff\"]"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
暂停
2
秒
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Pause
;
action
.
DurationMilliseconds
=
2000
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
移动鼠标至第
2
个元素上点击
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Click
;
action
.
Target
=
new
ElementFinder
(
"//*[@id=\"zhtbomrapex\"]"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
暂停
2
秒
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Pause
;
action
.
DurationMilliseconds
=
2000
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
移动鼠标至第
3
个元素上点击
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Click
;
action
.
Target
=
new
ElementFinder
(
"//*[@id=\"zhtbmg\"]"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
暂停
2
秒
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Pause
;
action
.
DurationMilliseconds
=
2000
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
移动鼠标至第
1
个元素上
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Click
;
action
.
Target
=
new
ElementFinder
(
"//*[@id=\"zhtbomrasff\"]"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
执行最后的执行动作,一定要有,不然不执行
{
var
action
=
new
MouseAction
();
action
.
Type
=
MouseActionType
.
Perform
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
return
rtns
;
}
}
}
Tests/WeatherTest.cs
0 → 100644
View file @
b6fef2b9
using
Kivii.WebDriver
;
using
Kivii.WebDriver.Actions
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Kivii.Test.WebDriver.Tests
{
internal
class
WeatherTest
{
public
static
WebPage
Get
()
{
var
rtns
=
new
WebPage
(
null
);
//autoPage.Url = "https://www.baidu.com";//生成DEMO时不需要
#
region
第一步,在输入框内输入内容
{
var
action
=
new
InputAction
();
action
.
Name
=
"输入查询内容"
;
action
.
InputValue
=
"最近天气"
;
action
.
ElementFinder
=
new
ElementFinder
(
"kw"
,
"id"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
第二步点击百度一下查询按键
{
var
action
=
new
ClickAction
();
action
.
Name
=
"百度一下"
;
action
.
ElementFinder
=
new
ElementFinder
(
"su"
,
"id"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
第三步从界面上取一些值
{
var
action
=
new
OutputAction
();
action
.
Name
=
"取当前城市"
;
//使用XPath
action
.
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]"
);
action
.
Attributes
.
Add
(
"innerText"
,
"所在城市"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
第四步从界面上取天气
{
var
action
=
new
OutputAction
();
action
.
Name
=
"取天气"
;
//使用XPath
action
.
ElementFinder
=
new
ElementFinder
(
".weather-main-temp_6CEpK > span:nth-child(1)"
,
"css"
);
action
.
Attributes
.
Add
(
"innerText"
,
"天气"
);
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
#
region
第五步:测试下本地
Action
{
var
action
=
new
MyJsAction
();
action
.
Name
=
"测试JS返回"
;
//使用XPath
action
.
Js
=
"return '测试JS返回';"
;
rtns
.
Actions
.
Add
(
action
);
}
#
endregion
return
rtns
;
}
}
}
packages.config
View file @
b6fef2b9
<?
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
2
0"
targetFramework
=
"net472"
/>
<
package
id
=
"Kivii.WebDriver"
version
=
"4.15.2023.110
3
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