jeudi 19 avril 2018

Using trace logs with geckodriver. How do I output to a file?

I have enabled trace logs on my TestNG tests, to see if I can track errors reported in the browser console, such as Status 500 errors.

I have added this to my driver initialization:

    private static WebDriver getFirefoxDriver() {
    Common.myPrint(thisClass + " Get Firefox Driver.");
    Common.printLine();
    String filename = driverFolder + "geckodriver.exe";
    // check file exists
    File f = new File(filename);
    if (f.exists() && !f.isDirectory()) {
        Common.myPrint(thisClass + " " + filename + " exists.\n" );

        System.setProperty("webdriver.gecko.driver", filename);

        FirefoxOptions options = new FirefoxOptions()
                .addPreference("browser.tabs.remote.autostart", false)
                .addPreference("security.sandbox.content.level", 5);

        // Enable Trace Logs. See: https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/TraceLogs.html

        if(global.variables.trace) {
            options.setLogLevel(FirefoxDriverLogLevel.TRACE);
        }

        driver = new FirefoxDriver(options);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        Common.myPrint("\n" + thisClass + " driver details " + driver.toString());

        setDriver();

        SessionId sessionId = ((FirefoxDriver) driver).getSessionId();

        Common.myPrint("\n" + thisClass + " *** Session id: " + sessionId.toString());

        return driver;
    } else {
        int errorCode = 1524141872;
        System.err.println(thisClass + " error code: " + errorCode +" Error getting firefox driver. " + filename + " could not be found.");
        return null;
    }
}

Is there any way I can make this trace output print to a file?

My Common.myPrint does just that with standard System.out.println command.

The problem is, with the trace output, the printout is so big, half of it gets truncated, and it makes no sense whatsoever on it's own without my own debugging lines.

Aucun commentaire:

Enregistrer un commentaire