Robot Framework

การใช้ Run Keyword And Return Status ใน Robot Framework

Run Keyword And Return Status

ใน Robot Framework สามารถใช้คำสั่ง Run Keyword And Return Status เพื่อเรียกใช้ฟังก์ชันหรือ Keyword อื่นๆ และคืนค่าสถานะการทำงานของฟังก์ชันนั้น ซึ่งสามารถใช้ในการตรวจสอบความถูกต้องและประเมินผลลัพธ์ของการทำงาน ดังตัวอย่างต่อไปนี้:

*** Test Cases ***
Example Test Case
    ${status}    Run Keyword And Return Status    Keyword To Test
    Should Be Equal    ${status}    PASS    # Check the return status

ในตัวอย่างนี้ คำสั่ง Run Keyword And Return Status จะเรียกใช้ Keyword ที่ชื่อว่า Keyword To Test และคืนค่าสถานะการทำงานของ Keyword นั้น ในตัวแปร ${status} จากนั้นคำสั่ง Should Be Equal จะใช้เพื่อตรวจสอบว่าค่าของ ${status} ตรงกับ PASS หรือไม่.

นอกจาก Run Keyword And Return Status นี้แล้ว Robot Framework ยังมีคำสั่งอื่นๆ เช่น Run Keyword And Continue On Failure ซึ่งจะทำงานเหมือน Run Keyword And Return Status แต่หาก Keyword ที่เรียกใช้ล้มเหลวจะทำงานต่อไปตาม Test Case อยู่แทนที่จะสิ้นสุดการทำงานทันที

*** Test Cases ***
Example Test Case
    Run Keyword And Continue On Failure    Keyword To Test
    Log    Keyword To Test has finished execution

ในตัวอย่างนี้ คำสั่ง Run Keyword And Continue On Failure จะเรียกใช้ Keyword ที่ชื่อว่า Keyword To Test และหาก Keyword นั้นล้มเหลว คำสั่ง Log จะยังคงทำงานและแสดงข้อความว่า Keyword นั้นเสร็จสิ้นการทำงาน.

Patter S

You may also like

Robot Framework

วิธีใช้ Screenshots ใน Robot Framework

การใช้งานฟีเจอร์ Screenshots ใน Robot Framework เป็นวิธีที่ดีในการสร้างเอกสารและรายงานทดสอบ มันช่วยให้เราเห็นถึงสถานะของ UI ในขณะที่การทดสอบกำลังดำเนินการ หรือในระหว่างการตรวจสอบข้อผิดพลาด มาดูวิธีการใช้งานฟีเจอร์นี้กัน ขั้นตอนที่ 1: ...
Robot Framework

วิธีใช้ Execute Java Script ใน Robot Framework

ใน Robot Framework คุณสามารถใช้คำสั่ง “Execute JavaScript” ในการรัน JavaScript ได้ วิธีนี้เป็นวิธีที่ดีในการทำงานกับ elements บนหน้าเว็บหรือรันสคริปต์ที่มีความซับซ้อนเพิ่มขึ้น โดยเฉพาะกับการทดสอบ ...

Leave a reply

Your email address will not be published. Required fields are marked *

Robot Framework

Keywords ใน Robot Framework คืออะไร

Keyword ใน Robot Framework เป็นส่วนหนึ่งที่สำคัญสำหรับการทดสอบ เพราะว่า Keyword จะช่วยให้คุณสามารถแบ่งแยกการทำงานของ Test Case เป็นส่วนๆ ย่อยๆ และสามารถใช้ ...
Robot Framework

Variables ใน Robot Framework คืออะไร

Robot Framework มีการจัดการตัวแปรที่หลากหลายและง่ายต่อการใช้งาน ซึ่งสามารถประกาศและใช้ตัวแปรได้ในทุกส่วนของ Test Case หรือ Keyword ต่างๆ ดังตัวอย่างต่อไปนี้: ในตัวอย่างนี้ ตัวแปร ${test_variable} ...