Botium脚本内存变量存储与响应匹配报错问题求助
Let's work through your two Botium problems step by step—these are common pitfalls, so I’ve got some concrete fixes for you:
1. Fixing Variable Capture Failure (TranscriptError)
You’re trying to capture the 99 value into $id but Botium isn’t matching your expected $id | This is a test pattern. Here’s what’s going wrong and how to fix it:
Correct the variable capture syntax: Botium uses
{{$VARNAME=REGEX_PATTERN}}to define variable captures in expected responses, not just$VARNAME. Your expected line should look like this:#bot {{$id=\d+}} | This is a testThe
\d+regex matches any numeric value (like 99), and Botium will store it in the$idvariable for later use.Verify memory is properly enabled: While you set
export BOTIUM_ENABLE_MEMORY=true, Botium prioritizes config file settings over environment variables. Double-check yourbotium.jsonhas:"SCRIPTING_ENABLE_MEMORY": trueThis ensures script-level memory variables are active.
Confirm environment variable scope: If you ran
exportin one terminal then opened a new one to runsudo botium-cli run mochawesome, the environment variable won’t carry over. Either re-run theexportcommand in the same terminal, or add the setting directly tobotium.jsonfor reliability.Update Botium CLI: Outdated versions sometimes have memory variable bugs. Run this to get the latest:
sudo npm install -g botium-cli
2. Fixing Regex SyntaxError for Special Character Responses
Your bot’s response includes asterisks and newlines, which are breaking regex matching. Even after removing asterisks, you’re still hitting errors—here’s how to resolve this:
Escape special regex characters: If you’re using the default
regexmatching mode, characters like*,., and newlines need to be escaped. For your original response, the expected line should look like this (note the escaped\*and\n):#bot {{/^\*Hier sind deine Erinnerungen:\*\n\nKeine Notizen, oder alles erledigt\.$/}}The
{{/ /}}wrapper tells Botium this is a regex pattern.Try wildcard matching instead: If regex feels too cumbersome, switch to wildcard mode in
botium.json:"SCRIPTING_MATCHING_MODE": "wildcard"In wildcard mode,
*acts as a placeholder, so to match the actual asterisks in your response, escape them with\:#bot \*Hier sind deine Erinnerungen:\*\n\nKeine Notizen, oder alles erledigt.Check what Botium actually receives: Use the verbose log to confirm the exact response Botium is getting. Sometimes there are hidden spaces, extra newlines, or the response is a full JSON object (not just the
fulfillmentTextcontent). If it’s the full JSON, adjust your expected response to match the entire structure, or configure your Botium connector to extract just thefulfillmentTextvalue.Avoid raw JSON in expectations: If your connector is already extracting the
fulfillmentText(most do by default), don’t include the surrounding{'fulfillmentText': '...'}in your expected line—just use the text inside the quotes.
内容的提问来源于stack exchange,提问作者ToWy

