Commit a4846853 by 施晓雨

更新示例

parent 42609465
......@@ -36,6 +36,7 @@
this.label3 = new System.Windows.Forms.Label();
this.cbxRemote = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.cbxHidenLocalCommandWindow = new System.Windows.Forms.CheckBox();
this.btnSwitchWindow = new System.Windows.Forms.Button();
this.panel5 = new System.Windows.Forms.Panel();
this.lblCurrenWindow = new System.Windows.Forms.Label();
......@@ -79,7 +80,7 @@
this.btnMouseDemo = new System.Windows.Forms.Button();
this.btnActionsDemo = new System.Windows.Forms.Button();
this.btnActionsJson = new System.Windows.Forms.Button();
this.cbxHidenLocalCommandWindow = new System.Windows.Forms.CheckBox();
this.btnMofcomTest = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.panel5.SuspendLayout();
this.panel2.SuspendLayout();
......@@ -193,6 +194,16 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "基础操作";
//
// cbxHidenLocalCommandWindow
//
this.cbxHidenLocalCommandWindow.AutoSize = true;
this.cbxHidenLocalCommandWindow.Location = new System.Drawing.Point(163, 53);
this.cbxHidenLocalCommandWindow.Name = "cbxHidenLocalCommandWindow";
this.cbxHidenLocalCommandWindow.Size = new System.Drawing.Size(84, 16);
this.cbxHidenLocalCommandWindow.TabIndex = 15;
this.cbxHidenLocalCommandWindow.Text = "隐藏命令行";
this.cbxHidenLocalCommandWindow.UseVisualStyleBackColor = true;
//
// btnSwitchWindow
//
this.btnSwitchWindow.Location = new System.Drawing.Point(238, 105);
......@@ -561,7 +572,7 @@
this.tpWebScript.Location = new System.Drawing.Point(4, 22);
this.tpWebScript.Name = "tpWebScript";
this.tpWebScript.Padding = new System.Windows.Forms.Padding(3);
this.tpWebScript.Size = new System.Drawing.Size(826, 237);
this.tpWebScript.Size = new System.Drawing.Size(820, 237);
this.tpWebScript.TabIndex = 1;
this.tpWebScript.Tag = "web";
this.tpWebScript.Text = "网页内执行";
......@@ -573,7 +584,7 @@
this.rtbWebScript.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtbWebScript.Location = new System.Drawing.Point(3, 3);
this.rtbWebScript.Name = "rtbWebScript";
this.rtbWebScript.Size = new System.Drawing.Size(820, 211);
this.rtbWebScript.Size = new System.Drawing.Size(814, 211);
this.rtbWebScript.TabIndex = 11;
this.rtbWebScript.Text = "";
//
......@@ -583,13 +594,13 @@
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(3, 214);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(820, 20);
this.panel1.Size = new System.Drawing.Size(814, 20);
this.panel1.TabIndex = 10;
//
// btnWindowExecuteScript
//
this.btnWindowExecuteScript.Dock = System.Windows.Forms.DockStyle.Right;
this.btnWindowExecuteScript.Location = new System.Drawing.Point(745, 0);
this.btnWindowExecuteScript.Location = new System.Drawing.Point(739, 0);
this.btnWindowExecuteScript.Name = "btnWindowExecuteScript";
this.btnWindowExecuteScript.Size = new System.Drawing.Size(75, 20);
this.btnWindowExecuteScript.TabIndex = 5;
......@@ -603,7 +614,7 @@
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.Size = new System.Drawing.Size(820, 237);
this.tpActionJson.TabIndex = 2;
this.tpActionJson.Text = "Action自动化测试";
this.tpActionJson.UseVisualStyleBackColor = true;
......@@ -614,12 +625,13 @@
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.Size = new System.Drawing.Size(820, 217);
this.rtbActionsJson.TabIndex = 13;
this.rtbActionsJson.Text = "";
//
// panel4
//
this.panel4.Controls.Add(this.btnMofcomTest);
this.panel4.Controls.Add(this.btnShowActionsTip);
this.panel4.Controls.Add(this.btnMouseDemo);
this.panel4.Controls.Add(this.btnActionsDemo);
......@@ -627,7 +639,7 @@
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.Size = new System.Drawing.Size(820, 20);
this.panel4.TabIndex = 12;
//
// btnShowActionsTip
......@@ -666,7 +678,7 @@
// btnActionsJson
//
this.btnActionsJson.Dock = System.Windows.Forms.DockStyle.Right;
this.btnActionsJson.Location = new System.Drawing.Point(751, 0);
this.btnActionsJson.Location = new System.Drawing.Point(745, 0);
this.btnActionsJson.Name = "btnActionsJson";
this.btnActionsJson.Size = new System.Drawing.Size(75, 20);
this.btnActionsJson.TabIndex = 5;
......@@ -674,17 +686,16 @@
this.btnActionsJson.UseVisualStyleBackColor = true;
this.btnActionsJson.Click += new System.EventHandler(this.btnActionsJson_Click);
//
// cbxHidenLocalCommandWindow
// btnMofcomTest
//
this.cbxHidenLocalCommandWindow.AutoSize = true;
this.cbxHidenLocalCommandWindow.Checked = true;
this.cbxHidenLocalCommandWindow.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbxHidenLocalCommandWindow.Location = new System.Drawing.Point(163, 53);
this.cbxHidenLocalCommandWindow.Name = "cbxHidenLocalCommandWindow";
this.cbxHidenLocalCommandWindow.Size = new System.Drawing.Size(84, 16);
this.cbxHidenLocalCommandWindow.TabIndex = 15;
this.cbxHidenLocalCommandWindow.Text = "隐藏命令行";
this.cbxHidenLocalCommandWindow.UseVisualStyleBackColor = true;
this.btnMofcomTest.Dock = System.Windows.Forms.DockStyle.Left;
this.btnMofcomTest.Location = new System.Drawing.Point(216, 0);
this.btnMofcomTest.Name = "btnMofcomTest";
this.btnMofcomTest.Size = new System.Drawing.Size(72, 20);
this.btnMofcomTest.TabIndex = 17;
this.btnMofcomTest.Text = "Mofcom";
this.btnMofcomTest.UseVisualStyleBackColor = true;
this.btnMofcomTest.Click += new System.EventHandler(this.btnMofcomTest_Click);
//
// FrmMain
//
......@@ -769,6 +780,7 @@
private System.Windows.Forms.ComboBox cbWindows;
private System.Windows.Forms.Button btnSwitchWindow;
private System.Windows.Forms.CheckBox cbxHidenLocalCommandWindow;
private System.Windows.Forms.Button btnMofcomTest;
}
}
......@@ -295,7 +295,7 @@ namespace Kivii.Test.WebDriver
/// <param name="e"></param>
private void btnNavigate_Click(object sender, EventArgs e)
{
_manager?.CurrentWindow.NavigateTo(tbxUrl.Text);
_manager?.CurrentWindow.GoTo(tbxUrl.Text);
}
/// <summary>
......@@ -341,9 +341,9 @@ namespace Kivii.Test.WebDriver
/// <param name="e"></param>
private void btnShowActionsTip_Click(object sender, EventArgs e)
{
foreach (var actionAttribute in ActionBase.GetActionAttributes())
foreach (var actionAttribute in ActionBase.AllActions())
{
appendMsg($"{actionAttribute.Type.FullName}{Environment.NewLine}别名:\"{actionAttribute.Alias}\" 描述:{actionAttribute.Description}");
appendMsg($"{actionAttribute.Type.FullName}{Environment.NewLine}别名:\"{actionAttribute.Alias}\" 名称:{actionAttribute.Name}{Environment.NewLine}描述:{actionAttribute.Description}");
}
}
private void cbWindows_Enter(object sender, EventArgs e)
......@@ -408,11 +408,9 @@ namespace Kivii.Test.WebDriver
private void btnActionsJson_Click(object sender, EventArgs e)
{
if (_manager == null) return;
_manager.Maximize();//最大化网页
var window = new Window(_manager);
window.ImportActions(rtbActionsJson.Text);
var rtns=window.ExecuteActions();
_manager.CurrentWindow.ImportActions(rtbActionsJson.Text);
var rtns = _manager.CurrentWindow.ExecuteActions();
appendMsg($"执行结果:{Environment.NewLine}{rtns}");
}
......@@ -427,8 +425,8 @@ namespace Kivii.Test.WebDriver
/// <param name="e"></param>
private void btnActionsDemo_Click(object sender, EventArgs e)
{
var autoPage = WeatherTest.Get();
var json = autoPage.ExportActions(true);
var actions = WeatherTest.GetActions();
var json = actions.ExportActions(true);
rtbActionsJson.Text = json;
}
/// <summary>
......@@ -442,6 +440,12 @@ namespace Kivii.Test.WebDriver
var json = autoPage.ExportActions(true);
rtbActionsJson.Text = json;
}
private void btnMofcomTest_Click(object sender, EventArgs e)
{
var autoPage = MofcomTest.Get();
var json = autoPage.ExportActions(true);
rtbActionsJson.Text = json;
}
......
......@@ -35,8 +35,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Kivii.WebDriver.V4.7, Version=4.15.2023.11040, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.WebDriver.4.15.2023.11040\lib\net47\Kivii.WebDriver.V4.7.dll</HintPath>
<Reference Include="Kivii.WebDriver.V4.7, Version=4.15.2023.11050, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.WebDriver.4.15.2023.11050\lib\net47\Kivii.WebDriver.V4.7.dll</HintPath>
</Reference>
<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>
......@@ -68,6 +68,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\MofcomTest.cs" />
<Compile Include="Tests\MouseTest.cs" />
<Compile Include="Tests\ReferenceTest.cs" />
<Compile Include="Tests\WeatherTest.cs" />
......
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 MofcomTest
{
public static Window Get()
{
var rtns = new Window(null);
#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 SleepAction();
action.PauseMilliseconds = 2000;
rtns.Actions.Add(action);
}
#endregion
#region 移动鼠标至第1个元素上点击
{
var action = new ClickAction();
action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]");
rtns.Actions.Add(action);
}
#endregion
#region 暂停2
{
var action = new SleepAction();
action.Name = "准备抓取网页";
action.PauseMilliseconds = 2000;
rtns.Actions.Add(action);
}
#endregion
#region 抓取内容
{
var action = new JavascriptAction();
action.Script="return '抓取当前页内容'";
rtns.Actions.Add(action);
}
#endregion
#region 点击下一页
{
var action = new ClickAction();
action.Target = new ElementFinder()
{
Type = ElementFindType.LinkText,
Selector = "下一页"
};
rtns.Actions.Add(action);
}
#endregion
#region 循环10
{
var action = new LoopAction();
action.LoopTimes =10;
action.FromName = "准备抓取网页";
rtns.Actions.Add(action);
}
#endregion
return rtns;
}
}
}
......@@ -21,7 +21,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new NavigateAction();
action.Name = "跳转网站";
action.Url = "http://www.cacs.mofcom.gov.cn/cacscms/view/notice/zhtbomrasff#";
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -29,8 +29,8 @@ namespace Kivii.Test.WebDriver.Tests
{
var action = new MouseAction();
action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000;
rtns.AddAction(action);
action.PauseMilliseconds = 2000;
rtns.Actions.Add(action);
}
#endregion
......@@ -39,7 +39,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction();
action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -47,8 +47,8 @@ namespace Kivii.Test.WebDriver.Tests
{
var action = new MouseAction();
action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000;
rtns.AddAction(action);
action.PauseMilliseconds = 2000;
rtns.Actions.Add(action);
}
#endregion
......@@ -57,7 +57,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction();
action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbomrapex\"]");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -65,8 +65,8 @@ namespace Kivii.Test.WebDriver.Tests
{
var action = new MouseAction();
action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000;
rtns.AddAction(action);
action.PauseMilliseconds = 2000;
rtns.Actions.Add(action);
}
#endregion
......@@ -75,7 +75,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction();
action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbmg\"]");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -83,8 +83,8 @@ namespace Kivii.Test.WebDriver.Tests
{
var action = new MouseAction();
action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000;
rtns.AddAction(action);
action.PauseMilliseconds = 2000;
rtns.Actions.Add(action);
}
#endregion
......@@ -93,7 +93,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction();
action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -101,7 +101,7 @@ namespace Kivii.Test.WebDriver.Tests
{
var action = new MouseAction();
action.Type = MouseActionType.Perform;
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
return rtns;
......
......@@ -10,17 +10,25 @@ namespace Kivii.Test.WebDriver.Tests
{
internal class WeatherTest
{
public static Window Get()
public static Window GetActions()
{
var rtns = new Window(null);
//autoPage.Url = "https://www.baidu.com";//生成DEMO时不需要
#region 导航到Baidu
{
var action = new NavigateAction();
action.Url = "https://www.baidu.com";
rtns.Actions.Add(action);
}
#endregion
#region 第一步,在输入框内输入内容
{
var action = new InputAction();
action.Name = "输入查询内容";
action.InputValue = "最近天气";
action.Target = new ElementFinder("kw", "id");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -29,7 +37,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new ClickAction();
action.Name = "百度一下";
action.Target = new ElementFinder("su", "id");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -40,7 +48,7 @@ namespace Kivii.Test.WebDriver.Tests
//使用XPath
action.Target = 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.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -51,7 +59,7 @@ namespace Kivii.Test.WebDriver.Tests
//使用XPath
action.Target = new ElementFinder(".weather-main-temp_6CEpK > span:nth-child(1)", "css");
action.Attributes.Add("innerText", "天气");
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
......@@ -61,7 +69,7 @@ namespace Kivii.Test.WebDriver.Tests
action.Name = "测试JS返回";
//使用XPath
action.Js = "return '测试JS返回';";
rtns.AddAction(action);
rtns.Actions.Add(action);
}
#endregion
return rtns;
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Kivii.WebDriver" version="4.15.2023.11040" targetFramework="net472" />
<package id="Kivii.WebDriver" version="4.15.2023.11050" 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.WebDriver" version="4.15.0" targetFramework="net472" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment