buchhalter-ai / buchhalter-ai-cli

The buchhalter open-source command line tool to automate invoice downloads from suppliers. Free, customizable, and designed for seamless financial workflow integration.
https://buchhalter.ai
Other
4 stars 1 forks source link

Extend "when" step property to support checking of elements #43

Open andygrunwald opened 6 months ago

andygrunwald commented 6 months ago

We need this to check if an element exists and a step should be executed or not.

example code:

 "when": {
        "exists": "#app_totp"
      }

Example (github recipe):

{
  "provider": "github",
  "domains": [
    "github.com"
  ],
  "type": "browser",
  "steps": [
    {
      "action": "open",
      "url": "https://github.com/login",
      "description": "Open the login page."
    },
    {
      "action": "type",
      "selector": "#login_field",
      "value": "{{ username }}",
      "description": "Insert login email."
    },
    {
      "action": "type",
      "selector": "#password",
      "value": "{{ password }}",
      "description": "Insert password."
    },
    {
      "action": "click",
      "selector": "//input[@type='submit']",
      "description": "Click on continue."
    },
    {
      "action": "waitFor",
      "selector": "#app_totp",
      "description": "Wait for the 2FA code input field.",
      "when": {
        "url": "https://github.com/sessions/two-factor/app"
      }
    },
    {
      "action": "type",
      "selector": "#app_totp",
      "value": "{{ totp }}",
      "description": "Insert the 2FA code (if required)",
      "when": {
        "url": "https://github.com/sessions/two-factor/app"
      }
    },
    {
      "action": "waitFor",
      "selector": "//input[@value='Remind me later' or @value='Ask me later']",
      "description": "Wait for security settings screen",
      "when": {
        "url": "https://github.com/sessions/trusted-device"
      }
    },
    {
      "action": "click",
      "selector": "//input[contains(., 'me later')]",
      "description": "Click remind me later or ask me later button",
      "when": {
        "url": "https://github.com/sessions/trusted-device"
      }
    },
    {
      "action": "waitFor",
      "selector": "//a[@href='/logout']",
      "description": "Wait for logout link"
    },
    {
      "action": "open",
      "url": "https://github.com/account/billing/history",
      "description": "Open the billing history page."
    },
    {
      "action": "downloadAll",
      "selector": "//a[contains(@id,'download-receipt')]",
      "description": "Download all invoices."
    }
  ]
}
andygrunwald commented 1 month ago

Usecase: When you login into GitHub, sometimes a "Is your phone number up to date?" or "Are your 2FA settings still the way to go?". In these forms, the URL is not changing.

This can be tested via the Github recipe:

{
  "supplier": "github",
  "domains": [
    "github.com"
  ],
  "type": "browser",
  "steps": [
    {
      "action": "open",
      "url": "https://github.com/login",
      "description": "Open the login page."
    },
    {
      "action": "type",
      "selector": "#login_field",
      "value": "{{ username }}",
      "description": "Insert login email."
    },
    {
      "action": "type",
      "selector": "#password",
      "value": "{{ password }}",
      "description": "Insert password."
    },
    {
      "action": "click",
      "selector": "//input[@type='submit']",
      "description": "Click on continue."
    },
    {
      "action": "waitFor",
      "selector": "#app_totp",
      "description": "Wait for the 2FA code input field.",
      "when": {
        "url": "https://github.com/sessions/two-factor/app"
      }
    },
    {
      "action": "type",
      "selector": "#app_totp",
      "value": "{{ totp }}",
      "description": "Insert the 2FA code (if required)",
      "when": {
        "url": "https://github.com/sessions/two-factor/app"
      }
    },
    {
      "action": "waitFor",
      "selector": "//input[@value='Remind me later' or @value='Ask me later']",
      "description": "Wait for security settings screen",
      "when": {
        "url": "https://github.com/sessions/trusted-device"
      }
    },
    {
      "action": "click",
      "selector": "//input[contains(., 'me later')]",
      "description": "Click remind me later or ask me later button",
      "when": {
        "url": "https://github.com/sessions/trusted-device"
      }
    },
    {
      "action": "waitFor",
      "selector": "//a[@href='/logout']",
      "description": "Wait for logout link"
    },
    {
      "action": "open",
      "url": "https://github.com/account/billing/history",
      "description": "Open the billing history page."
    },
    {
      "action": "downloadAll",
      "selector": "//a[contains(@id,'download-receipt')]",
      "description": "Download all invoices."
    }
  ]
}