taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

probe.py (2921B)


      1 # This file is part of GNU Taler
      2 # (C) 2026 Taler Systems S.A.
      3 #
      4 # GNU Taler is free software; you can redistribute it and/or modify it under the
      5 # terms of the GNU General Public License as published by the Free Software
      6 # Foundation; either version 3, or (at your option) any later version.
      7 #
      8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
      9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     10 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License along with
     13 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     14 """Poke at a running wallet one step at a time, printing what each step shows.
     15 
     16 Label discovery is most of the work in writing a scenario, and guessing from
     17 source is slower than looking.  Each invocation performs one action and dumps
     18 the resulting screen.
     19 
     20     python3 probe.py dump
     21     python3 probe.py tap Request
     22     python3 probe.py fill 1
     23     python3 probe.py back
     24     python3 probe.py uri 'taler+http://pay/...'
     25     SIM_SERIAL=emulator-5556 python3 probe.py dump
     26 """
     27 
     28 from __future__ import annotations
     29 
     30 import os
     31 import sys
     32 import time
     33 
     34 from device import Device
     35 from wallet import Wallet
     36 
     37 
     38 def show(dev: Device) -> None:
     39     screen = dev.dump()
     40     print(f"activity: {screen.activity}")
     41     for node in screen.labelled():
     42         print(f"  {node}")
     43     fields = screen.editable()
     44     print(f"editable fields: {len(fields)}")
     45     for node in fields:
     46         print(f"  FIELD {node}")
     47 
     48 
     49 def main() -> int:
     50     serial = os.environ.get("SIM_SERIAL", "emulator-5554")
     51     dev = Device(serial)
     52     app = Wallet(dev)
     53     args = sys.argv[1:] or ["dump"]
     54     op, rest = args[0], args[1:]
     55 
     56     if op == "dump":
     57         pass
     58     elif op == "home":
     59         app.home()
     60     elif op == "tap":
     61         dev.tap_text(rest[0], timeout=20)
     62         time.sleep(1.5)
     63     elif op == "fill":
     64         screen = dev.dump()
     65         fields = screen.editable()
     66         index = int(rest[1]) if len(rest) > 1 else 0
     67         if len(fields) <= index:
     68             print(f"no editable field {index} (found {len(fields)})")
     69             return 1
     70         dev.tap_node(fields[index])
     71         time.sleep(0.5)
     72         dev.type_text(rest[0])
     73         time.sleep(1.5)
     74     elif op == "back":
     75         dev.back()
     76         time.sleep(1.2)
     77     elif op == "scroll":
     78         dev.scroll(down=(not rest or rest[0] != "up"), screen=dev.dump())
     79         time.sleep(1.2)
     80     elif op == "uri":
     81         app.handle_uri(rest[0])
     82         time.sleep(2)
     83     elif op == "settings":
     84         app.open_settings()
     85     elif op == "fresh":
     86         app.fresh_start(dev_mode=True)
     87     elif op == "enter":
     88         dev.key("KEYCODE_ENTER")
     89         time.sleep(1.5)
     90     else:
     91         print(__doc__)
     92         return 2
     93     show(dev)
     94     return 0
     95 
     96 
     97 if __name__ == "__main__":
     98     raise SystemExit(main())