Ranorex入门指南34 – 最大最小化窗口

我们重新新建一个Csharp的测试代码模块,命名为SimpleCode.cs。在这个测试代码文件中,我们模仿官方文档上的例子来尝试激活SimpleGUI这个桌面应用,并且把它最大化,最小化,回复原状,然后关闭。

下面是例子里面的代码:
public class SimpleCode : ITestModule
{
SimpleGUITestRepository repo = SimpleGUITestRepository.Instance;
///
/// Constructs a new instance.
///

public SimpleCode()
{
// 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;

Report.Info(Ranorex.Form.DefaultSearchTimeout.ToString());
Report.Info(Ranorex.Form.TimeoutFactor.ToString());

if (!repo.SimpleGUI.SelfInfo.Exists())
{
Host.Local.RunApplication(“C:\\Documents and Settings\\Administrator\\桌面\\SimpleGUI.exe”, “”, “”, false);
}
repo.SimpleGUI.Self.Activate();
Delay.Seconds(1);
Report.Info(repo.SimpleGUI.Self.Active.ToString());
int x = repo.SimpleGUI.Self.ScreenRectangle.Width;
int y = repo.SimpleGUI.Self.ScreenRectangle.Height;

repo.SimpleGUI.Self.Maximize();
Delay.Seconds(1);
repo.SimpleGUI.Self.Minimize();
Delay.Seconds(1);
repo.SimpleGUI.Self.Restore();
Delay.Seconds(1);
repo.SimpleGUI.Self.Resize(x, y);
Delay.Seconds(1);

repo.SimpleGUI.Self.Close();

}
}

注意第3行代码是引用对象库,其他行的代码都很简单,连注释都不需要添加即可读懂。

对于初次编写测试代码的同学,下面几行代码可以重点关注下,他们分别是:
if (!repo.SimpleGUI.SelfInfo.Exists()) // 检查某个对象是否存在
repo.SimpleGUI.Self.Activate(); // 激活某个对象,是指成为最前的对象
Delay.Seconds(1); // 等待1秒钟的时间

Leave a comment

请输入正确的验证码