建立Adapter来访问更多的属性和方法

如果你使用Ranorex Spy来分析VIP Database应用,你会看到应用窗口提供了三种Adapter(Form, Control 和 NativeWindow)。Ranorex.Form adapter使用的对象库应用文件夹"MyApp"直接可用的所有属性和方法。如果你想要访问像“ProcessName”这样的属性或者是调用.NET WinForms控件暴露的方法,你需要把Form adapter转换为NativeWindow或者Control。就像你在下面的代码段中看到的,“...Info”对象用来创建想要的Adapter。

C#

// Creating adapter of type 'NativeWindow' using the "...Info" object Ranorex.NativeWindow nativeWnd = repo.MyApp.SelfInfo.CreateAdapter<Ranorex.NativeWindow>(false); // ... and read value of attribute 'ProcessName' Report.Info("Process name of VIP Database: " + nativeWnd.ProcessName);

// Using Control Adapter to access properties and methods of // .NET WinForms control Ranorex.Control winFormsControl = repo.MyApp.SelfInfo.CreateAdapter<Ranorex.Control>(false); // Set background color of VIP application to Color.Black using the // exposed property 'BackColor' winFormsControl.SetPropertyValue("BackColor",Color.Black);

// Report screenshot after changing the background color Report.Screenshot(repo.MyApp.Self); // Closes VIP Database by invoking the 'Close' method // exposed by the System.Windows.Forms.Form class winFormsControl.InvokeMethod("Close");

VB.NET

' Creating adapter of type 'NativeWindow' using the "...Info" object Dim nativeWnd As Ranorex.NativeWindow = repo.MyApp.SelfInfo.CreateAdapter(Of Ranorex.NativeWindow)(False) ' ... and read value of attribute 'ProcessName' Report.Info("Process name of VIP Database: " & nativeWnd.ProcessName)

' Using Control Adapter to access properties and methods of ' .NET WinForms control Dim winFormsControl As Ranorex.Control = repo.MyApp.SelfInfo.CreateAdapter(Of Ranorex.Control)(False) ' Set background color of VIP application to Color.Black using the ' exposed property 'BackColor' winFormsControl.SetPropertyValue("BackColor", Color.Black)

' Report screenshot after changing the background color Report.Screenshot(repo.MyApp.Self) ' Closes VIP Database by invoking the 'Close' method ' exposed by the System.Windows.Forms.Form class winFormsControl.InvokeMethod("Close")

注意:为了访问一个WinForms控件暴露出来的属性和方法,你需要知道它们的名字。如果你不熟悉控件的API,可以寻求应用的开发人员的协助。

posted @ 2016-04-10 20:18  老夫子_22  阅读(221)  评论(0)    收藏  举报