Verify Color

2 Answers 17 Views
WPF Testing
Sreelakshmi
Top achievements
Rank 1
Iron
Iron
Sreelakshmi asked on 03 Mar 2025, 05:32 AM

Hi Team,

Iam automating WPF application. Is there a way to identify and verify colors.

 

Thanks,

Sreelakshmi

 

2 Answers, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 03 Mar 2025, 10:39 AM

Hello Sreelakshmi,

Have you tried the advanced verification options so far? 

I believe that the color of each element can be verified through its properties and the advanced verification builder can help you with this. 

Regards,
Elena
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Sreelakshmi
Top achievements
Rank 1
Iron
Iron
commented on 05 Mar 2025, 05:37 AM

Hi,

I dont find anything related to color in advanced verifications options .So what i need to do is to verify a button colour is Green or not?

Thanks,

Sreelakshmi

0
Ivaylo
Telerik team
answered on 06 Mar 2025, 09:35 AM

Hello Sreelakshmi,

Thank you for your inquiry regarding verifying the color of a button using Test Studio UI.

Unfortunately, it is not possible to perform this verification directly through the Test Studio UI. However, you can achieve this by using coded steps, as demonstrated in the provided code snippet below:

// Find the button named "btn" in the main window of the active application
Button myBtn = Manager.ActiveApplication.MainWindow.Find.ByName<Button>("btn");

// Get the background color of the button as a SolidColorBrush
var background = myBtn.Background as SolidColorBrush;

// Uncomment the following lines to log the RGB values of the button's background color
// These lines help you see the actual RGB values, which you can then use in the Assert statements
// Log.WriteLine(background.Color.R.ToString()); // Logs the Red component of the color
// Log.WriteLine(background.Color.G.ToString()); // Logs the Green component of the color
// Log.WriteLine(background.Color.B.ToString()); // Logs the Blue component of the color

// Verify that the Red component of the background color is 144
Assert.AreEqual(background.Color.R.ToString(), "144");

// Verify that the Green component of the background color is 238
Assert.AreEqual(background.Color.G.ToString(), "238");

// Verify that the Blue component of the background color is 144
Assert.AreEqual(background.Color.B.ToString(), "144");


If you need further assistance or have any additional questions, please feel free to reach out.

Regards,
Ivaylo
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
WPF Testing
Asked by
Sreelakshmi
Top achievements
Rank 1
Iron
Iron
Answers by
Elena
Telerik team
Ivaylo
Telerik team
Share this question
or