Ranorex入门指南43 – Class和Code Module的区别

当我们在Ranorex项目中,新建文件的时候,可以看到Ranorex类别下,有CodeModule模板, 在C#类别下有Class模板。它们表面看上去都是C#的代码文件,那么它们有什么区别呢?

如果我们新建的是Class文件,那么Ranorex会自动帮你生成一个如下的类文件模板。这个基本上标准的C#类文件了,你可以用它实现些功能,然后让其他文件引用它。
/*
* Created by Ranorex
* User: user
* Date: 09-Oct-2012
* Time: 3:23 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace WindowTest
{
///
/// Description of Class1.
///
public class Class1
{
public Class1()
{
}
}
}

而如果我们新建的是Code Module文件,Ranorex会自动帮我们生成如下的Code Module模板,其中的类继承了ITestModule的Interface, 然后实现了部分代码以便你能把它加入测试套件中使用。
/*
* Created by Ranorex
* User: user
* Date: 09-Oct-2012
* Time: 3:24 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace WindowTest
{
///
/// Description of UserCodeModule1.
///
[TestModule(“E5DA5DBE-C503-4F5E-A363-1E17AFA6260C”, ModuleType.UserCode, 1)]
public class UserCodeModule1 : ITestModule
{
///
/// Constructs a new instance.
///
public UserCodeModule1()
{
// Do not delete – a parameterless constructor is required!
}
///
/// Performs the playback of actions in this module.
///
/// You should not call this method directly, instead pass the module
/// instance to the method
/// that will in turn invoke this method.
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
}
}
}

Leave a comment

请输入正确的验证码