C#学习记录
程序员文章站
2022-07-09 21:53:28
...
int r=repo.MainWnd_PMS_AzSoft.ctrl_DrawViewWindow.ScreenRectangle.Top;
int e=repo.MainWnd_PMS_AzSoft.ctrl_DrawViewWindow.ScreenRectangle.Bottom;
int d=repo.MainWnd_PMS_AzSoft.ctrl_DrawViewWindow.ScreenRectangle.Height;
int x=repo.MainWnd_PMS_AzSoft.ctrl_DrawViewWindow.ScreenRectangle.Width;
Report.Info("屏幕顶:"+r+";\r\n屏幕底:"+e+";\r\n屏幕高:"+d+";\r\n屏幕宽:"+x+";");
1、图片对比
/// <summary>
/// 图片对比
/// </summary>
/// <param name="element">这里获取了Element类型</param>
/// <param name="varImagePath">图片路径</param>
/// <param name="varImageName">图片名称</param>
/// <param name="varSimilarityNuber">相似度</param>
public static void CompareImge(Element element, string varImagePath,string varImageName,double varSimilarityNuber){
string ImageName=varImageName+".jpg"; //图片全名
string FilePathName=varImagePath+ImageName;
if(File.Exists(FilePathName)==false){
element.CaptureCompressedImage().Store(FilePathName); //捕获存储冬图片
Report.Info("存储二维、三维图片路径为:"+FilePathName);
}
Bitmap strImageName=Ranorex.Imaging.Load(FilePathName); //加载原来存储的图片
Imaging.FindOptions MyFindOptions=new Imaging.FindOptions(varSimilarityNuber); //设置图片相似度
Validate.Options MyOption = new Validate.Options(false,ReportLevel.Failure,Validate.CreateScreenshot.Never);
try{
repo.MainWnd_PMS_AzSoft.ctrl_DrawViewWindow.PressKeys("{Return}");
bool Similarity=Validate.CompareImage(element,strImageName,MyFindOptions,"图片对比名称:"+ImageName,MyOption);
if(Similarity==true){
Report.Info(ImageName+"与图片对比一致");
}
}catch(Exception e){
e.Message.ToString();
}
}
删除文件
/// <summary>
/// 删除路径下的工程,防止文件重名保存文件失败
/// </summary>
/// <param name="srcPath">工程路径</param>
public static bool DeleteFiles(string srcPath)
{
if (Directory.Exists(srcPath)==false)
{
return true;
}else{
try{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
File.Delete(i.FullName); //删除指定文件
}
}
Report.Info ("删除文件成功!");
return true;
} catch (Exception)
{
Report.Error("删除文件失败!");
return false;
}
}
}
上一篇: const指针
下一篇: Java笔记(18)NIO流