theintern / intern

A next-generation code testing stack for JavaScript.
https://theintern.io/
Other
4.36k stars 311 forks source link

Allow browser console logs to be retrieved for unit tests #1144

Open jason0x43 opened 4 years ago

jason0x43 commented 4 years ago

Intern should provide an easy way to retrieve logs from remote test sessions.

Requirements

How to retrieve logs

There are a couple ways to implement this. The webdriver API provides a getLogsFor method to retrieve logs. Intern could call that on a session suite when the session is completed to retrieve logs before closing the remote. That method isn't part of the WebDriver spec, though, so it may not be supported in all browsers.

Another option would be for Intern to override the console methods to capture them and send them back to the host. This is probably the better solution because it provides Intern finer control over what is captured and allows logs to be sent back to the host immediately rather than at the end of a test or session.

If the second option is implemented, logs could be emitted as events on the Intern host as they are received.

Configuration

Log capture should be disabled by default, both to minimize the performance impact (there may be a lot of log data) and to prevent intern from breaking any pre-existing modifications to the browser logging system.

Intern should provide config options allowing logging to be enabled on a session-specific basis and allowing logs to be captured to files. The example below is one possible way to handle the config:

{
  // Capture all log levels for all environments
  "captureConsole": true,

  "output": {
    // By default, logs will be captured and emitted as local events. Use a
    // remoteLogs output option to specify a location to save logs to a file.
    "remoteConsole": {
      // Dir to store console messages
      "dir": "logs",
      // If true, show console messages in Intern's output as they are received
      "show": true
    }
  },

  "environments": [
    {
      "browserName": "chrome",
      // Use "intern" capability group for Intern-specific config
      "intern": {
        // only capture info and warn logs
        "captureConsole": ["info", "warn"]
      }
  ]
}
shashanksjSSJ commented 1 year ago

Hello 😁, I am a beginner to open source contributions, It would ne great if I could solve this issue.