Robot Framework

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

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

*** Keywords ***
Example Keyword
    Log    This is an example of a keyword.

*** Test Cases ***
Example Test Case
    Example Keyword
    Log    This is a test case.

ในตัวอย่างนี้ เราสร้าง Keyword ชื่อ Example Keyword และใช้ Log ในการแสดงข้อความ This is an example of a keyword. จากนั้นใน Test Case ชื่อ Example Test Case เราใช้ Keyword Example Keyword และใช้ Log ในการแสดงข้อความ This is a test case. แสดงให้เห็นถึงการใช้ Keyword ใน Test Case.

นอกจาก Keyword ที่สร้างขึ้นเองแล้ว คุณยังสามารถใช้ Keyword ของ Library ต่างๆ ของ Robot Framework ได้เช่น BuiltIn Library ซึ่งเป็น Library พื้นฐานที่มีอยู่แล้ว และสามารถใช้ Keyword ต่างๆ ของ Library นี้ใน Test Case ได้เช่น Log, Sleep, Set Variable และอื่นๆ

*** Test Cases ***
Example Test Case
    Log    This is a test case.
    Sleep    2s
    ${result}    Set Variable    Example Value
    Log    The value of ${result} is: ${result}

ในตัวอย่างนี้ เราใช้ Keyword Log ในการแสดงข้อความ This is a test case. จากนั้นใช้ Keyword Sleep ในการหยุด Test Case นาน 2 วินาที จากนั้นใช้ Keyword Set Variable ในการกำหนดค่าของ ${result} ให้เป็น Example Value และใช้ Keyword Log ในการแสดงค่าของ ${result} แสดงให้เห็นถึงการใช้ Keyword ของ Library ใน Test Case.

นอกจากการใช้ Keyword ของ Library ต่างๆ แล้ว คุณยังสามารถใช้ Keyword ของ User-Defined Library ได้ โดยการเขียน Library ขึ้นมาเอง ซึ่งจะช่วยให้คุณสามารถใช้ Keyword ต่างๆ ซ้ำใน Project หรือระหว่าง Project ได้ และยังสามารถใช้ Keyword ของ User-Defined Library ใน Test Case ได้เช่น

*** Settings ***
Library    ExampleLibrary

*** Keywords ***
Example Keyword
    Log    This is an example of a keyword.

*** Test Cases ***
Example Test Case
    Example Keyword from Library

ในตัวอย่างนี้ เรากำหนด Library ชื่อ ExampleLibrary ให้ใช้งานใน Project จากนั้นใน Test Case เราใช้ Keyword Example Keyword from Library ซึ่งเป็น Keyword ของ User-Defined Library ExampleLibrary แสดงให้เห็นถึงการใช้ Keyword ของ User-Defined Library ใน Test Case.

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

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

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