1.我们需要加载对应的dll,并定义变量:

        [DllImport(@"c:\1\2\SuperPatrickLibrary.dll", EntryPoint = "findElement")]

        unsafe public extern static void findElement(string pStrId, string pStrName, string pStrClassName, string pStrControleType);

 

        [DllImport(@"c:\1\2\SuperPatrickLibrary.dll", EntryPoint = "sendShortCutKeys")]

        unsafe public extern static void sendShortCutKeys(string KeysString);

 

        [DllImport(@"c:\1\2\SuperPatrickLibrary.dll", EntryPoint = "sendKeys")]

        unsafe public extern static void sendKeys(string KeysString);

 

2.示例如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Runtime.InteropServices;

 

namespace cSharpSuperPatrickTest

{

    class A

    {

 

        [DllImport(@"c:\1\2\SuperPatrickLibrary.dll", EntryPoint = "findElement")]

        unsafe public extern static void findElement(string pStrId, string pStrName, string pStrClassName, string pStrControleType);

 

        [DllImport(@"c:\1\2\SuperPatrickLibrary.dll", EntryPoint = "sendShortCutKeys")]

        unsafe public extern static void sendShortCutKeys(string KeysString);

 

        [DllImport(@"c:\1\2\SuperPatrickLibrary.dll", EntryPoint = "sendKeys")]

        unsafe public extern static void sendKeys(string KeysString);

 

        static void Main(string[] args)

        {

            unsafe

            {

                findElement("307", "显示桌面", "", "Button");

 

                sendShortCutKeys("{WIN}r");

                sendKeys("notepad");

                sendShortCutKeys("{Return}");

                sendKeys("你好吗?测试文档!!!123");

                findElement("", "文件(F)", "", "MenuItem");

                findElement("3", "保存(S)   Ctrl+S", "", "MenuItem");

                sendKeys("test.txt");

                findElement("1", "", "Button", "Button");

                findElement("CommandButton_6", "(Y)", "CCPushButton", "Button");

                findElement("", "文件(F)", "", "MenuItem");

                findElement("7", "退出(X)", "", "MenuItem");

            }

 

        }

    }

}

 注意: 用Sleep方法在自动化测试中不是一个好习惯,这里只是为了演示方便。SuperPatrick后续版本会逐步退出智能等待的API

 

findElement函数的参数由SuperPatrick定位器所提供,你也可以通过SuperPatrick定位器提供的右键复制findlement函数来自动生成findElement函数调用进一步减少工作量,sendShortCutKeys集成了Windows快捷键操作,sendKeys则可以输入各种字符包括中文等各种字符,并且接口名称和webdriver一致,希望大家亲自把这个例子运行以下即可看到效果,是不是相当简单?更多的技巧接口SuperXi会陆续发布文章详细告诉大家如何使用。


SuperXi