Apply Java 8 features in Test Automation - Scenario 1
Jaba 8 has a lot of new features. In this blog series, we will see how to apply these features in Test Automation both UI and service. Instead of theory, I will show the feature in the form of a Challenge or a problem statement.
Challenge:- How to get the list of the links which are not empty from google.com. Also, print the names of the link in uppercase and count of these links?
WebDriverManager.chromedriver().setup();
WebDriver driver = ChromeDriver();
driver.get("http://www.google.com");
Thread.sleep(5000); // I know bad practice :)
List<WebElement> lists=driver.findElements(By.tagName("a"));
int count= (int) lists.stream()
.filter(e -> !e.getText().isEmpty())
.map(e-> e.getText().toUpperCase())
.peek(a -> System.out.println(a))
.count();
System.out.println("count of links "+ count);
driver.quit();
Comments
Post a Comment