0

我目前使用Chrome性能分析API獲取代碼覆蓋率,如下所示。Chrome遠程調試端口使用情況,用於使用Webdriverio進行Chrome性能分析

但每當我試着運行測試,我得到以下錯誤

Error: unexpected server response (404) at ClientRequest.response (/Users/svg7/projects/examples/build/js/testSuites.js:8419:16) at ClientRequest.g (events.js:291:16) at emitOne (events.js:96:13) at ClientRequest.emit (events.js:188:7) at HTTPParser.parserOnIncomingClient (_http_client.js:472:21) at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23) at Socket.socketOnData (_http_client.js:361:20) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:176:18)

代碼如下:

import * as fs from "fs"; 
import {createSession} from "chrome-debugging-client"; 

describe("Functional Coverage example", function() { 
this.timeout(880000); 
it("Get the coverage",() => { 
    createSession(async (session) => { 
     const api = await session.createAPIClient("localhost", 6813); 
     console.dir(api); 
     const tabs = await api.listTabs(); 
     const tab = tabs[0]; 
     console.log("====>"); 
     console.log(tab.webSocketDebuggerUrl); 
     // browser.stop(); 
     let client = await session.openDebuggingProtocol("http://localhost:6813"); 
     await client.send("Profiler.enable"); 
     await client.send("Page.enable"); 
     await client.send("Profiler.startPrecisionCoverage", {callCount: true}); 
     await client.send("Page.navigate", {url: "https://www.microsoft.com"}); 
     await new Promise((resolve) => client.on("Page.loadEventFired", resolve)); 
     await new Promise((resolve) => setTimeout(resolve, 10000)); 
     let result = await 
client.send("Profiler.takePrecisionCoverage"); 
     fs.writeFileSync("coverage.json", JSON.stringify(result, null, 2)); 
    }). catch(err => { 
     console.error(err); 
    }); 
}); 

    after(() => { 
    }); 
}); 

步驟我走:

  1. 通過啓動瀏覽器;
  2. 運行測試。

回答

0

我剛剛得到同樣的問題。 似乎有是標籤一個調試器鏈接,所以只需更換:

session.openDebuggingProtocol("http://localhost:6813")

通過

session.openDebuggingProtocol(tab.webSocketDebuggerUrl);