Commit da5239f4 by 施晓雨

更新代码测试

parent da58093e
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
{
internal class MyJsAction:ActionBase
{
public string Js { get; set; }
public override string Execute(Manager manager)
{
try
{
var value=manager.ExecuteScript(Js);
return value;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
...@@ -39,14 +39,18 @@ ...@@ -39,14 +39,18 @@
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.btnTest = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox();
this.btnTestBaidu = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnInjection = new System.Windows.Forms.Button();
this.btnHandlers = new System.Windows.Forms.Button(); this.btnHandlers = new System.Windows.Forms.Button();
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();
this.btnInjectionScript = new System.Windows.Forms.Button(); this.btnLoadScript = new System.Windows.Forms.Button();
this.btnNavigate = new System.Windows.Forms.Button(); this.btnNavigate = new System.Windows.Forms.Button();
this.tbxUrl = new System.Windows.Forms.TextBox(); this.tbxUrl = new System.Windows.Forms.TextBox();
this.tbxVarName = new System.Windows.Forms.TextBox();
this.tbxScriptPath = new System.Windows.Forms.TextBox(); this.tbxScriptPath = new System.Windows.Forms.TextBox();
this.panel3 = new System.Windows.Forms.Panel(); this.panel3 = new System.Windows.Forms.Panel();
this.gbMsg = new System.Windows.Forms.GroupBox(); this.gbMsg = new System.Windows.Forms.GroupBox();
...@@ -66,6 +70,7 @@ ...@@ -66,6 +70,7 @@
this.btnExecuteScript = new System.Windows.Forms.Button(); this.btnExecuteScript = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.panel2.SuspendLayout(); this.panel2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.panel3.SuspendLayout(); this.panel3.SuspendLayout();
this.gbMsg.SuspendLayout(); this.gbMsg.SuspendLayout();
...@@ -193,45 +198,69 @@ ...@@ -193,45 +198,69 @@
// //
// panel2 // panel2
// //
this.panel2.Controls.Add(this.btnTest); this.panel2.Controls.Add(this.groupBox3);
this.panel2.Controls.Add(this.groupBox2); this.panel2.Controls.Add(this.groupBox2);
this.panel2.Controls.Add(this.groupBox1); this.panel2.Controls.Add(this.groupBox1);
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, 687); this.panel2.Size = new System.Drawing.Size(287, 545);
this.panel2.TabIndex = 10; this.panel2.TabIndex = 10;
// //
// btnTest // groupBox3
// //
this.btnTest.Location = new System.Drawing.Point(21, 521); this.groupBox3.Controls.Add(this.btnTestBaidu);
this.btnTest.Name = "btnTest"; this.groupBox3.Dock = System.Windows.Forms.DockStyle.Top;
this.btnTest.Size = new System.Drawing.Size(72, 23); this.groupBox3.Location = new System.Drawing.Point(0, 277);
this.btnTest.TabIndex = 11; this.groupBox3.Name = "groupBox3";
this.btnTest.Text = "动态测试"; this.groupBox3.Size = new System.Drawing.Size(287, 100);
this.btnTest.UseVisualStyleBackColor = true; this.groupBox3.TabIndex = 12;
this.btnTest.Click += new System.EventHandler(this.btnTest_Click); this.groupBox3.TabStop = false;
this.groupBox3.Text = "自动化测试";
//
// btnTestBaidu
//
this.btnTestBaidu.Location = new System.Drawing.Point(8, 20);
this.btnTestBaidu.Name = "btnTestBaidu";
this.btnTestBaidu.Size = new System.Drawing.Size(119, 23);
this.btnTestBaidu.TabIndex = 12;
this.btnTestBaidu.Text = "执行百度查询";
this.btnTestBaidu.UseVisualStyleBackColor = true;
this.btnTestBaidu.Click += new System.EventHandler(this.btnTestBaidu_Click_1);
// //
// groupBox2 // groupBox2
// //
this.groupBox2.Controls.Add(this.btnInjection);
this.groupBox2.Controls.Add(this.btnHandlers); this.groupBox2.Controls.Add(this.btnHandlers);
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);
this.groupBox2.Controls.Add(this.btnInjectionScript); this.groupBox2.Controls.Add(this.btnLoadScript);
this.groupBox2.Controls.Add(this.btnNavigate); this.groupBox2.Controls.Add(this.btnNavigate);
this.groupBox2.Controls.Add(this.tbxUrl); this.groupBox2.Controls.Add(this.tbxUrl);
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, 130);
this.groupBox2.Name = "groupBox2"; this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(287, 196); this.groupBox2.Size = new System.Drawing.Size(287, 147);
this.groupBox2.TabIndex = 10; this.groupBox2.TabIndex = 10;
this.groupBox2.TabStop = false; this.groupBox2.TabStop = false;
this.groupBox2.Text = "原生功能"; this.groupBox2.Text = "原生功能";
// //
// btnInjection
//
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 // btnHandlers
// //
this.btnHandlers.Location = new System.Drawing.Point(6, 167); this.btnHandlers.Location = new System.Drawing.Point(8, 101);
this.btnHandlers.Name = "btnHandlers"; this.btnHandlers.Name = "btnHandlers";
this.btnHandlers.Size = new System.Drawing.Size(72, 23); this.btnHandlers.Size = new System.Drawing.Size(72, 23);
this.btnHandlers.TabIndex = 4; this.btnHandlers.TabIndex = 4;
...@@ -239,6 +268,15 @@ ...@@ -239,6 +268,15 @@
this.btnHandlers.UseVisualStyleBackColor = true; this.btnHandlers.UseVisualStyleBackColor = true;
this.btnHandlers.Click += new System.EventHandler(this.btnHandlers_Click); this.btnHandlers.Click += new System.EventHandler(this.btnHandlers_Click);
// //
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(6, 80);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(53, 12);
this.label6.TabIndex = 3;
this.label6.Text = "注入对象";
//
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
...@@ -246,7 +284,7 @@ ...@@ -246,7 +284,7 @@
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(53, 12); this.label4.Size = new System.Drawing.Size(53, 12);
this.label4.TabIndex = 3; this.label4.TabIndex = 3;
this.label4.Text = "注入脚本"; this.label4.Text = "网页脚本";
// //
// label1 // label1
// //
...@@ -257,15 +295,15 @@ ...@@ -257,15 +295,15 @@
this.label1.TabIndex = 1; this.label1.TabIndex = 1;
this.label1.Text = "打开网址"; this.label1.Text = "打开网址";
// //
// btnInjectionScript // btnLoadScript
// //
this.btnInjectionScript.Location = new System.Drawing.Point(227, 46); this.btnLoadScript.Location = new System.Drawing.Point(227, 46);
this.btnInjectionScript.Name = "btnInjectionScript"; this.btnLoadScript.Name = "btnLoadScript";
this.btnInjectionScript.Size = new System.Drawing.Size(49, 23); this.btnLoadScript.Size = new System.Drawing.Size(49, 23);
this.btnInjectionScript.TabIndex = 0; this.btnLoadScript.TabIndex = 0;
this.btnInjectionScript.Text = "注入"; this.btnLoadScript.Text = "加载";
this.btnInjectionScript.UseVisualStyleBackColor = true; this.btnLoadScript.UseVisualStyleBackColor = true;
this.btnInjectionScript.Click += new System.EventHandler(this.btnInjectionScript_Click); this.btnLoadScript.Click += new System.EventHandler(this.btnLoadScript_Click);
// //
// btnNavigate // btnNavigate
// //
...@@ -285,6 +323,14 @@ ...@@ -285,6 +323,14 @@
this.tbxUrl.TabIndex = 2; this.tbxUrl.TabIndex = 2;
this.tbxUrl.Text = "http://www.baidu.com"; this.tbxUrl.Text = "http://www.baidu.com";
// //
// tbxVarName
//
this.tbxVarName.Location = new System.Drawing.Point(64, 74);
this.tbxVarName.Name = "tbxVarName";
this.tbxVarName.Size = new System.Drawing.Size(158, 21);
this.tbxVarName.TabIndex = 2;
this.tbxVarName.Text = "test";
//
// tbxScriptPath // tbxScriptPath
// //
this.tbxScriptPath.Location = new System.Drawing.Point(64, 47); this.tbxScriptPath.Location = new System.Drawing.Point(64, 47);
...@@ -300,7 +346,7 @@ ...@@ -300,7 +346,7 @@
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(287, 0); this.panel3.Location = new System.Drawing.Point(287, 0);
this.panel3.Name = "panel3"; this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(817, 687); this.panel3.Size = new System.Drawing.Size(807, 545);
this.panel3.TabIndex = 12; this.panel3.TabIndex = 12;
// //
// gbMsg // gbMsg
...@@ -309,7 +355,7 @@ ...@@ -309,7 +355,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(817, 461); this.gbMsg.Size = new System.Drawing.Size(807, 319);
this.gbMsg.TabIndex = 14; this.gbMsg.TabIndex = 14;
this.gbMsg.TabStop = false; this.gbMsg.TabStop = false;
this.gbMsg.Text = "输出"; this.gbMsg.Text = "输出";
...@@ -320,7 +366,7 @@ ...@@ -320,7 +366,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(811, 441); this.rtbMsg.Size = new System.Drawing.Size(801, 299);
this.rtbMsg.TabIndex = 5; this.rtbMsg.TabIndex = 5;
this.rtbMsg.Text = ""; this.rtbMsg.Text = "";
// //
...@@ -329,9 +375,9 @@ ...@@ -329,9 +375,9 @@
this.gbScript.Controls.Add(this.tabScripts); this.gbScript.Controls.Add(this.tabScripts);
this.gbScript.Controls.Add(this.panel1); this.gbScript.Controls.Add(this.panel1);
this.gbScript.Dock = System.Windows.Forms.DockStyle.Bottom; this.gbScript.Dock = System.Windows.Forms.DockStyle.Bottom;
this.gbScript.Location = new System.Drawing.Point(0, 461); this.gbScript.Location = new System.Drawing.Point(0, 319);
this.gbScript.Name = "gbScript"; this.gbScript.Name = "gbScript";
this.gbScript.Size = new System.Drawing.Size(817, 226); this.gbScript.Size = new System.Drawing.Size(807, 226);
this.gbScript.TabIndex = 13; this.gbScript.TabIndex = 13;
this.gbScript.TabStop = false; this.gbScript.TabStop = false;
this.gbScript.Text = "执行Javascript脚本"; this.gbScript.Text = "执行Javascript脚本";
...@@ -344,7 +390,7 @@ ...@@ -344,7 +390,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(811, 181); this.tabScripts.Size = new System.Drawing.Size(801, 181);
this.tabScripts.TabIndex = 8; this.tabScripts.TabIndex = 8;
// //
// tpEngineScript // tpEngineScript
...@@ -354,7 +400,7 @@ ...@@ -354,7 +400,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(803, 155); this.tpEngineScript.Size = new System.Drawing.Size(793, 155);
this.tpEngineScript.TabIndex = 0; this.tpEngineScript.TabIndex = 0;
this.tpEngineScript.Tag = "engine"; this.tpEngineScript.Tag = "engine";
this.tpEngineScript.Text = "引擎执行(driver为变量名)"; this.tpEngineScript.Text = "引擎执行(driver为变量名)";
...@@ -366,7 +412,7 @@ ...@@ -366,7 +412,7 @@
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(797, 129); this.rtbEngineScript.Size = new System.Drawing.Size(787, 129);
this.rtbEngineScript.TabIndex = 10; this.rtbEngineScript.TabIndex = 10;
this.rtbEngineScript.Text = ""; this.rtbEngineScript.Text = "";
// //
...@@ -378,7 +424,7 @@ ...@@ -378,7 +424,7 @@
this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom; this.panel4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel4.Location = new System.Drawing.Point(3, 132); this.panel4.Location = new System.Drawing.Point(3, 132);
this.panel4.Name = "panel4"; this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(797, 20); this.panel4.Size = new System.Drawing.Size(787, 20);
this.panel4.TabIndex = 9; this.panel4.TabIndex = 9;
// //
// cbScriptTip // cbScriptTip
...@@ -404,15 +450,14 @@ ...@@ -404,15 +450,14 @@
"driver.Close();//关闭当前窗口", "driver.Close();//关闭当前窗口",
"driver.Dispose();//销毁当前程序,释放所有资源", "driver.Dispose();//销毁当前程序,释放所有资源",
"driver.ExecuteScript(\"脚本\");//在网页中执行Javascript", "driver.ExecuteScript(\"脚本\");//在网页中执行Javascript",
"driver.FindElement(\"id\",\"form1\");//查找元素,第一个参数为id,tagname,classname,tagname,第二个为选择" + "driver.FindElement(\"/\",);//查找元素,默认查XPath",
"器", "driver.FindElement(\"form1\",\"id\");//查找元素,",
"driver.FindElements(\"classname\",\"cls1\");//查找元素集合,第一个参数为id,tagname,classname,tagna" + "driver.FindElements(\"/\");//查找元素集合,默认查XPath",
"me,第二个为选择器", "driver.FindElements(\"cls1\",\"classname\");//查找元素集合,",
"driver.Sleep(1000);//睡眠1000毫秒", "driver.Sleep(1000);//睡眠1000毫秒"});
""});
this.cbScriptTip.Location = new System.Drawing.Point(59, 0); this.cbScriptTip.Location = new System.Drawing.Point(59, 0);
this.cbScriptTip.Name = "cbScriptTip"; this.cbScriptTip.Name = "cbScriptTip";
this.cbScriptTip.Size = new System.Drawing.Size(682, 20); this.cbScriptTip.Size = new System.Drawing.Size(672, 20);
this.cbScriptTip.TabIndex = 3; this.cbScriptTip.TabIndex = 3;
// //
// label5 // label5
...@@ -428,7 +473,7 @@ ...@@ -428,7 +473,7 @@
// btnAutoAppendScript // btnAutoAppendScript
// //
this.btnAutoAppendScript.Dock = System.Windows.Forms.DockStyle.Right; this.btnAutoAppendScript.Dock = System.Windows.Forms.DockStyle.Right;
this.btnAutoAppendScript.Location = new System.Drawing.Point(741, 0); this.btnAutoAppendScript.Location = new System.Drawing.Point(731, 0);
this.btnAutoAppendScript.Name = "btnAutoAppendScript"; this.btnAutoAppendScript.Name = "btnAutoAppendScript";
this.btnAutoAppendScript.Size = new System.Drawing.Size(56, 20); this.btnAutoAppendScript.Size = new System.Drawing.Size(56, 20);
this.btnAutoAppendScript.TabIndex = 0; this.btnAutoAppendScript.TabIndex = 0;
...@@ -442,7 +487,7 @@ ...@@ -442,7 +487,7 @@
this.tpWebScript.Location = new System.Drawing.Point(4, 22); this.tpWebScript.Location = new System.Drawing.Point(4, 22);
this.tpWebScript.Name = "tpWebScript"; this.tpWebScript.Name = "tpWebScript";
this.tpWebScript.Padding = new System.Windows.Forms.Padding(3); this.tpWebScript.Padding = new System.Windows.Forms.Padding(3);
this.tpWebScript.Size = new System.Drawing.Size(696, 155); this.tpWebScript.Size = new System.Drawing.Size(793, 155);
this.tpWebScript.TabIndex = 1; this.tpWebScript.TabIndex = 1;
this.tpWebScript.Tag = "web"; this.tpWebScript.Tag = "web";
this.tpWebScript.Text = "网页内执行"; this.tpWebScript.Text = "网页内执行";
...@@ -454,7 +499,7 @@ ...@@ -454,7 +499,7 @@
this.rtbWebScript.Dock = System.Windows.Forms.DockStyle.Fill; this.rtbWebScript.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtbWebScript.Location = new System.Drawing.Point(3, 3); this.rtbWebScript.Location = new System.Drawing.Point(3, 3);
this.rtbWebScript.Name = "rtbWebScript"; this.rtbWebScript.Name = "rtbWebScript";
this.rtbWebScript.Size = new System.Drawing.Size(690, 149); this.rtbWebScript.Size = new System.Drawing.Size(787, 149);
this.rtbWebScript.TabIndex = 9; this.rtbWebScript.TabIndex = 9;
this.rtbWebScript.Text = ""; this.rtbWebScript.Text = "";
// //
...@@ -465,7 +510,7 @@ ...@@ -465,7 +510,7 @@
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(3, 198); this.panel1.Location = new System.Drawing.Point(3, 198);
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(811, 25); this.panel1.Size = new System.Drawing.Size(801, 25);
this.panel1.TabIndex = 2; this.panel1.TabIndex = 2;
// //
// btnClearMsg // btnClearMsg
...@@ -482,7 +527,7 @@ ...@@ -482,7 +527,7 @@
// btnExecuteScript // btnExecuteScript
// //
this.btnExecuteScript.Dock = System.Windows.Forms.DockStyle.Right; this.btnExecuteScript.Dock = System.Windows.Forms.DockStyle.Right;
this.btnExecuteScript.Location = new System.Drawing.Point(736, 0); this.btnExecuteScript.Location = new System.Drawing.Point(726, 0);
this.btnExecuteScript.Name = "btnExecuteScript"; this.btnExecuteScript.Name = "btnExecuteScript";
this.btnExecuteScript.Size = new System.Drawing.Size(75, 25); this.btnExecuteScript.Size = new System.Drawing.Size(75, 25);
this.btnExecuteScript.TabIndex = 1; this.btnExecuteScript.TabIndex = 1;
...@@ -494,7 +539,7 @@ ...@@ -494,7 +539,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1104, 687); this.ClientSize = new System.Drawing.Size(1094, 545);
this.Controls.Add(this.panel3); this.Controls.Add(this.panel3);
this.Controls.Add(this.panel2); this.Controls.Add(this.panel2);
this.Name = "FrmMain"; this.Name = "FrmMain";
...@@ -502,6 +547,7 @@ ...@@ -502,6 +547,7 @@
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.panel2.ResumeLayout(false); this.panel2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox2.PerformLayout();
this.panel3.ResumeLayout(false); this.panel3.ResumeLayout(false);
...@@ -529,7 +575,7 @@ ...@@ -529,7 +575,7 @@
private System.Windows.Forms.Panel panel2; private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnInjectionScript; private System.Windows.Forms.Button btnLoadScript;
private System.Windows.Forms.Button btnNavigate; private System.Windows.Forms.Button btnNavigate;
private System.Windows.Forms.TextBox tbxUrl; private System.Windows.Forms.TextBox tbxUrl;
private System.Windows.Forms.TextBox tbxScriptPath; private System.Windows.Forms.TextBox tbxScriptPath;
...@@ -553,7 +599,11 @@ ...@@ -553,7 +599,11 @@
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 btnTest; private System.Windows.Forms.Button btnInjection;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox tbxVarName;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button btnTestBaidu;
} }
} }
using Kivii.WebDriver; using Kivii.WebDriver;
using OpenQA.Selenium; using Kivii.WebDriver.Actions;
using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote; using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Events; using OpenQA.Selenium.Support.Events;
using System; using System;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
namespace Kivii.Test.WebDriver namespace Kivii.Test.WebDriver
...@@ -21,6 +20,7 @@ namespace Kivii.Test.WebDriver ...@@ -21,6 +20,7 @@ namespace Kivii.Test.WebDriver
private void appendMsg(string msg) private void appendMsg(string msg)
{ {
rtbMsg.AppendText($"{msg}{Environment.NewLine}"); rtbMsg.AppendText($"{msg}{Environment.NewLine}");
rtbMsg.ScrollToCaret();
} }
#region 事件 #region 事件
...@@ -164,9 +164,15 @@ namespace Kivii.Test.WebDriver ...@@ -164,9 +164,15 @@ namespace Kivii.Test.WebDriver
serviceUrl = $"http://driver.{cbxBrowserType.Text}.selenium.kivii.org"; serviceUrl = $"http://driver.{cbxBrowserType.Text}.selenium.kivii.org";
} }
} }
_manager.Initialize(cbxBrowserType.Text, serviceUrl); if (_manager.Initialize(cbxBrowserType.Text, serviceUrl))
{
addListener(); addListener();
} }
else
{
appendMsg("初始化失败,可能是未能成功连接WebDriver驱动!");
}
}
private void btnClose_Click(object sender, EventArgs e) private void btnClose_Click(object sender, EventArgs e)
{ {
_manager?.Dispose(); _manager?.Dispose();
...@@ -182,7 +188,7 @@ namespace Kivii.Test.WebDriver ...@@ -182,7 +188,7 @@ namespace Kivii.Test.WebDriver
_manager?.Screenshot(sfd.FileName); _manager?.Screenshot(sfd.FileName);
} }
private void btnInjectionScript_Click(object sender, EventArgs e) private void btnLoadScript_Click(object sender, EventArgs e)
{ {
_manager?.LoadScript(tbxScriptPath.Text); _manager?.LoadScript(tbxScriptPath.Text);
} }
...@@ -265,7 +271,6 @@ namespace Kivii.Test.WebDriver ...@@ -265,7 +271,6 @@ namespace Kivii.Test.WebDriver
{ {
rtbEngineScript.AppendText($"{cbScriptTip.Text}{Environment.NewLine}"); rtbEngineScript.AppendText($"{cbScriptTip.Text}{Environment.NewLine}");
} }
#endregion
...@@ -287,5 +292,79 @@ namespace Kivii.Test.WebDriver ...@@ -287,5 +292,79 @@ namespace Kivii.Test.WebDriver
} }
driver.Quit(); driver.Quit();
} }
private void btnInjection_Click(object sender, EventArgs e)
{
//向Manager中注入一个变量,可以在引擎执行代码中调用,变量名为tbxVarName中配置的
//这个功能可以注入一个服务器端存储或读取数量的类,方便交互,
//在引擎代码中可以直接调用test.MessageBox("内容")来与主程序交互功能
_manager?.Injection(tbxVarName.Text, new InjectionTest());
appendMsg($"注入了变量名为{tbxVarName.Text},可在引擎代码中执行{tbxVarName.Text}.{nameof(InjectionTest.MessageBox)}(\"消息\");或{tbxVarName.Text}.{nameof(InjectionTest.GetValue)}(\"内容\")");
} }
#endregion
private void btnTestBaidu_Click_1(object sender, EventArgs e)
{
if(_manager==null) return;
_manager.Maximize();//最大化网页
var baidu = new WebPage(_manager);
baidu.Url = "https://www.baidu.com";
#region 第一步,在输入框内输入内容
var inputAction = new InputAction();
inputAction.Name = "输入查询内容";
inputAction.InputValue = "最近天气";
inputAction.ElementFinder = new ElementFinder("kw", "id");
baidu.Actions.Add(inputAction);
#endregion
#region 第二步点击百度一下查询按键
var clickAction=new ClickAction();
clickAction.Name = "百度一下";
clickAction.ElementFinder = new ElementFinder("su","id");
baidu.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", "所在城市");
baidu.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", "天气");
baidu.Actions.Add(outputAction2);
#endregion
#region 第五步:测试下本地Action
var jsAction = new MyJsAction();
jsAction.Name = "测试JS返回";
//使用XPath
jsAction.Js = "return '测试JS返回';";
baidu.Actions.Add(jsAction);
#endregion
var result =baidu.Execute();
appendMsg($"执行结果:{Environment.NewLine}{result}");
}
}
#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.11000, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Kivii.WebDriver.V4.7, Version=4.15.2023.11010, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.WebDriver.4.15.2023.11000\lib\net47\Kivii.WebDriver.V4.7.dll</HintPath> <HintPath>packages\Kivii.WebDriver.4.15.2023.11010\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>
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Actions\MyAction.cs" />
<Compile Include="FrmMain.cs"> <Compile Include="FrmMain.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Kivii.WebDriver" version="4.15.2023.11000" targetFramework="net472" /> <package id="Kivii.WebDriver" version="4.15.2023.11010" 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" />
<package id="System.Drawing.Common" version="7.0.0" targetFramework="net472" />
<package id="Selenium.WebDriver.ChromeDriver" version="119.0.6045.10500" targetFramework="net472" /> <package id="Selenium.WebDriver.ChromeDriver" version="119.0.6045.10500" targetFramework="net472" />
<package id="Selenium.WebDriver.GeckoDriver.Win64" version="0.33.0" targetFramework="net472" /> <package id="Selenium.WebDriver.GeckoDriver.Win64" version="0.33.0" targetFramework="net472" />
<package id="Selenium.WebDriver.IEDriver" version="4.14.0" targetFramework="net472" /> <package id="Selenium.WebDriver.IEDriver" version="4.14.0" targetFramework="net472" />
<package id="Selenium.WebDriver.MSEdgeDriver" version="118.0.2088.41" targetFramework="net472" /> <package id="Selenium.WebDriver.MSEdgeDriver" version="118.0.2088.41" targetFramework="net472" />
<package id="System.Drawing.Common" version="7.0.0" targetFramework="net472" />
</packages> </packages>
\ No newline at end of file
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