ลดหรือเพิ่มตัวแปรในกรอบงานหุ่นยนต์

ฉันแค่ต้องการลดตัวแปร N_groups ในบรรทัดสุดท้าย นี่คือไฟล์โรบอตของฉัน:

Preconditions - Delete Groups But Not First
    ${N_groups}    Setup Groups Count Groups
    Log to console    N_groups: ${N_groups}
    : FOR    ${INDEX}    IN RANGE    1    20
    \    Run Keyword If    '${N_groups}' == '1'    Exit For Loop
    \    Setup Groups Delete Group    ${group}
    \    ${N_groups}=    ${N_groups}-1

ฉันได้รับข้อผิดพลาด:

No keyword with name '${N_groups}-1' found.

ฉันทำอะไรผิดที่นี่?


person kame    schedule 28.01.2016    source แหล่งที่มา


คำตอบ (3)


ลองใส่ไว้ในชื่อ var ดูครับ เช่น.

${N_groups-1}
person shicky    schedule 28.01.2016
comment
นี่ไม่ใช่สัญชาตญาณ - person kame; 28.01.2016
comment
ใช่ ฉันจำได้ว่าเจออุปสรรคเดิมๆ เมื่อหลายเดือนก่อน จากการพัฒนา มันแค่รู้สึกผิด เหมือนฉันใช้ตัวแปรที่แตกต่างไปจากเดิมอย่างสิ้นเชิง แทนที่จะเปลี่ยนค่าของตัวแปร แต่ฉันเดาว่าไวยากรณ์ก็คือไวยากรณ์ - person shicky; 28.01.2016
comment
@kame: มันไม่ง่ายนัก แต่เป็นคุณสมบัติที่ได้รับการบันทึกไว้: robotframework.org /robotframework/ล่าสุด/ - person Bryan Oakley; 28.01.2016

หากตัวแปรเป็นตัวเลขอยู่แล้ว คุณสามารถใช้:

${N_groups}= ${N_groups-1}

ในการดำเนินการนี้ คุณต้องบังคับให้เป็นตัวเลข (ไม่เช่นนั้นคุณจะได้รับข้อผิดพลาดแจ้งว่า failed: TypeError: coercing to Unicode: need string or buffer, int found) เช่น

*** Variables *** ${N_groups}= ${0} # ${} notation coerces value to a number

หรือคุณสามารถใช้ Evaluate เช่นนี้ ซึ่งได้ผลไม่ว่า ${N_groups} จะถูกบังคับด้วยตัวเลขหรือไม่ก็ตาม:

${N_groups}= Evaluate ${N_groups} - 1

person qbert220    schedule 07.06.2017

ลองสิ่งนี้:

${decrement_counter}=  set variable   1

-- อยู่ภายในวง

${N_groups}=   Evaluate    ${N_groups} - ${decrement_counter}

หมายเหตุ - มีเพียงช่องว่างเดียวก่อนและหลังเครื่องหมายลบ

person Ashok Kakade    schedule 09.02.2021