Skip to content

Robot Framework เริ่มต้น กำหนดโครงสร้างโปรเจค EP2

Sharing is caring!

ต่อจากบทความ Robot Framework เตรียมพร้อมก่อนเริ่มโค๊ด Robot EP1 จะแนะนำ scripts ของ robot ที่จำเป็นต้องทราบก่อนการเพิ่มโค๊ด Robot มาต่อกันที่บทความนี้ขจะพาทุกคน เริ่มสร้าง กำหนดโครงสร้างโฟลเดอร์ ไฟล์ ต่างๆ ของ โปรเจค

คำแนะนำเกี่ยวกับข้อมูลและเนื้อหาของบทความนี้

  • ติดตั้ง python 3.8 ขึ้นไป
  • ติดตั้ง pycharm

กำหนดโครงสร้างโฟลเดอร์ ไฟล์ ต่างๆ ภายในโปรเจค

ตัวอย่างนี้เป็นเพียงการออกแบบจากผู้เขียนบทความเอง เท่านั้น ผู้อ่านสามารถปรับเปลี่ยน แก้ไข เพื่อให้เหมาะสม

  • poolsawat.com (ชื่อโปรเจค)
    • keywords (ไฟล์ keywords ต่าง ๆ )
      • ***_keywords.robot
    • pythonlibs (function ต่าง ๆ สามารถเรียกใช้งานเหมือนกับ keywords ปกติ)
      • ***.py
    • resources (ไฟล์ data, config, data test)
      • configs
        • dev
          • env.yaml
        • staging
          • env.yaml
      • testdata
        • dev
          • module1_data.yaml
        • staging
          • module1_data.yaml
      • commons.yaml
      • imports.robot
    • scripts
    • testcases (ไฟล์ testcases ต่าง ๆ)
      • module1_testcase.robot
    • venv
    • requirements.txt

ตัวอย่างคำสั่ง รัน testcase และ ผลลัพธ์จากการ รัน testcase

command เพื่อใช้สั่ง run testcase

robot -L TRACE --variable ENV:dev -t "CASE_000**" "testcases/episode_1.robot"
  • robot : คำสั่งจะสามารถเรียกใช้งานได้หลังจากติดตั้ง robotframework
  • -L TRACE : write log level TRACE
  • –variable ENV:dev : defined variable ENV เพื่อใช้แยก resource environment ในโค๊ด Robot
  • -t “CASE_000**” : filter cases ที่ต้องการสั่งรัน เป็นชุด testcase เพื่อใช้ในการรัน
  • “testcases/episode_1.robot” : specific file testcase ที่จะรัน
(poolsawat.com-venv1) D:\RobotFramework\poolsawat.com>robot -L TRACE --variable ENV:dev -t "CASE_000**" "testcases/episode_1.robot"
==============================================================================
Episode 1                                                                     
==============================================================================
CASE_00001 lesson 1 Log to console                                    'Hello World 1'
CASE_00001 lesson 1 Log to console                                    | PASS |
------------------------------------------------------------------------------
CASE_00002 lesson 2 use external keywords with void                   'Result from Print Message from agruments keywords ::==''Hello world 2'
CASE_00002 lesson 2 use external keywords with void                   | PASS |
------------------------------------------------------------------------------
CASE_00003 lesson 3 use external keywords with return                 .'Result from Calculate value keywords::=='15
CASE_00003 lesson 3 use external keywords with return                 | PASS |
------------------------------------------------------------------------------
CASE_00004 lesson 4 get data from yaml file                           'request ::='{'name': 'poolsawat Dev Env', 'age': 30, 'nation': 'Thai'}
.'expect_data ::=='{'status': {'code': 'API200', 'message': 'Success'}}
CASE_00004 lesson 4 get data from yaml file                           | PASS |
------------------------------------------------------------------------------
CASE_00005 lesson 5 get env global file                               'app_name ::=='poolsawat.com
CASE_00005 lesson 5 get env global file                               | PASS |
------------------------------------------------------------------------------
CASE_00006 lesson 6 use custom lib keywords                           .'now ::=='2022-07-13 14:47:23.480131
CASE_00006 lesson 6 use custom lib keywords                           | PASS |
------------------------------------------------------------------------------
CASE_00007 lesson 7 use variable with resource environnment           'welcome_message from dev::=='welcome from Dev environment
CASE_00007 lesson 7 use variable with resource environnment           | PASS |
------------------------------------------------------------------------------
Episode 1                                                             | PASS |
7 tests, 7 passed, 0 failed
==============================================================================
Output:  D:\RobotFramework\poolsawat.com\output.xml
Log:     D:\RobotFramework\poolsawat.com\log.html
Report:  D:\RobotFramework\poolsawat.com\report.html

และสามารถเปิดตรวจสอบ result ได้จากไฟล์ .\log.html

บทความถัดไปจะเป็นเนื้อหาที่เน้นลงลึกไปในรายละเอียดของไฟล์ต่าง ๆ ขอบคุณที่ติดตาม

EP1 Robot Framework เตรียมพร้อมก่อนเริ่มโค๊ด Robot EP1
EP3 Robot Framework อธิบายการทำงาน EP3
EP4 Robot Framework แนะนำ Pycharm IDE ช่วยให้เขียน Robot ง่ายยิ่งขึ้น EP4

Tags:

ใส่ความเห็น

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *