Commit 42609465 by 施晓雨

更新代码示例

parent b6fef2b9
...@@ -12,11 +12,11 @@ namespace Kivii.Test.WebDriver ...@@ -12,11 +12,11 @@ namespace Kivii.Test.WebDriver
internal class MyJsAction:ActionBase internal class MyJsAction:ActionBase
{ {
public string Js { get; set; } public string Js { get; set; }
public override string Execute(Manager manager) public override string Execute(Window window)
{ {
try try
{ {
var value=manager.ExecuteScript(Js); var value=window.ExecuteScript(Js);
return value; return value;
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -28,21 +28,26 @@ ...@@ -28,21 +28,26 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.btnOpen = new System.Windows.Forms.Button(); this.btnInitialize = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button(); this.btnDispose = new System.Windows.Forms.Button();
this.cbxBrowserType = new System.Windows.Forms.ComboBox(); this.cbxBrowserType = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.btnScreenshot = new System.Windows.Forms.Button(); this.btnScreenshot = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.cbxRemote = new System.Windows.Forms.CheckBox(); this.cbxRemote = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnSwitchWindow = new System.Windows.Forms.Button();
this.panel5 = new System.Windows.Forms.Panel();
this.lblCurrenWindow = new System.Windows.Forms.Label();
this.btnCloseCurrentWindow = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.cbWindows = new System.Windows.Forms.ComboBox();
this.cbUseHub = new System.Windows.Forms.CheckBox(); this.cbUseHub = new System.Windows.Forms.CheckBox();
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.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnInjection = new System.Windows.Forms.Button(); this.btnSetReference = new System.Windows.Forms.Button();
this.btnHandlers = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
...@@ -59,22 +64,24 @@ ...@@ -59,22 +64,24 @@
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.pnlEngineToolBar = 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.btnAutoAppendScript = new System.Windows.Forms.Button();
this.btnManagerExecuteScript = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
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.btnExecuteScript = new System.Windows.Forms.Button(); this.btnWindowExecuteScript = new System.Windows.Forms.Button();
this.tpActionJson = new System.Windows.Forms.TabPage(); this.tpActionJson = new System.Windows.Forms.TabPage();
this.rtbActionsJson = new System.Windows.Forms.RichTextBox(); this.rtbActionsJson = new System.Windows.Forms.RichTextBox();
this.panel4 = new System.Windows.Forms.Panel(); this.panel4 = new System.Windows.Forms.Panel();
this.btnShowActionsTip = new System.Windows.Forms.Button();
this.btnMouseDemo = new System.Windows.Forms.Button();
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.cbxHidenLocalCommandWindow = new System.Windows.Forms.CheckBox();
this.btnShowActionsTip = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.panel5.SuspendLayout();
this.panel2.SuspendLayout(); this.panel2.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.panel3.SuspendLayout(); this.panel3.SuspendLayout();
...@@ -89,25 +96,25 @@ ...@@ -89,25 +96,25 @@
this.panel4.SuspendLayout(); this.panel4.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// btnOpen // btnInitialize
// //
this.btnOpen.Location = new System.Drawing.Point(8, 91); this.btnInitialize.Location = new System.Drawing.Point(6, 79);
this.btnOpen.Name = "btnOpen"; this.btnInitialize.Name = "btnInitialize";
this.btnOpen.Size = new System.Drawing.Size(75, 23); this.btnInitialize.Size = new System.Drawing.Size(53, 23);
this.btnOpen.TabIndex = 0; this.btnInitialize.TabIndex = 0;
this.btnOpen.Text = "启动"; this.btnInitialize.Text = "启动";
this.btnOpen.UseVisualStyleBackColor = true; this.btnInitialize.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click); this.btnInitialize.Click += new System.EventHandler(this.btnInitialize_Click);
// //
// btnClose // btnDispose
// //
this.btnClose.Location = new System.Drawing.Point(103, 91); this.btnDispose.Location = new System.Drawing.Point(73, 79);
this.btnClose.Name = "btnClose"; this.btnDispose.Name = "btnDispose";
this.btnClose.Size = new System.Drawing.Size(75, 23); this.btnDispose.Size = new System.Drawing.Size(54, 23);
this.btnClose.TabIndex = 0; this.btnDispose.TabIndex = 0;
this.btnClose.Text = "关闭"; this.btnDispose.Text = "销毁";
this.btnClose.UseVisualStyleBackColor = true; this.btnDispose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click); this.btnDispose.Click += new System.EventHandler(this.btnDispose_Click);
// //
// cbxBrowserType // cbxBrowserType
// //
...@@ -126,7 +133,7 @@ ...@@ -126,7 +133,7 @@
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 28); this.label2.Location = new System.Drawing.Point(1, 28);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 12); this.label2.Size = new System.Drawing.Size(59, 12);
this.label2.TabIndex = 1; this.label2.TabIndex = 1;
...@@ -134,9 +141,9 @@ ...@@ -134,9 +141,9 @@
// //
// btnScreenshot // btnScreenshot
// //
this.btnScreenshot.Location = new System.Drawing.Point(194, 91); this.btnScreenshot.Location = new System.Drawing.Point(133, 79);
this.btnScreenshot.Name = "btnScreenshot"; this.btnScreenshot.Name = "btnScreenshot";
this.btnScreenshot.Size = new System.Drawing.Size(75, 23); this.btnScreenshot.Size = new System.Drawing.Size(55, 23);
this.btnScreenshot.TabIndex = 0; this.btnScreenshot.TabIndex = 0;
this.btnScreenshot.Text = "截图"; this.btnScreenshot.Text = "截图";
this.btnScreenshot.UseVisualStyleBackColor = true; this.btnScreenshot.UseVisualStyleBackColor = true;
...@@ -145,7 +152,7 @@ ...@@ -145,7 +152,7 @@
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 57); this.label3.Location = new System.Drawing.Point(1, 57);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(59, 12); this.label3.Size = new System.Drawing.Size(59, 12);
this.label3.TabIndex = 1; this.label3.TabIndex = 1;
...@@ -164,28 +171,92 @@ ...@@ -164,28 +171,92 @@
// //
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.cbxHidenLocalCommandWindow);
this.groupBox1.Controls.Add(this.btnSwitchWindow);
this.groupBox1.Controls.Add(this.panel5);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.cbWindows);
this.groupBox1.Controls.Add(this.cbUseHub); this.groupBox1.Controls.Add(this.cbUseHub);
this.groupBox1.Controls.Add(this.lnkVncUrl); this.groupBox1.Controls.Add(this.lnkVncUrl);
this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.btnOpen); this.groupBox1.Controls.Add(this.btnInitialize);
this.groupBox1.Controls.Add(this.cbxRemote); this.groupBox1.Controls.Add(this.cbxRemote);
this.groupBox1.Controls.Add(this.btnClose); this.groupBox1.Controls.Add(this.btnDispose);
this.groupBox1.Controls.Add(this.btnScreenshot); this.groupBox1.Controls.Add(this.btnScreenshot);
this.groupBox1.Controls.Add(this.cbxBrowserType); this.groupBox1.Controls.Add(this.cbxBrowserType);
this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top; this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox1.Location = new System.Drawing.Point(0, 0); this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(287, 130); this.groupBox1.Size = new System.Drawing.Size(293, 184);
this.groupBox1.TabIndex = 8; this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "基础操作"; this.groupBox1.Text = "基础操作";
// //
// btnSwitchWindow
//
this.btnSwitchWindow.Location = new System.Drawing.Point(238, 105);
this.btnSwitchWindow.Name = "btnSwitchWindow";
this.btnSwitchWindow.Size = new System.Drawing.Size(49, 23);
this.btnSwitchWindow.TabIndex = 14;
this.btnSwitchWindow.Text = "打开";
this.btnSwitchWindow.UseVisualStyleBackColor = true;
this.btnSwitchWindow.Click += new System.EventHandler(this.btnSwitchWindow_Click);
//
// panel5
//
this.panel5.Controls.Add(this.lblCurrenWindow);
this.panel5.Controls.Add(this.btnCloseCurrentWindow);
this.panel5.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel5.Location = new System.Drawing.Point(3, 143);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(287, 38);
this.panel5.TabIndex = 13;
//
// lblCurrenWindow
//
this.lblCurrenWindow.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblCurrenWindow.Location = new System.Drawing.Point(0, 0);
this.lblCurrenWindow.Name = "lblCurrenWindow";
this.lblCurrenWindow.Size = new System.Drawing.Size(238, 38);
this.lblCurrenWindow.TabIndex = 10;
this.lblCurrenWindow.Text = "当前窗口";
//
// btnCloseCurrentWindow
//
this.btnCloseCurrentWindow.Dock = System.Windows.Forms.DockStyle.Right;
this.btnCloseCurrentWindow.Location = new System.Drawing.Point(238, 0);
this.btnCloseCurrentWindow.Name = "btnCloseCurrentWindow";
this.btnCloseCurrentWindow.Size = new System.Drawing.Size(49, 38);
this.btnCloseCurrentWindow.TabIndex = 9;
this.btnCloseCurrentWindow.Text = "关闭当前窗口";
this.btnCloseCurrentWindow.UseVisualStyleBackColor = true;
this.btnCloseCurrentWindow.Click += new System.EventHandler(this.btnCloseCurrentWindow_Click);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(1, 113);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(59, 12);
this.label7.TabIndex = 10;
this.label7.Text = "选择窗口:";
//
// cbWindows
//
this.cbWindows.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbWindows.FormattingEnabled = true;
this.cbWindows.Location = new System.Drawing.Point(72, 107);
this.cbWindows.Name = "cbWindows";
this.cbWindows.Size = new System.Drawing.Size(163, 20);
this.cbWindows.TabIndex = 11;
this.cbWindows.Enter += new System.EventHandler(this.cbWindows_Enter);
//
// cbUseHub // cbUseHub
// //
this.cbUseHub.AutoSize = true; this.cbUseHub.AutoSize = true;
this.cbUseHub.Enabled = false; this.cbUseHub.Enabled = false;
this.cbUseHub.Location = new System.Drawing.Point(217, 24); this.cbUseHub.Location = new System.Drawing.Point(208, 24);
this.cbUseHub.Name = "cbUseHub"; this.cbUseHub.Name = "cbUseHub";
this.cbUseHub.Size = new System.Drawing.Size(42, 16); this.cbUseHub.Size = new System.Drawing.Size(42, 16);
this.cbUseHub.TabIndex = 7; this.cbUseHub.TabIndex = 7;
...@@ -211,23 +282,22 @@ ...@@ -211,23 +282,22 @@
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, 632); this.panel2.Size = new System.Drawing.Size(293, 632);
this.panel2.TabIndex = 10; this.panel2.TabIndex = 10;
// //
// groupBox3 // groupBox3
// //
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, 331);
this.groupBox3.Name = "groupBox3"; this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(287, 136); this.groupBox3.Size = new System.Drawing.Size(293, 136);
this.groupBox3.TabIndex = 12; this.groupBox3.TabIndex = 12;
this.groupBox3.TabStop = false; this.groupBox3.TabStop = false;
this.groupBox3.Text = "自动化测试"; this.groupBox3.Text = "自动化测试";
// //
// groupBox2 // groupBox2
// //
this.groupBox2.Controls.Add(this.btnInjection); this.groupBox2.Controls.Add(this.btnSetReference);
this.groupBox2.Controls.Add(this.btnHandlers);
this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.label1);
...@@ -237,32 +307,22 @@ ...@@ -237,32 +307,22 @@
this.groupBox2.Controls.Add(this.tbxVarName); this.groupBox2.Controls.Add(this.tbxVarName);
this.groupBox2.Controls.Add(this.tbxScriptPath); this.groupBox2.Controls.Add(this.tbxScriptPath);
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Top; this.groupBox2.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox2.Location = new System.Drawing.Point(0, 130); this.groupBox2.Location = new System.Drawing.Point(0, 184);
this.groupBox2.Name = "groupBox2"; this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(287, 147); this.groupBox2.Size = new System.Drawing.Size(293, 147);
this.groupBox2.TabIndex = 10; this.groupBox2.TabIndex = 10;
this.groupBox2.TabStop = false; this.groupBox2.TabStop = false;
this.groupBox2.Text = "原生功能"; this.groupBox2.Text = "原生功能";
// //
// btnInjection // btnSetReference
//
this.btnInjection.Location = new System.Drawing.Point(228, 73);
this.btnInjection.Name = "btnInjection";
this.btnInjection.Size = new System.Drawing.Size(48, 23);
this.btnInjection.TabIndex = 12;
this.btnInjection.Text = "注入";
this.btnInjection.UseVisualStyleBackColor = true;
this.btnInjection.Click += new System.EventHandler(this.btnInjection_Click);
// //
// btnHandlers this.btnSetReference.Location = new System.Drawing.Point(228, 73);
// this.btnSetReference.Name = "btnSetReference";
this.btnHandlers.Location = new System.Drawing.Point(3, 101); this.btnSetReference.Size = new System.Drawing.Size(48, 23);
this.btnHandlers.Name = "btnHandlers"; this.btnSetReference.TabIndex = 12;
this.btnHandlers.Size = new System.Drawing.Size(72, 23); this.btnSetReference.Text = "注入";
this.btnHandlers.TabIndex = 4; this.btnSetReference.UseVisualStyleBackColor = true;
this.btnHandlers.Text = "输出窗口"; this.btnSetReference.Click += new System.EventHandler(this.btnSetReference_Click);
this.btnHandlers.UseVisualStyleBackColor = true;
this.btnHandlers.Click += new System.EventHandler(this.btnHandlers_Click);
// //
// label6 // label6
// //
...@@ -340,9 +400,9 @@ ...@@ -340,9 +400,9 @@
this.panel3.Controls.Add(this.gbMsg); this.panel3.Controls.Add(this.gbMsg);
this.panel3.Controls.Add(this.gbScript); this.panel3.Controls.Add(this.gbScript);
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(293, 0);
this.panel3.Name = "panel3"; this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(840, 632); this.panel3.Size = new System.Drawing.Size(834, 632);
this.panel3.TabIndex = 12; this.panel3.TabIndex = 12;
// //
// gbMsg // gbMsg
...@@ -351,7 +411,7 @@ ...@@ -351,7 +411,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(840, 349); this.gbMsg.Size = new System.Drawing.Size(834, 349);
this.gbMsg.TabIndex = 14; this.gbMsg.TabIndex = 14;
this.gbMsg.TabStop = false; this.gbMsg.TabStop = false;
this.gbMsg.Text = "输出"; this.gbMsg.Text = "输出";
...@@ -362,7 +422,7 @@ ...@@ -362,7 +422,7 @@
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(834, 329); this.rtbMsg.Size = new System.Drawing.Size(828, 329);
this.rtbMsg.TabIndex = 5; this.rtbMsg.TabIndex = 5;
this.rtbMsg.Text = ""; this.rtbMsg.Text = "";
this.rtbMsg.DoubleClick += new System.EventHandler(this.rtbMsg_DoubleClick); this.rtbMsg.DoubleClick += new System.EventHandler(this.rtbMsg_DoubleClick);
...@@ -373,7 +433,7 @@ ...@@ -373,7 +433,7 @@
this.gbScript.Dock = System.Windows.Forms.DockStyle.Bottom; this.gbScript.Dock = System.Windows.Forms.DockStyle.Bottom;
this.gbScript.Location = new System.Drawing.Point(0, 349); this.gbScript.Location = new System.Drawing.Point(0, 349);
this.gbScript.Name = "gbScript"; this.gbScript.Name = "gbScript";
this.gbScript.Size = new System.Drawing.Size(840, 283); this.gbScript.Size = new System.Drawing.Size(834, 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脚本";
...@@ -387,7 +447,7 @@ ...@@ -387,7 +447,7 @@
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(834, 263); this.tabScripts.Size = new System.Drawing.Size(828, 263);
this.tabScripts.TabIndex = 8; this.tabScripts.TabIndex = 8;
// //
// tpEngineScript // tpEngineScript
...@@ -397,7 +457,7 @@ ...@@ -397,7 +457,7 @@
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(826, 237); this.tpEngineScript.Size = new System.Drawing.Size(820, 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为变量名)";
...@@ -409,74 +469,80 @@ ...@@ -409,74 +469,80 @@
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(820, 211); this.rtbEngineScript.Size = new System.Drawing.Size(814, 211);
this.rtbEngineScript.TabIndex = 10; this.rtbEngineScript.TabIndex = 10;
this.rtbEngineScript.Text = ""; this.rtbEngineScript.Text = "";
// //
// pnlEngineToolBar // pnlEngineToolBar
// //
this.pnlEngineToolBar.Controls.Add(this.btnAutoAppendScript);
this.pnlEngineToolBar.Controls.Add(this.btnExecuteEngine);
this.pnlEngineToolBar.Controls.Add(this.cbScriptTip); this.pnlEngineToolBar.Controls.Add(this.cbScriptTip);
this.pnlEngineToolBar.Controls.Add(this.btnAutoAppendScript);
this.pnlEngineToolBar.Controls.Add(this.btnManagerExecuteScript);
this.pnlEngineToolBar.Controls.Add(this.label5); this.pnlEngineToolBar.Controls.Add(this.label5);
this.pnlEngineToolBar.Dock = System.Windows.Forms.DockStyle.Bottom; this.pnlEngineToolBar.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pnlEngineToolBar.Location = new System.Drawing.Point(3, 214); this.pnlEngineToolBar.Location = new System.Drawing.Point(3, 214);
this.pnlEngineToolBar.Name = "pnlEngineToolBar"; this.pnlEngineToolBar.Name = "pnlEngineToolBar";
this.pnlEngineToolBar.Size = new System.Drawing.Size(820, 20); this.pnlEngineToolBar.Size = new System.Drawing.Size(814, 20);
this.pnlEngineToolBar.TabIndex = 9; 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.SwitchWindow(\"窗口名称\");//多个窗口时,选择一个窗口打开", "driver.SwitchWindow(\"窗口句柄\");//多个窗口时,选择一个窗口打开",
"driver.SwitchNewWindow();//新的浏览器窗口", "driver.CreateNewWindow();//新的浏览器窗口",
"driver.SwitchNewTab();//在浏览器中打开新标签窗口", "driver.CreateNewTab();//在浏览器中打开新标签窗口",
"driver.SwitchParentFrame();//选择当前的上一级Frame", "driver.SwitchParentFrame();//选择当前的上一级Frame",
"driver.SwitchSubFrame(\"子窗口名称\")//选择子Frame", "driver.SwitchSubFrame(\"子窗口名称\")//选择子Frame",
"driver.SwitchSubFrame(子窗口索引数字);//选择子Frame", "driver.SwitchSubFrame(子窗口索引数字);//选择子Frame",
"driver.Screenshot(“图片路径”);//保存截图",
"driver.ResetInputState();//重置输入框状态",
"driver.NavigateTo(\"url\");//导航跳转",
"driver.NavigateBack();//页面历史后退",
"driver.NavigateForward();//页面历史向前",
"driver.FullScreen();//浏览器全屏", "driver.FullScreen();//浏览器全屏",
"driver.Maximize();//最大化窗口", "driver.Maximize();//最大化窗口",
"driver.Minimize();//最小化窗口", "driver.Minimize();//最小化窗口",
"driver.Close();//关闭当前窗口", "driver.Sleep(1000);//睡眠1000毫秒",
"driver.Dispose();//销毁当前程序,释放所有资源", "driver.Dispose();//销毁当前管理器,释放所有资源",
"driver.ExecuteScript(\"脚本\");//在网页中执行Javascript", "//网页操作相关,只针对当前的窗口,切换窗口请先使用SwitchWindow(handle)方法",
"driver.FindElement(\"/\",);//查找元素,默认查XPath", "driver.CurrentWindow.NavigateTo(\"url\");//导航跳转",
"driver.FindElement(\"form1\",\"id\");//查找元素,", "driver.CurrentWindow.NavigateBack();//页面历史后退",
"driver.FindElements(\"/\");//查找元素集合,默认查XPath", "driver.CurrentWindow.NavigateForward();//页面历史向前",
"driver.FindElements(\"cls1\",\"classname\");//查找元素集合,", "driver.CurrentWindow.NavigateRefresh();//页面强制刷新",
"driver.Sleep(1000);//睡眠1000毫秒"}); "driver.CurrentWindow.LoadScript(\"\");//在当前页面加载一个JS路径",
"driver.CurrentWindow.ExecuteScript(\"脚本\");//在网页中执行Javascript",
"driver.CurrentWindow.FindElement(\"/\",);//查找元素,默认查XPath",
"driver.CurrentWindow.FindElement(\"form1\",\"id\");//查找元素,第二个参数为查找类型,id,xpath,class,t" +
"ag,name等",
"driver.CurrentWindow.FindElements(\"/\");//查找元素集合,默认查XPath",
"driver.CurrentWindow.FindElements(\"cls1\",\"classname\");//查找元素集合,",
"driver.CurrentWindow.Screenshot(“图片路径”);//保存截图",
"driver.CurrentWindow.ResetInputState();//重置输入框状态",
"driver.CurrentWindow.Close();//关闭当前窗口"});
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(645, 20); this.cbScriptTip.Size = new System.Drawing.Size(624, 20);
this.cbScriptTip.TabIndex = 3; this.cbScriptTip.TabIndex = 6;
//
// btnAutoAppendScript
//
this.btnAutoAppendScript.Dock = System.Windows.Forms.DockStyle.Right;
this.btnAutoAppendScript.Location = new System.Drawing.Point(683, 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;
this.btnAutoAppendScript.Click += new System.EventHandler(this.btnAutoAppendScript_Click);
//
// btnManagerExecuteScript
//
this.btnManagerExecuteScript.Dock = System.Windows.Forms.DockStyle.Right;
this.btnManagerExecuteScript.Location = new System.Drawing.Point(739, 0);
this.btnManagerExecuteScript.Name = "btnManagerExecuteScript";
this.btnManagerExecuteScript.Size = new System.Drawing.Size(75, 20);
this.btnManagerExecuteScript.TabIndex = 4;
this.btnManagerExecuteScript.Text = "执行脚本";
this.btnManagerExecuteScript.UseVisualStyleBackColor = true;
this.btnManagerExecuteScript.Click += new System.EventHandler(this.btnManagerExecuteScript_Click);
// //
// label5 // label5
// //
...@@ -513,23 +579,23 @@ ...@@ -513,23 +579,23 @@
// //
// panel1 // panel1
// //
this.panel1.Controls.Add(this.btnExecuteScript); this.panel1.Controls.Add(this.btnWindowExecuteScript);
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(3, 214); this.panel1.Location = new System.Drawing.Point(3, 214);
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(820, 20); this.panel1.Size = new System.Drawing.Size(820, 20);
this.panel1.TabIndex = 10; this.panel1.TabIndex = 10;
// //
// btnExecuteScript // btnWindowExecuteScript
// //
this.btnExecuteScript.Dock = System.Windows.Forms.DockStyle.Right; this.btnWindowExecuteScript.Dock = System.Windows.Forms.DockStyle.Right;
this.btnExecuteScript.Location = new System.Drawing.Point(745, 0); this.btnWindowExecuteScript.Location = new System.Drawing.Point(745, 0);
this.btnExecuteScript.Name = "btnExecuteScript"; this.btnWindowExecuteScript.Name = "btnWindowExecuteScript";
this.btnExecuteScript.Size = new System.Drawing.Size(75, 20); this.btnWindowExecuteScript.Size = new System.Drawing.Size(75, 20);
this.btnExecuteScript.TabIndex = 5; this.btnWindowExecuteScript.TabIndex = 5;
this.btnExecuteScript.Text = "执行脚本"; this.btnWindowExecuteScript.Text = "执行脚本";
this.btnExecuteScript.UseVisualStyleBackColor = true; this.btnWindowExecuteScript.UseVisualStyleBackColor = true;
this.btnExecuteScript.Click += new System.EventHandler(this.btnExecuteScript_Click); this.btnWindowExecuteScript.Click += new System.EventHandler(this.btnWindowExecuteScript_Click);
// //
// tpActionJson // tpActionJson
// //
...@@ -564,6 +630,28 @@ ...@@ -564,6 +630,28 @@
this.panel4.Size = new System.Drawing.Size(826, 20); this.panel4.Size = new System.Drawing.Size(826, 20);
this.panel4.TabIndex = 12; this.panel4.TabIndex = 12;
// //
// btnShowActionsTip
//
this.btnShowActionsTip.Dock = System.Windows.Forms.DockStyle.Left;
this.btnShowActionsTip.Location = new System.Drawing.Point(144, 0);
this.btnShowActionsTip.Name = "btnShowActionsTip";
this.btnShowActionsTip.Size = new System.Drawing.Size(72, 20);
this.btnShowActionsTip.TabIndex = 16;
this.btnShowActionsTip.Text = "显示动作类型";
this.btnShowActionsTip.UseVisualStyleBackColor = true;
this.btnShowActionsTip.Click += new System.EventHandler(this.btnShowActionsTip_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);
//
// btnActionsDemo // btnActionsDemo
// //
this.btnActionsDemo.Dock = System.Windows.Forms.DockStyle.Left; this.btnActionsDemo.Dock = System.Windows.Forms.DockStyle.Left;
...@@ -571,7 +659,7 @@ ...@@ -571,7 +659,7 @@
this.btnActionsDemo.Name = "btnActionsDemo"; this.btnActionsDemo.Name = "btnActionsDemo";
this.btnActionsDemo.Size = new System.Drawing.Size(72, 20); this.btnActionsDemo.Size = new System.Drawing.Size(72, 20);
this.btnActionsDemo.TabIndex = 13; this.btnActionsDemo.TabIndex = 13;
this.btnActionsDemo.Text = "加载示例"; this.btnActionsDemo.Text = "常规示例";
this.btnActionsDemo.UseVisualStyleBackColor = true; this.btnActionsDemo.UseVisualStyleBackColor = true;
this.btnActionsDemo.Click += new System.EventHandler(this.btnActionsDemo_Click); this.btnActionsDemo.Click += new System.EventHandler(this.btnActionsDemo_Click);
// //
...@@ -586,27 +674,17 @@ ...@@ -586,27 +674,17 @@
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 // cbxHidenLocalCommandWindow
//
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
// //
this.btnShowActionsTip.Dock = System.Windows.Forms.DockStyle.Left; this.cbxHidenLocalCommandWindow.AutoSize = true;
this.btnShowActionsTip.Location = new System.Drawing.Point(144, 0); this.cbxHidenLocalCommandWindow.Checked = true;
this.btnShowActionsTip.Name = "btnShowActionsTip"; this.cbxHidenLocalCommandWindow.CheckState = System.Windows.Forms.CheckState.Checked;
this.btnShowActionsTip.Size = new System.Drawing.Size(72, 20); this.cbxHidenLocalCommandWindow.Location = new System.Drawing.Point(163, 53);
this.btnShowActionsTip.TabIndex = 16; this.cbxHidenLocalCommandWindow.Name = "cbxHidenLocalCommandWindow";
this.btnShowActionsTip.Text = "显示动作类型"; this.cbxHidenLocalCommandWindow.Size = new System.Drawing.Size(84, 16);
this.btnShowActionsTip.UseVisualStyleBackColor = true; this.cbxHidenLocalCommandWindow.TabIndex = 15;
this.btnShowActionsTip.Click += new System.EventHandler(this.btnShowActionsTip_Click); this.cbxHidenLocalCommandWindow.Text = "隐藏命令行";
this.cbxHidenLocalCommandWindow.UseVisualStyleBackColor = true;
// //
// FrmMain // FrmMain
// //
...@@ -619,6 +697,7 @@ ...@@ -619,6 +697,7 @@
this.Text = "代码测试"; this.Text = "代码测试";
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.panel5.ResumeLayout(false);
this.panel2.ResumeLayout(false); this.panel2.ResumeLayout(false);
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox2.PerformLayout();
...@@ -638,8 +717,8 @@ ...@@ -638,8 +717,8 @@
#endregion #endregion
private System.Windows.Forms.Button btnOpen; private System.Windows.Forms.Button btnInitialize;
private System.Windows.Forms.Button btnClose; private System.Windows.Forms.Button btnDispose;
private System.Windows.Forms.ComboBox cbxBrowserType; private System.Windows.Forms.ComboBox cbxBrowserType;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnScreenshot; private System.Windows.Forms.Button btnScreenshot;
...@@ -658,25 +737,23 @@ ...@@ -658,25 +737,23 @@
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.Label label4; private System.Windows.Forms.Label label4;
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 rtbEngineScript; private System.Windows.Forms.RichTextBox rtbEngineScript;
private System.Windows.Forms.Panel pnlEngineToolBar; private System.Windows.Forms.Panel pnlEngineToolBar;
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;
private System.Windows.Forms.CheckBox cbUseHub; private System.Windows.Forms.CheckBox cbUseHub;
private System.Windows.Forms.Button btnInjection; private System.Windows.Forms.Button btnSetReference;
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 btnAutoAppendScript; private System.Windows.Forms.Button btnAutoAppendScript;
private System.Windows.Forms.Button btnExecuteEngine; private System.Windows.Forms.Button btnManagerExecuteScript;
private System.Windows.Forms.RichTextBox rtbWebScript; private System.Windows.Forms.RichTextBox rtbWebScript;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnExecuteScript; private System.Windows.Forms.Button btnWindowExecuteScript;
private System.Windows.Forms.TabPage tpActionJson; private System.Windows.Forms.TabPage tpActionJson;
private System.Windows.Forms.RichTextBox rtbActionsJson; private System.Windows.Forms.RichTextBox rtbActionsJson;
private System.Windows.Forms.Panel panel4; private System.Windows.Forms.Panel panel4;
...@@ -684,6 +761,14 @@ ...@@ -684,6 +761,14 @@
private System.Windows.Forms.Button btnActionsDemo; private System.Windows.Forms.Button btnActionsDemo;
private System.Windows.Forms.Button btnMouseDemo; private System.Windows.Forms.Button btnMouseDemo;
private System.Windows.Forms.Button btnShowActionsTip; private System.Windows.Forms.Button btnShowActionsTip;
private System.Windows.Forms.ComboBox cbScriptTip;
private System.Windows.Forms.Panel panel5;
private System.Windows.Forms.Label lblCurrenWindow;
private System.Windows.Forms.Button btnCloseCurrentWindow;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.ComboBox cbWindows;
private System.Windows.Forms.Button btnSwitchWindow;
private System.Windows.Forms.CheckBox cbxHidenLocalCommandWindow;
} }
} }
...@@ -6,33 +6,50 @@ using OpenQA.Selenium.Firefox; ...@@ -6,33 +6,50 @@ using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote; using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Events; using OpenQA.Selenium.Support.Events;
using System; using System;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace Kivii.Test.WebDriver namespace Kivii.Test.WebDriver
{ {
public partial class FrmMain : Form public partial class FrmMain : Form
{ {
/// <summary>
/// 管理器
/// </summary>
private Manager _manager=null; private Manager _manager=null;
#region 初始化
public FrmMain() public FrmMain()
{ {
InitializeComponent(); InitializeComponent();
} }
#endregion
#region 输出日志相关
private void appendMsg(string msg) private void appendMsg(string msg)
{ {
rtbMsg.AppendText($"{msg}{Environment.NewLine}"); rtbMsg.AppendText($"{msg}{Environment.NewLine}");
rtbMsg.ScrollToCaret(); rtbMsg.ScrollToCaret();
} }
/// <summary>
/// 双击输出消息,清除内容
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void rtbMsg_DoubleClick(object sender, EventArgs e)
{
rtbMsg.Clear();
}
#endregion
#region 事件 #region 监听管理器的事件
private void addListener() private void addListener()
{ {
if (_manager == null) return; if (_manager == null) return;
_manager.OnException += manager_OnException; _manager.OnException += manager_OnException;
_manager.OnWindowChanged += manager_OnWindowChanged; _manager.OnCurrentWindowChanged += manager_OnWindowChanged;
//以下是WebDriver的事件
_manager.ElementClicked += EventDriver_ElementClicked; _manager.ElementClicked += EventDriver_ElementClicked;
_manager.ElementClicking += EventDriver_ElementClicking; _manager.ElementClicking += EventDriver_ElementClicking;
_manager.ElementValueChanging += EventDriver_ElementValueChanging; _manager.ElementValueChanging += EventDriver_ElementValueChanging;
...@@ -54,22 +71,22 @@ namespace Kivii.Test.WebDriver ...@@ -54,22 +71,22 @@ namespace Kivii.Test.WebDriver
private void manager_OnWindowChanged(object sender, Window e) private void manager_OnWindowChanged(object sender, Window e)
{ {
gbMsg.Text = $"输出(窗口Handle={e.Handle},Title={e.Title})"; lblCurrenWindow.Text = $"当前窗口:{(_manager?.StartWindow==_manager.CurrentWindow?"主窗口":"子窗口")}{Environment.NewLine}{e.Handle}{Environment.NewLine}标题:{e.Title}";
} }
private void manager_OnException(object sender, Exception e) private void manager_OnException(object sender, Exception e)
{ {
appendMsg($"Exception:{DateTime.Now}{Environment.NewLine}{e.Message}{Environment.NewLine}{e.StackTrace}"); appendMsg($"管理器执行异常:{DateTime.Now}{Environment.NewLine}{e.Message}{Environment.NewLine}{e.StackTrace}");
} }
private void EventDriver_ScriptExecuting(object sender, WebDriverScriptEventArgs e) private void EventDriver_ScriptExecuting(object sender, WebDriverScriptEventArgs e)
{ {
appendMsg($"EventDriver_ScriptExecuting:{Environment.NewLine}{e.Script}"); appendMsg($"网页脚本执行:{Environment.NewLine}{e.Script}");
} }
private void EventDriver_ScriptExecuted(object sender, WebDriverScriptEventArgs e) private void EventDriver_ScriptExecuted(object sender, WebDriverScriptEventArgs e)
{ {
appendMsg($"EventDriver_ScriptExecuted:{Environment.NewLine}{e.Script}"); appendMsg($"网页脚本执行成功:{Environment.NewLine}{e.Script}");
} }
private void EventDriver_NavigatingForward(object sender, WebDriverNavigationEventArgs e) private void EventDriver_NavigatingForward(object sender, WebDriverNavigationEventArgs e)
...@@ -124,7 +141,7 @@ namespace Kivii.Test.WebDriver ...@@ -124,7 +141,7 @@ namespace Kivii.Test.WebDriver
private void EventDriver_ExceptionThrown(object sender, WebDriverExceptionEventArgs e) private void EventDriver_ExceptionThrown(object sender, WebDriverExceptionEventArgs e)
{ {
appendMsg($"EventDriver_ExceptionThrown:{Environment.NewLine}{e}"); appendMsg($"EventDriver_ExceptionThrown:{Environment.NewLine}{e.ThrownException?.Message}");
} }
private void EventDriver_ElementValueChanged(object sender, WebElementValueEventArgs e) private void EventDriver_ElementValueChanged(object sender, WebElementValueEventArgs e)
...@@ -148,17 +165,78 @@ namespace Kivii.Test.WebDriver ...@@ -148,17 +165,78 @@ namespace Kivii.Test.WebDriver
} }
#endregion #endregion
#region 交互事件 #region 组织管理器的配置
/// <summary>
/// 使用远程WebDriver选择框发生变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbxRemote_CheckedChanged(object sender, EventArgs e)
{
lnkVncUrl.Enabled = cbxRemote.Checked;
cbUseHub.Enabled = cbxRemote.Checked;
cbxHidenLocalCommandWindow.Visible=!cbxRemote.Checked;
cbxBrowserType_SelectedIndexChanged(null, null);
}
/// <summary>
/// 浏览器类型选择发生变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbxBrowserType_SelectedIndexChanged(object sender, EventArgs e)
{
if (!cbxRemote.Checked)
{
lnkVncUrl.Text = null;
return;
}
if (cbUseHub.Checked)
{
lnkVncUrl.Text = $"http://hub.selenium.kivii.org";
}
else
{
if (string.IsNullOrEmpty(cbxBrowserType.Text))
{
lnkVncUrl.Text = null;
}
else
{
lnkVncUrl.Text = $"http://viewer.{cbxBrowserType.Text}.selenium.kivii.org";
}
}
}
/// <summary>
/// 点击了远程浏览器VNC
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lnkVncUrl_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (cbUseHub.Checked)
{
System.Diagnostics.Process.Start($"{lnkVncUrl.Text}");
}
else
{
System.Diagnostics.Process.Start($"{lnkVncUrl.Text}/?autoconnect=1&resize=scale&password=secret");
}
}
#endregion
#region 初始化和销毁管理器
/// <summary> /// <summary>
/// 初始化管理器 /// 初始化管理器
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnOpen_Click(object sender, EventArgs e) private void btnInitialize_Click(object sender, EventArgs e)
{ {
if (_manager != null) return; if (_manager != null) return;
rtbMsg.Clear(); rtbMsg.Clear();
_manager = new Manager(); _manager = new Manager();
_manager.HideCommandPromptWindow = cbxHidenLocalCommandWindow.Checked;//如果是本地运行,可选择隐藏本地服务的命令行
addListener();//管理器的2个事件是直接可以监听的,WebDriver的事件是需要等初始化完才能监听的
var serviceUrl = string.Empty; var serviceUrl = string.Empty;
if (cbxRemote.Checked) if (cbxRemote.Checked)
{ {
...@@ -171,25 +249,22 @@ namespace Kivii.Test.WebDriver ...@@ -171,25 +249,22 @@ namespace Kivii.Test.WebDriver
serviceUrl = $"http://driver.{cbxBrowserType.Text}.selenium.kivii.org"; serviceUrl = $"http://driver.{cbxBrowserType.Text}.selenium.kivii.org";
} }
} }
if (_manager.Initialize(cbxBrowserType.Text, serviceUrl)) var result=_manager.Initialize(cbxBrowserType.Text, serviceUrl)?"成功":"失败,可能是未能正确加载驱动";
{ appendMsg($"初始化{result}");
addListener();
}
else
{
appendMsg("初始化失败,可能是未能成功连接WebDriver驱动!");
}
} }
/// <summary> /// <summary>
/// 关闭管理器 /// 销毁管理器
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnClose_Click(object sender, EventArgs e) private void btnDispose_Click(object sender, EventArgs e)
{ {
_manager?.Dispose(); _manager?.Dispose();
_manager = null; _manager = null;
} }
#endregion
#region 原生操作
/// <summary> /// <summary>
/// 浏览器截图 /// 浏览器截图
/// </summary> /// </summary>
...@@ -201,7 +276,7 @@ namespace Kivii.Test.WebDriver ...@@ -201,7 +276,7 @@ namespace Kivii.Test.WebDriver
SaveFileDialog sfd=new SaveFileDialog(); SaveFileDialog sfd=new SaveFileDialog();
sfd.Filter = "图片文件|*.jpg"; sfd.Filter = "图片文件|*.jpg";
if (sfd.ShowDialog() != DialogResult.OK) return; if (sfd.ShowDialog() != DialogResult.OK) return;
_manager?.Screenshot(sfd.FileName); _manager?.CurrentWindow.Screenshot(sfd.FileName);
} }
/// <summary> /// <summary>
/// 向网页加载一个脚本路径 /// 向网页加载一个脚本路径
...@@ -210,128 +285,105 @@ namespace Kivii.Test.WebDriver ...@@ -210,128 +285,105 @@ namespace Kivii.Test.WebDriver
/// <param name="e"></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?.CurrentWindow.LoadScript(tbxScriptPath.Text);
} }
/// <summary> /// <summary>
/// 使用远程WebDriver选择框发生变化 /// 导航至某个网页
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void cbxRemote_CheckedChanged(object sender, EventArgs e) private void btnNavigate_Click(object sender, EventArgs e)
{ {
lnkVncUrl.Enabled = cbxRemote.Checked; _manager?.CurrentWindow.NavigateTo(tbxUrl.Text);
cbUseHub.Enabled=cbxRemote.Checked;
cbxBrowserType_SelectedIndexChanged(null, null);
} }
/// <summary> /// <summary>
/// 浏览器类型选择发生变化 /// 显示当前浏览器中所有的窗口信息
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void cbxBrowserType_SelectedIndexChanged(object sender, EventArgs e) private void btnHandlers_Click(object sender, EventArgs e)
{ {
if (!cbxRemote.Checked) foreach (var handler in _manager.AllWindowHandles)
{
lnkVncUrl.Text= null;
return;
}
if (cbUseHub.Checked)
{
lnkVncUrl.Text = $"http://hub.selenium.kivii.org";
}
else
{ {
if (string.IsNullOrEmpty(cbxBrowserType.Text)) appendMsg($"Handle Name:{handler}");
{
lnkVncUrl.Text = null;
}
else
{
lnkVncUrl.Text = $"http://viewer.{cbxBrowserType.Text}.selenium.kivii.org";
}
} }
appendMsg($"Current Handle:{_manager.CurrentWindowHandle}");
} }
/// <summary> /// <summary>
/// 点击了远程浏览器VNC /// 向执行器加入一段代码
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void lnkVncUrl_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) private void btnAutoAppendScript_Click(object sender, EventArgs e)
{ {
if (cbUseHub.Checked) rtbEngineScript.AppendText($"{cbScriptTip.Text}{Environment.NewLine}");
{
System.Diagnostics.Process.Start($"{lnkVncUrl.Text}");
}
else
{
System.Diagnostics.Process.Start($"{lnkVncUrl.Text}/?autoconnect=1&resize=scale&password=secret");
}
} }
/// <summary> /// <summary>
/// 导航至某个网页 /// 向管理器引擎注入一个变量
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnNavigate_Click(object sender, EventArgs e) private void btnSetReference_Click(object sender, EventArgs e)
{ {
_manager?.NavigateTo(tbxUrl.Text); //向Manager中注入一个变量,可以在引擎执行代码中调用,变量名为tbxVarName中配置的
//这个功能可以注入一个服务器端存储或读取数量的类,方便交互,
_manager?.SetReference(tbxVarName.Text, new ReferenceTest());
appendMsg($"注入了变量名为{tbxVarName.Text},可在Manager.ExecuteScript()的脚本代码中使用该变量");
} }
/// <summary> /// <summary>
/// 显示当前浏览器中所有的窗口信息 /// 显示当前应用程序域中所有Action动作的类型
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnHandlers_Click(object sender, EventArgs e) private void btnShowActionsTip_Click(object sender, EventArgs e)
{ {
foreach (var handler in _manager.AllWindowHandles) foreach (var actionAttribute in ActionBase.GetActionAttributes())
{ {
appendMsg($"Handler Name:{handler}"); appendMsg($"{actionAttribute.Type.FullName}{Environment.NewLine}别名:\"{actionAttribute.Alias}\" 描述:{actionAttribute.Description}");
} }
} }
private void cbWindows_Enter(object sender, EventArgs e)
/// <summary>
/// 向执行器加入一段代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAutoAppendScript_Click(object sender, EventArgs e)
{ {
rtbEngineScript.AppendText($"{cbScriptTip.Text}{Environment.NewLine}"); cbWindows.Items.Clear();
var windows = _manager?.AllWindowHandles.ToArray();
if (windows == null) return;
cbWindows.Items.AddRange(windows);
} }
/// <summary> /// <summary>
/// 向管理器引擎注入一个变量 /// 选择一个窗口激活
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnInjection_Click(object sender, EventArgs e) private void btnSwitchWindow_Click(object sender, EventArgs e)
{ {
//向Manager中注入一个变量,可以在引擎执行代码中调用,变量名为tbxVarName中配置的 _manager?.SwitchWindow(cbWindows.Text);
//这个功能可以注入一个服务器端存储或读取数量的类,方便交互,
//在引擎代码中可以直接调用test.MessageBox("内容")来与主程序交互功能
_manager?.Injection(tbxVarName.Text, new InjectionTest());
appendMsg($"注入了变量名为{tbxVarName.Text},可在引擎代码中执行{tbxVarName.Text}.{nameof(InjectionTest.MessageBox)}(\"消息\");或{tbxVarName.Text}.{nameof(InjectionTest.GetValue)}(\"内容\")");
} }
#endregion
/// <summary> /// <summary>
/// 双击输出消息,清除内容 /// 关闭当前窗口
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void rtbMsg_DoubleClick(object sender, EventArgs e) private void btnCloseCurrentWindow_Click(object sender, EventArgs e)
{ {
rtbMsg.Clear(); _manager?.CurrentWindow?.Close();
} }
#endregion
#region 三个脚本执行功能 #region 三个脚本执行功能
/// <summary> /// <summary>
/// 执行内置脚本引擎 /// 执行Manager内置脚本引擎
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnExecuteEngine_Click(object sender, EventArgs e) private void btnManagerExecuteScript_Click(object sender, EventArgs e)
{ {
var result = _manager.Execute(rtbEngineScript.Text); var result = _manager.ExecuteScript(rtbEngineScript.Text);
rtbEngineScript.Clear(); rtbEngineScript.Clear();
appendMsg($"Result:{result}"); appendMsg($"Result:{result}");
} }
...@@ -341,23 +393,13 @@ namespace Kivii.Test.WebDriver ...@@ -341,23 +393,13 @@ namespace Kivii.Test.WebDriver
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void btnExecuteScript_Click(object sender, EventArgs e) private void btnWindowExecuteScript_Click(object sender, EventArgs e)
{ {
var result = _manager?.ExecuteScript(rtbWebScript.Text); var result = _manager?.CurrentWindow.ExecuteScript(rtbWebScript.Text);
rtbWebScript.Clear(); rtbWebScript.Clear();
appendMsg($"Result:{result}"); 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 = WeatherTest.Get();
var json = autoPage.ExportActions(true);
rtbActionsJson.Text = json;
}
/// <summary> /// <summary>
/// 将Actions的JSON代码加载进WebPage中执行,URL的起始页使用界面上的tbxUrl中的值 /// 将Actions的JSON代码加载进WebPage中执行,URL的起始页使用界面上的tbxUrl中的值
/// </summary> /// </summary>
...@@ -368,22 +410,26 @@ namespace Kivii.Test.WebDriver ...@@ -368,22 +410,26 @@ namespace Kivii.Test.WebDriver
if (_manager == null) return; if (_manager == null) return;
_manager.Maximize();//最大化网页 _manager.Maximize();//最大化网页
var autoPage = new WebPage(_manager); var window = new Window(_manager);
autoPage.Url =tbxUrl.Text;//生成DEMO时不需要 window.ImportActions(rtbActionsJson.Text);
autoPage.ImportActions(rtbActionsJson.Text); var rtns=window.ExecuteActions();
var rtns=autoPage.Execute();
appendMsg($"执行结果:{Environment.NewLine}{rtns}"); appendMsg($"执行结果:{Environment.NewLine}{rtns}");
} }
#endregion #endregion
private void btnShowActionsTip_Click(object sender, EventArgs e) #region Action的演示代码
/// <summary>
/// 加载一段演示动作的Actions代码,JSON格式
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnActionsDemo_Click(object sender, EventArgs e)
{ {
foreach (var actionAttribute in ActionBase.GetActionAttributes()) var autoPage = WeatherTest.Get();
{ var json = autoPage.ExportActions(true);
appendMsg($"{actionAttribute.Type.FullName}{Environment.NewLine}别名:\"{actionAttribute.Alias}\" 描述:{actionAttribute.Description}"); rtbActionsJson.Text = json;
}
} }
/// <summary> /// <summary>
/// 鼠标动作示例 /// 鼠标动作示例
...@@ -396,18 +442,11 @@ namespace Kivii.Test.WebDriver ...@@ -396,18 +442,11 @@ namespace Kivii.Test.WebDriver
var json = autoPage.ExportActions(true); var json = autoPage.ExportActions(true);
rtbActionsJson.Text = json; rtbActionsJson.Text = json;
} }
#endregion
} }
#region 注入的对象
internal class InjectionTest
{
public void MessageBox(string msg)
{
System.Windows.Forms.MessageBox.Show(msg);
}
public string GetValue(string key)
{
return $"Key={key}";
}
}
#endregion
} }
...@@ -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.11030, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Kivii.WebDriver.V4.7, Version=4.15.2023.11040, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.WebDriver.4.15.2023.11030\lib\net47\Kivii.WebDriver.V4.7.dll</HintPath> <HintPath>packages\Kivii.WebDriver.4.15.2023.11040\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>
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
<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\MouseTest.cs" />
<Compile Include="Tests\ReferenceTest.cs" />
<Compile Include="Tests\WeatherTest.cs" /> <Compile Include="Tests\WeatherTest.cs" />
<EmbeddedResource Include="FrmMain.resx"> <EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.cs</DependentUpon> <DependentUpon>FrmMain.cs</DependentUpon>
......
...@@ -10,9 +10,9 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -10,9 +10,9 @@ namespace Kivii.Test.WebDriver.Tests
{ {
internal class MouseTest internal class MouseTest
{ {
public static WebPage Get() public static Window Get()
{ {
var rtns = new WebPage(null); var rtns = new Window(null);
//rtns.Url = "https://www.baidu.com";//这个配置可通过NavigateAction进行 //rtns.Url = "https://www.baidu.com";//这个配置可通过NavigateAction进行
...@@ -21,7 +21,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -21,7 +21,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new NavigateAction(); var action = new NavigateAction();
action.Name = "跳转网站"; action.Name = "跳转网站";
action.Url = "http://www.cacs.mofcom.gov.cn/cacscms/view/notice/zhtbomrasff#"; action.Url = "http://www.cacs.mofcom.gov.cn/cacscms/view/notice/zhtbomrasff#";
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -30,7 +30,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -30,7 +30,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Pause; action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000; action.DurationMilliseconds = 2000;
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -39,7 +39,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -39,7 +39,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Click; action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]"); action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -48,7 +48,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -48,7 +48,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Pause; action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000; action.DurationMilliseconds = 2000;
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -57,7 +57,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -57,7 +57,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Click; action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbomrapex\"]"); action.Target = new ElementFinder("//*[@id=\"zhtbomrapex\"]");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -66,7 +66,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -66,7 +66,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Pause; action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000; action.DurationMilliseconds = 2000;
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -75,7 +75,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -75,7 +75,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Click; action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbmg\"]"); action.Target = new ElementFinder("//*[@id=\"zhtbmg\"]");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -84,7 +84,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -84,7 +84,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Pause; action.Type = MouseActionType.Pause;
action.DurationMilliseconds = 2000; action.DurationMilliseconds = 2000;
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -93,7 +93,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -93,7 +93,7 @@ namespace Kivii.Test.WebDriver.Tests
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Click; action.Type = MouseActionType.Click;
action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]"); action.Target = new ElementFinder("//*[@id=\"zhtbomrasff\"]");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -101,7 +101,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -101,7 +101,7 @@ namespace Kivii.Test.WebDriver.Tests
{ {
var action = new MouseAction(); var action = new MouseAction();
action.Type = MouseActionType.Perform; action.Type = MouseActionType.Perform;
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
return rtns; return rtns;
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kivii.Test.WebDriver.Tests
{
/// <summary>
/// 本对象是通过manager.SetReference()的方法注入到Manager中
/// 在Manager的ExecuteScript时,就可以使用到本类的内置方法
/// </summary>
internal class ReferenceTest
{
}
}
...@@ -10,17 +10,17 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -10,17 +10,17 @@ namespace Kivii.Test.WebDriver.Tests
{ {
internal class WeatherTest internal class WeatherTest
{ {
public static WebPage Get() public static Window Get()
{ {
var rtns = new WebPage(null); var rtns = new Window(null);
//autoPage.Url = "https://www.baidu.com";//生成DEMO时不需要 //autoPage.Url = "https://www.baidu.com";//生成DEMO时不需要
#region 第一步,在输入框内输入内容 #region 第一步,在输入框内输入内容
{ {
var action = new InputAction(); var action = new InputAction();
action.Name = "输入查询内容"; action.Name = "输入查询内容";
action.InputValue = "最近天气"; action.InputValue = "最近天气";
action.ElementFinder = new ElementFinder("kw", "id"); action.Target = new ElementFinder("kw", "id");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -28,8 +28,8 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -28,8 +28,8 @@ namespace Kivii.Test.WebDriver.Tests
{ {
var action = new ClickAction(); var action = new ClickAction();
action.Name = "百度一下"; action.Name = "百度一下";
action.ElementFinder = new ElementFinder("su", "id"); action.Target = new ElementFinder("su", "id");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -38,9 +38,9 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -38,9 +38,9 @@ namespace Kivii.Test.WebDriver.Tests
var action = new OutputAction(); var action = new OutputAction();
action.Name = "取当前城市"; action.Name = "取当前城市";
//使用XPath //使用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.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", "所在城市"); action.Attributes.Add("innerText", "所在城市");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -49,9 +49,9 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -49,9 +49,9 @@ namespace Kivii.Test.WebDriver.Tests
var action = new OutputAction(); var action = new OutputAction();
action.Name = "取天气"; action.Name = "取天气";
//使用XPath //使用XPath
action.ElementFinder = new ElementFinder(".weather-main-temp_6CEpK > span:nth-child(1)", "css"); action.Target = new ElementFinder(".weather-main-temp_6CEpK > span:nth-child(1)", "css");
action.Attributes.Add("innerText", "天气"); action.Attributes.Add("innerText", "天气");
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
...@@ -61,7 +61,7 @@ namespace Kivii.Test.WebDriver.Tests ...@@ -61,7 +61,7 @@ namespace Kivii.Test.WebDriver.Tests
action.Name = "测试JS返回"; action.Name = "测试JS返回";
//使用XPath //使用XPath
action.Js = "return '测试JS返回';"; action.Js = "return '测试JS返回';";
rtns.Actions.Add(action); rtns.AddAction(action);
} }
#endregion #endregion
return rtns; return rtns;
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Kivii.WebDriver" version="4.15.2023.11030" targetFramework="net472" /> <package id="Kivii.WebDriver" version="4.15.2023.11040" 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" />
......
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