LaVOZs

The World’s Largest Online Community for Developers

'; java - Selenium - output system logs to text file - LavOzs.Com

Im trying to get the network logs output to a text file, I have network log starting but i cant figure out how to output it to a text file

I have the below code but im not sure how to export it to a text file

            DesiredCapabilities caps = DesiredCapabilities.chrome();
            LoggingPreferences logPrefs = new LoggingPreferences();
            logPrefs.enable(LogType.BROWSER, Level.ALL);
            caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

Try this:

Logs logs = driver.manage().logs();
LogEntries logEntries = logs.get(LogType.DRIVER); // or other logType

List<String> lines = logEntries.getAll().stream().map(LogEntry::toString).collect(Collectors.toList());

//Write data to some file.
Files.write(Paths.get("someFile"), lines);
Related
In Java, what is the best way to determine the size of an object?
How to really read text file from classpath in Java
How do I create a file and write to it in Java?
How to avoid Java code in JSP files?
How to take screenshot with Selenium WebDriver
Reading a plain text file in Java
Can't start Eclipse - Java was started but returned exit code=13
How do I find an element that contains specific text in Selenium Webdriver (Python)?
saving the logs in text file which gets generated in selenium webdriver
Selenium using Python - Geckodriver executable needs to be in PATH