관리 메뉴
Automotive Software
로봇 프레임워크 테스트케이스 문법 - 사용자 키워드 본문
테스트 케이스를 구현하다 보면 사전에 정의된 또는 이미 제공되는 키워드를 사용하기보단 요구사항에 맞게 사용자 키워드를 구현해야 하는 경우가 많이 발생하게 된다.
사용자 키워드는 간단히 C의 함수와 같다고 생각하면 되겠으나 다시 한번 기억할 점은 로봇 프레임워크에서 사용되는 문장은 대개의 경우 키워드로 인식된다는 점이다. 따라서, 키워드 내 로컬 변수에 값을 할당할 경우, 이 할당 구문이 키워드로 인식되지 않도록 하는 것이 필요하다.
기본 문법을 보면,
키워드 영역을 *** Keywords *** 로 선언한 후 다음 줄부터 바로 사용자 키워드를 구현하게 된다.
*** Keywords ***
사용자 키워드 명
_(들여 쓰기)_세부 키워드 구현
MyFirstTestCase.resource
*** Keywords ***
Run and Evaluate Test
Log This is the keyword for Run and Evaluate Test which is in other resouce file
인자가 필요한 경우,
_(들여 쓰기)_[Arguments]를 사용하여 필요한 개수만큼, 인자를 명시할 수 있다. 이때, 기본값이 필요한 인자에는 아래와 같이 ${인자명}=기본값으로 명시할 수 있다.
User Keyword with Default
[Arguments] ${mandatory_arg} ${mandatory_arg_with_default_value}=1
Log To Console Received arguments ${mandatory_arg}, ${mandatory_arg_with_default_value}
유동적으로 인자의 개수가 바뀌는 경우에는,
@{인자명}을 통해 유동적으로 인자를 받을 수 있다.
User Keyword with Variable Args
[Documentation] *varargs is for variable number of arguments
[Arguments] ${mandatory_arg} @{varargs}
Log To Console Received the mandatory argument as ${mandatory_arg}
FOR ${item} IN @{varargs}
Log To Console Received the variable argument as ${item}
END
상기 예제를 사용하는 테스트 케이스는,
*** Keywords ***
Run and Evaluate Test
Log This is the keyword for Run and Evaluate Test which is in other resouce file
User Keyword with Default
[Arguments] ${mandatory_arg} ${mandatory_arg_with_default_value}=1
Log To Console Received arguments ${mandatory_arg}, ${mandatory_arg_with_default_value}
User Keyword with Variable Args
[Documentation] *varargs is for variable number of arguments
[Arguments] ${mandatory_arg} @{varargs}
Log To Console Received the mandatory argument as ${mandatory_arg}
FOR ${item} IN @{varargs}
Log To Console Received the variable argument as ${item}
END
*** Test Cases ***
My Second Test Case
[Documentation] This is the documentation for my second test case
[Tags] My Test Second Test Case
[Timeout] 5
User Keyword with Default 1
User Keyword with Default 1 2
User Keyword with Variable Args 10 20 30
실행 결과는
'프로그래밍 (Programming) > 로봇프레임워크 (Robotframework)' 카테고리의 다른 글
테스트 케이스 명칭 및 설명 (0) | 2023.03.21 |
---|---|
테스트 케이스 종료 (0) | 2023.03.18 |
로봇 프레임워크 테스트케이스 문법 - 테스트 케이스 영역 설정 (0) | 2023.03.15 |
로봇 프레임워크 테스트케이스 문법 - 기본 (0) | 2023.03.14 |
문제 해결 (0) | 2023.03.11 |