eWert-Online / OSnap

OSnap is a snapshot testing tool, which mainly focuses on speed and ease of use.
https://ewert-online.github.io/OSnap/
152 stars 2 forks source link

[Feature] Functions in Test #5

Closed l-mbert closed 2 years ago

l-mbert commented 3 years ago

I would like functions in OSnap as a way to trigger repetitive tasks in tests. (e.g. dismissing a CookieConsent-Box). Adding this again and again could be hard to maintain for users and it could be prone to errors.

As of API-Design I think adding a new key called functions or actions:

./osnap.config.json

{
  "functions": {
      "dismissCookieConsent": [
        { "action": "click", "selector": "#cookieconsent .settings" },
        { "action": "click", "selector": "#cookieconsent .ga-disable" },
        { "action": "click", "selector": "#cookieconsent .accept" },
        { "action": "wait", "timeout": 250 }
      ]
    }
}

so we could use it in a Test like this:

./random-test.osnap.json

[
  {
    "name": "Home",
    "url": "/",
    "actions": [
      { "action": "function", "name": "dismissCookieConsent" },
      { "action": "type", "selector": "#search", "text": "some text to type" },
      { "action": "click", "selector": "#id .class" },
      { "action": "wait", "timeout": 2000 }
    ]
  }
]

This would simplify maintaining and using OSnap since we can change the declaration of the function and not change all of our tests to match.

eWert-Online commented 2 years ago

This will be in the next release 🎉