I need to make a script that checks if all h1 tags in a page are of a certain hex color. If they are not, test fails. What are the available options for doing this?
I'm using selenium with java
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.Sign up to join this community
It depends on how is the color displayed on each h1. Assuming it is on the style attribute:
String color = "background-color: #ff6347"; List<WebElement> allH1 = driver.findElements(By.cssSelector("h1")); Boolean allHaveExpectedColor = allH1.parallelStream() // Let's look at all elements in parallel allMatch( // Let's verify all of them match some condition elem -> // Given we are looking into a H1 element elem.getAttribute("style"). // Let's get the style attribute contains(color) // And check if it contains the color mark )); Assert.assertTrue(allHaveExpectedColor, "Some H1 does not have the expected color");
If the color is displayed some other way, you just need to change the lambda function.