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 SolidColorBrushvar 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.