Ranorex入门指南48 – 基于图像的测试

Ranorex有一个优点,就是可以快速通过给定的图片,在界面上找到类似的对象,然后对该对象进行操作。这大大提高了测试的灵活性,因为往往有的软件并非用标准技术开发,控件不一定能够被自动测试工具识别。这个时候,测试工程师可以通过图像识别的方式来对界面上的某些特殊控件进行操作。

这在ranorex里面叫做 image based test。我们这一节就来看一个小例子,首先要将changecolor这个对象的screenshot加入对象库,然后编写如下的代码:
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
ImageBaseTest() ;
}

void ImageBaseTest()
{
repo.SimpleGUI.SearchTimeout = new Duration(1000);
if (repo.SimpleGUI.SelfInfo.Exists())
{
repo.SimpleGUI.Self.Close();
}
Host.Local.RunApplication(“c:/SimpleGUI.exe”, “”, “”, false);
repo.SimpleGUI.Self.Activate();

Bitmap MyScreenshot = repo.SimpleGUI.ChangeColorInfo.GetScreenshot1();
repo.SimpleGUI.Self.Click(MyScreenshot);

repo.SimpleGUI.Self.Click(); // move the mouse
repo.SimpleGUI.Self.Click(new Location(MyScreenshot, new Imaging.FindOptions(0.97)));

repo.SimpleGUI.Self.Click(); // move the mouse
Imaging.FindOptions.Default.Similarity = 0.95;
repo.SimpleGUI.Self.Click(MyScreenshot);

}

这个例子里面展现了三种通过图像来对控件进行操作的方法。repo.SimpleGUI.Self.Click(MyScreenshot);是直接通过位图进行查找,然后操作。 repo.SimpleGUI.Self.Click(new Location(MyScreenshot, new Imaging.FindOptions(0.97))); 是通过找到位置后进行操作,可以指定相似度。第三种Imaging.FindOptions.Default.Similarity = 0.95;可以设定气候所有的图像查找的相似度。

Leave a comment

请输入正确的验证码