1
1
using Aquality . Selenium . Core . Configurations ;
2
2
using Aquality . Selenium . Core . Elements . Interfaces ;
3
3
using Aquality . Selenium . Core . Localization ;
4
- using SkiaSharp ;
5
4
using System ;
6
5
using System . Collections . Generic ;
7
6
using System . Globalization ;
@@ -39,15 +38,7 @@ public virtual float Compare(string dumpName = null)
39
38
{
40
39
var directory = GetDumpDirectory ( dumpName ) ;
41
40
LocalizedLogger . Info ( "loc.form.dump.compare" , directory . Name ) ;
42
- if ( ! directory . Exists )
43
- {
44
- throw new InvalidOperationException ( $ "Dump directory [{ directory . FullName } ] does not exist.") ;
45
- }
46
- var imageFiles = directory . GetFiles ( $ "*{ ImageFormat . Extension } ") ;
47
- if ( imageFiles . Length == 0 )
48
- {
49
- throw new InvalidOperationException ( $ "Dump directory [{ directory . FullName } ] does not contain any [*{ ImageFormat . Extension } ] files.") ;
50
- }
41
+ var imageFiles = GetImageFiles ( directory ) ;
51
42
var existingElements = FilterElementsForVisualization ( ) . ToDictionary ( el => el . Key , el => el . Value ) ;
52
43
var countOfUnproceededElements = existingElements . Count ;
53
44
var countOfProceededElements = 0 ;
@@ -64,12 +55,21 @@ public virtual float Compare(string dumpName = null)
64
55
}
65
56
else
66
57
{
67
- comparisonResult += existingElements [ key ] . Visual . GetDifference ( SKImage . FromEncodedData ( imageFile . FullName ) ) ;
58
+ comparisonResult += existingElements [ key ] . Visual . GetDifference ( imageFile . ReadImage ( ) ) ;
68
59
countOfUnproceededElements -- ;
69
60
countOfProceededElements ++ ;
70
61
existingElements . Remove ( key ) ;
71
62
}
72
63
}
64
+ LogUnproceededElements ( countOfUnproceededElements , existingElements , absentOnFormElementNames ) ;
65
+ // adding of countOfUnproceededElements means 100% difference for each element absent in dump or on page
66
+ var result = ( comparisonResult + countOfUnproceededElements ) / ( countOfProceededElements + countOfUnproceededElements ) ;
67
+ LocalizedLogger . Info ( "loc.form.dump.compare.result" , result . ToString ( "P" , CultureInfo . InvariantCulture ) ) ;
68
+ return result ;
69
+ }
70
+
71
+ private void LogUnproceededElements ( int countOfUnproceededElements , IDictionary < string , T > existingElements , IList < string > absentOnFormElementNames )
72
+ {
73
73
if ( countOfUnproceededElements > 0 )
74
74
{
75
75
if ( existingElements . Any ( ) )
@@ -82,10 +82,20 @@ public virtual float Compare(string dumpName = null)
82
82
}
83
83
LocalizedLogger . Warn ( "loc.form.dump.unprocessedelements" , countOfUnproceededElements ) ;
84
84
}
85
- // adding of countOfUnproceededElements means 100% difference for each element absent in dump or on page
86
- var result = ( comparisonResult + countOfUnproceededElements ) / ( countOfProceededElements + countOfUnproceededElements ) ;
87
- LocalizedLogger . Info ( "loc.form.dump.compare.result" , result . ToString ( "P" , CultureInfo . InvariantCulture ) ) ;
88
- return result ;
85
+ }
86
+
87
+ private FileInfo [ ] GetImageFiles ( DirectoryInfo directory )
88
+ {
89
+ if ( ! directory . Exists )
90
+ {
91
+ throw new InvalidOperationException ( $ "Dump directory [{ directory . FullName } ] does not exist.") ;
92
+ }
93
+ var imageFiles = directory . GetFiles ( $ "*{ ImageFormat . Extension } ") ;
94
+ if ( imageFiles . Length == 0 )
95
+ {
96
+ throw new InvalidOperationException ( $ "Dump directory [{ directory . FullName } ] does not contain any [*{ ImageFormat . Extension } ] files.") ;
97
+ }
98
+ return imageFiles ;
89
99
}
90
100
91
101
public virtual void Save ( string dumpName = null )
@@ -170,10 +180,11 @@ protected virtual DirectoryInfo GetDumpDirectory(string dumpName = null)
170
180
if ( fullDumpPath . Length + maxNameLengthOfDumpElements > MaxFullFileNameLength )
171
181
{
172
182
validDumpNameString = validDumpNameString . Substring ( 0 , MaxFullFileNameLength - Path . GetFullPath ( DumpsDirectory ) . Length - maxNameLengthOfDumpElements ) ;
173
- LocalizedLogger . Warn ( "loc.form.dump.exceededdumpname" , validDumpNameString ) ;
183
+ fullDumpPath = Path . Combine ( DumpsDirectory , validDumpNameString ) ;
184
+ LocalizedLogger . Warn ( "loc.form.dump.exceededdumpname" , fullDumpPath ) ;
174
185
}
175
186
176
- return new DirectoryInfo ( Path . Combine ( DumpsDirectory , validDumpNameString ) ) ;
187
+ return new DirectoryInfo ( fullDumpPath ) ;
177
188
}
178
189
}
179
190
}
0 commit comments