Skip to content

fluent-qa/fluentqa-helper

Repository files navigation

FluentQA Simple Capture

For Some Reason,I want to try to capture API to generate tests, but don't want to spend too much time on this.

What I want:

  • Use as less code as you can to capture API request to database for automation code generation.
  • A simple UI to do the proxy setting and start capturing API Request.

Finally, after doing some research,I completed it in one day. Features:

  1. cli to start mitmproxy and plugin
  2. cli to reset proxy
  3. ui to start mitmproxy,plugin and reset proxy

Commandline Features:

  • Use mitmproxy to capture API request:
poetry run qacli capture start --name="scenario_name"

start.png

  • Capture API Request Based on Configuration: configs/settings.toml

captured URL setting: all request to www.baidu.com and www.bing.com will save to database

mitm = { recorded_url = "https://www.baidu.com,https://www.bing.com" }
  • all api request and response in database, table fields:
class ApiMonitorRecord(SQLModel, table=True):
    __tablename__ = "api_monitor_record"

    id: Optional[int] = Field(default=None, primary_key=True)
    app: Optional[str] = None
    service: Optional[str] = None
    api: Optional[str] = None
    path: Optional[str] = None
    request_url: Optional[str] = None
    method: Optional[str] = None
    request_headers: Optional[str] = None
    request_body: Optional[str] = None
    response_headers: Optional[str] = None
    status_code: int
    response_body: Optional[str] = None
    scenario_name: Optional[str] = None
  • turn on/off proxy setting in MAC
 poetry run qacli mac-proxy --help
                                                                                                                                                         
 Usage: qacli mac-proxy [OPTIONS] COMMAND [ARGS]...                                                                                                      
                                                                                                                                                         
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ off                  disable api capture proxy                                                                                                        │
│ on                   enable api capture proxy 
  • capture/record in CLI manner
❯ poetry run qacli capture --help

api recorder initialized ....
                                                                                                                                                                                                                   
 Usage: qacli capture [OPTIONS] COMMAND [ARGS]...                                                                                                                                                                  
                                                                                                                                                                                                                   
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                                                                                                                                                     │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ start                                                  capture api                                                                                                                                              │
│ stop                                                   stop capture api                                                                                                                                         │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

UI Feature

poetry run qaui

qaui.png

  • input capture name: any name your want
  • start to capture API request
  • Query Database to get all the request you want
select * from api_monitor_record where scenario_name=<your_record_name>
  • export or do some changes for your automation testing

To Do

References

Releases

No releases published

Packages

No packages published

Languages