275 lines
12 KiB
Python
275 lines
12 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate fully-concrete admin Maestro flows (no runFlow env anywhere).
|
|
|
|
runFlow `file:` + `env:` does not propagate in this Maestro version, so every
|
|
parameterised step is inlined here with literal values. Static subflows
|
|
(login, confirm-open, pick-image-ios) are referenced as ../subflows/*.
|
|
|
|
Env in: STAMP, STORE1/2, P1, P2, COMBO, TAG1/2, STAFF_ID, STORE1_ID, STORE2_ID.
|
|
Out: gen/admin-stores.yaml, gen/admin-product-p1.yaml, gen/admin-product-p2.yaml,
|
|
gen/admin-combo.yaml, gen/admin-tags.yaml
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
E = os.environ
|
|
STAMP = E['STAMP']
|
|
STORE1, STORE2 = E['STORE1'], E['STORE2']
|
|
P1, P2, COMBO = E['P1'], E['P2'], E['COMBO']
|
|
TAG1, TAG2 = E['TAG1'], E['TAG2']
|
|
STAFF_ID = E.get('STAFF_ID', '')
|
|
STORE1_ID, STORE2_ID = E.get('STORE1_ID', ''), E.get('STORE2_ID', '')
|
|
MODE = sys.argv[1] if len(sys.argv) > 1 else 'all' # 'stores' | 'products' | 'combo-tags' | 'all'
|
|
|
|
OUT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'gen')
|
|
os.makedirs(OUT, exist_ok=True)
|
|
|
|
ADMIN_APP = 'in.freshyo.adminui'
|
|
|
|
|
|
def head(tags):
|
|
# write() adds the appId/--- header; this returns opening steps only.
|
|
return [
|
|
'- launchApp',
|
|
'- extendedWaitUntil:',
|
|
" visible:",
|
|
" id: 'login-name-input|add-product-menu-item'",
|
|
' timeout: 120000',
|
|
'- runFlow:',
|
|
' when:',
|
|
' visible:',
|
|
' id: login-name-input',
|
|
' commands:',
|
|
' - runFlow: ../subflows/login.yaml',
|
|
]
|
|
|
|
|
|
def confirm_open(link):
|
|
return [f'- openLink: {link}', '- runFlow: ../subflows/confirm-open.yaml']
|
|
|
|
|
|
|
|
def sc(element_id, direction='DOWN', center=True):
|
|
"""One self-contained scrollUntilVisible step (single YAML string)."""
|
|
s = ('- scrollUntilVisible:\n element:\n id: ' + element_id +
|
|
'\n direction: ' + direction + '\n speed: 100' +
|
|
'\n visibilityPercentage: 60')
|
|
if center:
|
|
s += '\n centerElement: true'
|
|
return s
|
|
|
|
def select_option(dd, opt):
|
|
"""Inline single-select pick with sheet-settle + backdrop fallback."""
|
|
return [
|
|
sc(dd),
|
|
f'- tapOn:\n id: {dd}',
|
|
'- waitForAnimationToEnd',
|
|
# NOTE: no centering inside bottom sheets — short option lists cannot
|
|
# scroll-to-center and the scroll would fail.
|
|
sc(f'{dd}-option-{opt}', center=False),
|
|
# Settle: tapping while the sheet is still centering lands on the
|
|
# backdrop, closing the sheet with nothing selected (silent owner-less
|
|
# submits downstream).
|
|
'- waitForAnimationToEnd',
|
|
f'- tapOn:\n id: {dd}-option-{opt}',
|
|
'- waitForAnimationToEnd',
|
|
'- runFlow:',
|
|
' when:',
|
|
' visible:',
|
|
f' id: {dd}-option-{opt}',
|
|
' commands:',
|
|
' - tapOn:\n point: 50%,15%',
|
|
' - extendedWaitUntil:',
|
|
' notVisible:',
|
|
f' id: {dd}-option-{opt}',
|
|
' timeout: 10000',
|
|
]
|
|
|
|
|
|
def fill_input(test_id, text):
|
|
# Clipboard-paste (not keystroke) entry: immune to keystroke races and
|
|
# iOS autocorrect rewrites. Double settle: the first wait can return
|
|
# before the keyboard slide-up animation starts; the second catches it.
|
|
# (Freshly-rendered cards shift layout when the keyboard opens; typing
|
|
# too early loses keystrokes.)
|
|
return [
|
|
f'- tapOn:\n id: {test_id}',
|
|
'- waitForAnimationToEnd',
|
|
'- waitForAnimationToEnd',
|
|
'- eraseText',
|
|
f'- setClipboard: {text}',
|
|
'- pasteText',
|
|
'- pressKey: Enter',
|
|
]
|
|
|
|
|
|
def fill_variant(v, qty, price, mrp, offer, image):
|
|
steps = []
|
|
steps += [sc(f'variant-{v}-attr-0-value', 'DOWN')]
|
|
steps += fill_input(f'variant-{v}-attr-0-value', qty)
|
|
steps += [sc(f'variant-{v}-price', 'DOWN')]
|
|
steps += fill_input(f'variant-{v}-price', price)
|
|
steps += [sc(f'variant-{v}-market-price', 'DOWN')]
|
|
steps += fill_input(f'variant-{v}-market-price', mrp)
|
|
if offer:
|
|
steps += [sc(f'variant-{v}-offer', 'DOWN'),
|
|
f'- tapOn:\n id: variant-{v}-offer']
|
|
if image:
|
|
steps += [sc(f'variant-{v}-image-add', 'DOWN'),
|
|
f'- tapOn:\n id: variant-{v}-image-add',
|
|
'- runFlow: ../subflows/pick-image-ios.yaml']
|
|
return steps
|
|
|
|
|
|
def add_variant():
|
|
# NOTE: the header add-variant-button tap is unreliable (layout shift swallows
|
|
# it); the footer button always works (verified by experiment).
|
|
return [sc('add-variant-button-footer', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: add-variant-button-footer',
|
|
'- waitForAnimationToEnd']
|
|
|
|
|
|
def submit_create(alert):
|
|
return [sc('create-product-button', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: create-product-button',
|
|
f"- assertVisible: '{alert}'", '- tapOn: OK']
|
|
|
|
|
|
def settle(text):
|
|
"""Insert waitForAnimationToEnd after every scrollUntilVisible block so
|
|
follow-up taps never land on a still-settling ScrollView (iOS swallows them)."""
|
|
pat = re.compile(r'(- scrollUntilVisible:\n(?: [^\n]+\n)+?)(?=- |\Z)')
|
|
|
|
def rep(m):
|
|
block = m.group(1)
|
|
if 'waitForAnimationToEnd' in block:
|
|
return block
|
|
return block + '- waitForAnimationToEnd\n'
|
|
|
|
return pat.sub(rep, text)
|
|
|
|
|
|
def write(name, steps, add_media=True):
|
|
lines = [f'# GENERATED by scripts/gen_flows.py — do not edit.', f'appId: {ADMIN_APP}', '---']
|
|
if add_media:
|
|
# Path relative to this generated file (gen/).
|
|
lines += ['- addMedia:', " - '../assets/test-product.png'"]
|
|
lines += steps
|
|
with open(os.path.join(OUT, name), 'w') as f:
|
|
f.write(settle('\n'.join(lines)) + '\n')
|
|
|
|
|
|
# ---- stores ----
|
|
if MODE in ('stores', 'all'):
|
|
steps = head(['stores'])
|
|
for name, desc in [(STORE1, f'Full-suite store one {STAMP}'), (STORE2, f'Full-suite store two {STAMP}')]:
|
|
steps += confirm_open('freshyoadmin://dashboard/stores/add')
|
|
steps += ['- extendedWaitUntil:', ' visible:', ' id: store-name-input', ' timeout: 30000']
|
|
steps += fill_input('store-name-input', name)
|
|
steps += fill_input('store-description-input', desc)
|
|
steps += select_option('store-owner-dropdown', STAFF_ID)
|
|
steps += [sc('store-submit-button', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: store-submit-button',
|
|
"- assertVisible: 'Store created successfully'", '- tapOn: OK']
|
|
write('admin-stores.yaml', steps, add_media=False)
|
|
|
|
# ---- products ----
|
|
def product_flow(name, store_id, ptype_opt, variants):
|
|
steps = head(['products'])
|
|
steps += ['- tapOn:', ' id: add-product-menu-item',
|
|
'- extendedWaitUntil:', ' visible:', ' id: product-name-input', ' timeout: 30000']
|
|
steps += fill_input('product-name-input', name)
|
|
steps += select_option('product-store-dropdown', store_id)
|
|
steps += select_option('product-type-dropdown', ptype_opt)
|
|
# NOTE: the all-regions checkbox was removed from the admin app (all-region
|
|
# products are managed from superadmin-ui only) — no scroll/assert here.
|
|
for i, (qty, price, mrp, offer, image) in enumerate(variants):
|
|
if i > 0:
|
|
steps += add_variant()
|
|
steps += fill_variant(i, qty, price, mrp, offer, image)
|
|
steps += submit_create('Product created successfully!')
|
|
return steps
|
|
|
|
if MODE in ('products', 'all'):
|
|
write('admin-product-p1.yaml',
|
|
product_flow(P1, STORE1_ID, 'item', [('500 g', '120', '150', False, True), ('1 kg', '220', '260', True, True)]))
|
|
write('admin-product-p2.yaml',
|
|
product_flow(P2, STORE2_ID, 'item', [('250 g', '60', '80', True, True), ('500 g', '110', '140', False, True),
|
|
('1 kg', '200', '250', True, True), ('5 kg', '950', '1100', False, True)]))
|
|
|
|
# ---- combo ----
|
|
if MODE in ('combo-tags', 'all'):
|
|
steps = head(['products'])
|
|
steps += ['- tapOn:', ' id: add-product-menu-item',
|
|
'- extendedWaitUntil:', ' visible:', ' id: product-name-input', ' timeout: 30000']
|
|
steps += fill_input('product-name-input', COMBO)
|
|
steps += select_option('product-store-dropdown', STORE1_ID)
|
|
steps += select_option('product-type-dropdown', 'combo')
|
|
steps += fill_variant(0, '1 pack', '299', '349', False, True)
|
|
for ci, sk in [(0, E.get('P1SK0', '')), (1, E.get('P2SK0', ''))]:
|
|
dd = f'variant-0-combo-sku-{ci}'
|
|
opt_id = f'{dd}-option-{sk}'
|
|
steps += [sc(f'variant-0-combo-add', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: variant-0-combo-add',
|
|
sc(dd),
|
|
'- waitForAnimationToEnd',
|
|
f'- tapOn:\n id: {dd}',
|
|
'- waitForAnimationToEnd',
|
|
# NOTE: this SKU dropdown has no search box and its rows expose
|
|
# only testIDs (no visible label text) — page the sheet with
|
|
# in-list drags until our SKU's option id is visible, then tap.
|
|
# Self-terminating; overshoot-safe (our SKUs sort last).
|
|
'- repeat:',
|
|
' times: 10',
|
|
' commands:',
|
|
' - runFlow:',
|
|
' when:',
|
|
' visible:',
|
|
f' id: {opt_id}',
|
|
' commands:',
|
|
f' - tapOn:\n id: {opt_id}',
|
|
' - swipe:',
|
|
' start: 50%,80%',
|
|
' end: 50%,30%',
|
|
' duration: 300',
|
|
'- waitForAnimationToEnd',
|
|
# The sheet must be gone (single-select closes it on pick).
|
|
'- assertNotVisible:\n text: SKU']
|
|
steps += submit_create('Product created successfully!')
|
|
write('admin-combo.yaml', steps)
|
|
|
|
if MODE in ('combo-tags', 'all'):
|
|
# ---- tags ----
|
|
steps = head(['tags'])
|
|
for tag, desc, pname in [(TAG1, f'Full-suite tag one {STAMP}', P1), (TAG2, f'Full-suite tag two {STAMP}', P2)]:
|
|
steps += confirm_open('freshyoadmin://dashboard/product-tags/add')
|
|
steps += ['- extendedWaitUntil:', ' visible:', ' id: tag-name-input', ' timeout: 30000']
|
|
steps += fill_input('tag-name-input', tag)
|
|
steps += fill_input('tag-description-input', desc)
|
|
steps += [sc('tag-dashboard-checkbox', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: tag-dashboard-checkbox']
|
|
steps += [sc('tag-products-selector', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: tag-products-selector',
|
|
'- tapOn:\n id: tag-products-selector-search',
|
|
'- waitForAnimationToEnd',
|
|
'- waitForAnimationToEnd',
|
|
f'- setClipboard: {pname}',
|
|
'- pasteText',
|
|
'- pressKey: Enter',
|
|
'- waitForAnimationToEnd',
|
|
"- tapOn:\n id: 'tag-products-selector-option-.*'\n index: 0",
|
|
'- tapOn:\n id: tag-products-selector-done']
|
|
steps += [sc('tag-submit-button', 'DOWN'),
|
|
'- waitForAnimationToEnd',
|
|
'- tapOn:\n id: tag-submit-button',
|
|
"- assertVisible: 'Tag created successfully'", '- tapOn: OK']
|
|
write('admin-tags.yaml', steps, add_media=False)
|
|
|
|
print('generated admin flows in gen/')
|