Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement AxeResult.ToString based on JsonConvert #75

Merged
merged 5 commits into from
Oct 14, 2022

Conversation

dbjorge
Copy link
Contributor

@dbjorge dbjorge commented Oct 11, 2022

Details

This PR adds in a basic ToString implementation for AxeResult and AxeResultItem that just uses JsonConvert.SerializeObject.

The motivation for this is that these types are likely to be used in users' test assertions; when an assertion related to them fails, we want the test output to be actionable.

I wanted to reuse the same JsonSerializerSettings as everywhere else in the Selenium package, so I extracted it out of AxeBuilder (and several tests that repeated bits of it) into a AxeJsonSerializerSettings static class in the commons package. I think this is a better home for the serializer settings anyway, since they're tightly coupled to the implementation of the types.

The test addition will have a merge conflict to resolve with #74, which adds overlapping unit tests that share the same sample input JSON.

Example output of AxeResult.ToString() using the pinned sample input from the new unit test:

{
  "violations": [
    {
      "id": "document-title",
      "description": "Ensures each HTML document contains a non-empty <title> element",
      "help": "Documents must have <title> element to aid in navigation",
      "helpUrl": "https://dequeuniversity.com/rules/axe/4.4/document-title?application=axe-puppeteer",
      "impact": "serious",
      "tags": [
        "cat.text-alternatives",
        "wcag2a",
        "wcag242",
        "ACT"
      ],
      "nodes": [
        {
          "target": "html",
          "xPath": "/html",
          "ancestry": null,
          "html": "<html><head></head><body>\n</body></html>",
          "impact": "serious",
          "any": [
            {
              "data": null,
              "id": "doc-has-title",
              "impact": "serious",
              "message": "Document does not have a non-empty <title> element",
              "relatedNodes": []
            }
          ],
          "all": [],
          "none": []
        }
      ]
    }
  ],
  "passes": [],
  "inapplicable": [],
  "incomplete": [],
  "timestamp": "2000-01-02T03:04:05.006+00:00",
  "testEnvironment": {
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/100.0.4889.0 Safari/537.36",
    "windowWidth": 800,
    "windowHeight": 600,
    "orientationType": "portrait-primary",
    "orientationAngle": 0.0
  },
  "testRunner": {
    "name": "axe"
  },
  "url": "http://localhost/",
  "error": null,
  "testEngineName": "axe-core",
  "testEngineVersion": "4.4.1",
  "toolOptions": {
    "xpath": true,
    "runOnly": {
      "type": "rule",
      "values": [
        "document-title"
      ]
    },
    "reporter": "v1"
  }
}

Copy link
Collaborator

@lisli1 lisli1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michael-siek
Copy link
Member

  • reviewed for security

@michael-siek michael-siek merged commit ab63d59 into dequelabs:develop Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants