小编典典

Selenium-Chrome性能日志不起作用

selenium

嗨,我有一个selenium脚本运行,应该给我性能日志。我有一个方法“ printLog”,应该(显然)打印性能日志。我的代码将能够准确地深入解释我要做什么。

static void printLog(String type, RemoteWebDriver driver, String inputURL)  {

    ChromeOptions cap = new ChromeOptions();
    LoggingPreferences logP = new LoggingPreferences();
    logP.enable(LogType.PERFORMANCE, Level.ALL);
    cap.setCapability(CapabilityType.LOGGING_PREFS, logP);

    List<LogEntry> entries = driver.manage().logs().get(type).getAll();
    System.out.println("\"Input URL\"," + "\"" + inputURL + "\"");
    for (LogEntry entry : entries) {
        // Checks whether this is a webtrends tag and whether it was accepted by the
        // server

        if (entry.getMessage().contains("statse") && entry.getMessage().contains("Network.responseReceived")) {
            String statseString = entry.getMessage();
            // regex for finding all wt tags: WT\..+?(?=&)
            // List<String> allMatches = new ArrayList<String>();
            // Matcher m = Pattern.compile("WT\\..+?(?=&)")
            // .matcher(statseString);
            // while (m.find()) {
            // allMatches.add(m.group());
            // }
            int statseBegin = statseString.indexOf("\"url\":\"") + 1;
            int statseEnd = statseString.indexOf("\"},\"", statseBegin);
            statseString = statseString.substring(statseBegin, statseEnd);
            String[] allMatches = statseString.split("&");
            for (String tags : allMatches) {
                tags = tags.replaceFirst("=", "ReallyLongUniqueStringWithNoChanceOfOverlap");
                String tagParts[] = tags.split("ReallyLongUniqueStringWithNoChanceOfOverlap");

                if (tagParts.length > 1) {
                    System.out.println("\"" + tagParts[0] + "\",\"" + tagParts[1] + "\"");
                } else {
                    System.out.println("\"" + tagParts[0] + ",\"\"");
                }
            }
        }
    }
}

当我运行代码时,Chrome打开,我在控制台中得到以下堆栈跟踪:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown 
error: log type 'performance' not found
(Session info: chrome=69.0.3497.92)
(Driver info: chromedriver=2.42.591088 
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.16299 
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05- 
08T15:15:03.216Z'
System info: host: 'WKSP0009ADAD', ip: '172.17.237.35', os.name: 'Windows 
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, 
applicationCacheEnabled: false, browserConnectionEnabled: false, 
browserName: chrome, chrome: {chromedriverVersion: 2.42.591088 
(7b2b2dca23cca0..., userDataDir: C:\Users\BPJ0sGW\AppData\Lo...}, 
cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: 
{debuggerAddress: localhost:50809}, handlesAlerts: true, hasTouchScreen: 
false, javascriptEnabled: true, locationContextEnabled: true, 
mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: 
false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: 
false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, 
unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 
69.0.3497.92, webStorageEnabled: true, webdriver.remote.sessionid: 
f50e54d130a8c7e3b3a9cb6984f...}
Session ID: f50e54d130a8c7e3b3a9cb6984fcb558
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAcc 
essorImpl.java:62)
atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstr 
uctorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
atorg.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:
atorg.openqa.selenium.remote.RemoteLogs.getRemoteEntries(RemoteLogs.java:81)
at org.openqa.selenium.remote.RemoteLogs.get(RemoteLogs.java:77)
at demoJenkins.WebTrendsCapture.printLog(WebTrendsCapture.java:141)
at demoJenkins.WebTrendsCapture.main(WebTrendsCapture.java:114)

我可以根据要求提供更多详细信息,但基本上我只是想弄清楚为什么该方法返回此错误。谢谢。


阅读 845

收藏
2020-06-26

共1个答案

小编典典

https://github.com/seleniumhq/selenium-google-code-issue-
archive/issues/8386通过@Kiril小号,这似乎用RemoteWebDriver时才会发生。使用纯ChromeDriver对象即可。

2020-06-26