Last active
November 3, 2020 12:40
-
-
Save ShamaUgale/f126f42dea806bceddf7425d2f9713ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.devtools; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.devtools.DevTools; | |
import org.openqa.selenium.devtools.performance.Performance; | |
import org.openqa.selenium.devtools.performance.model.Metric; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class GetMetrics { | |
final static String PROJECT_PATH = System.getProperty("user.dir"); | |
public static void main(String[] args){ | |
System.setProperty("webdriver.chrome.driver", PROJECT_PATH + "/src/main/resources/chromedriver"); | |
ChromeDriver driver = new ChromeDriver(); | |
DevTools devTools = driver.getDevTools(); | |
devTools.createSession(); | |
devTools.send(Performance.enable()); | |
driver.get("https://www.google.org"); | |
List<Metric> metrics = devTools.send(Performance.getMetrics()); | |
List<String> metricNames = metrics.stream() | |
.map(o -> o.getName()) | |
.collect(Collectors.toList()); | |
devTools.send(Performance.disable()); | |
List<String> metricsToCheck = Arrays.asList( | |
"Timestamp", "Documents", "Frames", "JSEventListeners", | |
"LayoutObjects", "MediaKeySessions", "Nodes", | |
"Resources", "DomContentLoaded", "NavigationStart"); | |
metricsToCheck.forEach( metric -> System.out.println(metric + | |
" is : " + metrics.get(metricNames.indexOf(metric)).getValue())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment