How do I return the value of difference between the two pixelmaps being compared? I want to know the difference so I can use a while loop to delay execution until the two pixelmaps are within a certain tolerance. The reason being I want to wait until images located in different elements on a web page are loaded before the rest of the code is executed (for an automated test). I am using the Assert.IsTrue to compare the two currently with a 5 percent tolerance but I'm not sure how to turn this into a loop.

ArtOfTest.Common.PixelMap expected = ArtOfTest.Common.PixelMap.FromBitmap(expectedbmp);
ArtOfTest.Common.PixelMap actual = ArtOfTest.Common.PixelMap.FromBitmap(actualbmp);

Assert.IsTrue(expected.Compare(actual,5.0));
有帮助吗?

解决方案

It sounds like you're asking how to do a while loop which performs a test and waits until the condition has fulfilled. I don't think the fact that you're doing it in an automated test or not really matters. In either case, assuming something is going on in the background thread which will eventually make the two PixelMaps return true on Compare:

 while( !expected.Compare(actual, 5.0))
 {
     const int numberOfMillisecondsToSleep = 1000;
     System.Threading.Thread.Sleep(numberOfMillisecondsToSleep);
 }

I don't fully understand the context of the question and this assumes that if you sleep the condition will eventually be fulfilled. If not, this is an endless loop, so be careful.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top