Validate without touch module success/failure status

Class library usage, coding and language questions.
phibao37
Posts: 5
Joined: Tue Mar 07, 2017 9:35 am

Validate without touch module success/failure status

Post by phibao37 » Tue Mar 07, 2017 10:35 am

I'm validating my app item captured image match with some expected image, like this:
// Get screenshot image of repo item
CompressedImage img1 = myItemInfo.Getscreenshot_1();
CompressedImage img2 = myItemInfo.Getscreenshot_2();
CompressedImage img3 = myItemInfo.Getscreenshot_3();

bool res1 = Validate.ContainsImage(myItemInfo, img1, Imaging.FindOptions.Default, "Validate with img1", false);
bool res2 = Validate.ContainsImage(myItemInfo, img2, Imaging.FindOptions.Default, "Validate with img2", false);
bool res3 = Validate.ContainsImage(myItemInfo, img3, Imaging.FindOptions.Default, "Validate with img3", false);
//bool res4 = Validate.Exists(myItemInfo, "Validate item exist", false);
//bool res5 = Validate.AreEqual(1+1, 2, "Validating...", false);

if (res1 || res2 || res3)
	Report.Log(ReportLevel.Success, "Validation", "Current item is in state1/state2/state3");
else
	Report.Failure("Validation", "Current item is not in any expected state");
I want this module step success when myItemInfo match either img1, img2 or img3, and the module failure only when it doesn't match any expected image.
In the code above, I tried to set exceptionOnFail to false in each validation, and yes, it does not throw any exception. But I'd like my module run as success, too, and this is in the report:

Code: Select all

Success Validation  Validate with img1  
Failure Validation  Validate with img2  
Failure Validation  Validate with img3
Success Validation  Current item is in state1/state2/state3 
Error Module The module has failed because one or more actions have failed. 
As above, the module still be marked as faiure, not success.
So, how to solve my problem here?

PS, I would like it to work with other validation method as well, example Validate.Exist, Validate.AreEqual, ...
I wonder that there is some method like ValidateCore.ContainsImage, ValidateCore.Exist,.. that execute validation only and do not 'touch' to current module execution. Does such method exist?
Last edited by phibao37 on Fri Mar 10, 2017 9:39 am, edited 1 time in total.

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

Re: Validate without touch module success/failure status

Post by asdf » Thu Mar 09, 2017 3:38 pm

Hi Phibao,

In order to check whether the image are the same, I would recommend using the Imaging class rather than the Validate class, since the imaging class doesn't throw an exception on a failure. It just compare images and returns true or false and doesn't abort the test run.

Code: Select all

Imaging.Compare(bitmapA,bitmapB);
Hope this helps.

Kind regards,
asdf

phibao37
Posts: 5
Joined: Tue Mar 07, 2017 9:35 am

Re: Validate without touch module success/failure status

Post by phibao37 » Fri Mar 10, 2017 10:40 am

asdf wrote:Hi Phibao,

In order to check whether the image are the same, I would recommend using the Imaging class rather than the Validate class, since the imaging class doesn't throw an exception on a failure. It just compare images and returns true or false and doesn't abort the test run.

Code: Select all

Imaging.Compare(bitmapA,bitmapB);
Hope this helps.

Kind regards,
asdf
Thanks, it worked!
However, the correct method should be Imaging.Contains, not Imaging.Compare

I summary some corresponding method with each Validation API:
  • Validate.ContainsImage(element, image, option) <==> Imaging.Contains(element, image, option)
  • Validate.CompareImage(element, image, option) <==> Imaging.Compare(element, image, option)
  • Validate.Exists(repoInfo) <==> repoInfo.Exists()
  • Validate.Attribute(element, name, value) <==> element.GetAttributeValue(name).Equals(value)