简体   繁体   中英

Can I put defined robot keywords under Suite SetUp/ Test Setup in Robot Framework

I am new to coding and robot framework, Could anyone please kindly explain to me if my approach down here is not applicable.

My goal would like to do a test setup to create a game as prerequisties in order to let all players to join the same game. Otherwise, robot will loop through my keywords and each time will need to create a new game for the next player to join, which is the case I would like to avoid.

However, it seems that Test Setup doesn't allow me to put my own defined robot keywords and throwing errors, could anyone kindly advise?

#Create Trading Arena Game
When Create trading arena game name as ${game_name} with status ${status} where start date on ${minutes_to_start} and end date on ${day_to_end} open for vip tiers ${vip_tiers} and user type ${user_type} and trade filter ${instrument_pair} by wallet ${wallet_type} with min trade volume ${min_trade_volume} and leaderboard ${is_with_leaderboard}
When Wait 60000 millisecond
#Error log
Using local env settings...
==============================================================================
001.Vip Tiers Join Trading Arena Game                                         
==============================================================================
Level 1 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 2 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 3 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 4 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 5 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 6 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 7 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 8 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
Level 9 user join trading arena game                                  | FAIL |
Parent suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
------------------------------------------------------------------------------
001.Vip Tiers Join Trading Arena Game                                 | FAIL |
Suite setup failed:
Keyword 'Create Trading Arena Game' expected 0 arguments, got 10.
*** Settings ***

Resource        ../../../robot_resources/Common.robot
Resource        ../../../robot_resources/Assertion.robot

Test Template   Different vip tiers of user join trading arena game
Test Setup     Create Trading Arena Game
*** Variables ***
${record_number}        1
${user_1}     1
${user_2}     2
${user_3}     3
${user_4}     4
${user_5}     5
${user_5}     6
${user_5}     7
${user_5}     8
${user_5}     9

${game_name}    Test vip tiers level join trading game
${status}       ACTIVE
${minutes_to_start}   1
${day_to_end}     30
${vip_tiers}    1,2,3,4,5,6,7,8,9
${user_type}    INDIVIDUAL
${instrument_pair}      BTC,USDT
${wallet_type}          SPOT
${min_trade_volume}     0
${is_with_leaderboard}  true


${status2}       ENDED
${vip_tiers2}    ${EMPTY}
${user_type2}    ${EMPTY}
${instrument_pair2}      ${EMPTY}
${wallet_type2}          ${EMPTY}
${min_trade_volume2}     ${EMPTY}
${is_with_leaderboard2}  ${EMPTY}

*** Test Cases ***
Level 1 user join trading arena game    ${user1}    ${checking}
Level 2 user join trading arena game    ${user2}    ${checking}
Level 3 user join trading arena game    ${user3}    ${checking}
Level 4 user join trading arena game    ${user4}    ${checking}
Level 5 user join trading arena game    ${user5}    ${checking}
Level 6 user join trading arena game    ${user6}    ${checking}
Level 7 user join trading arena game    ${user7}    ${checking}
Level 8 user join trading arena game    ${user8}    ${checking}
Level 9 user join trading arena game    ${user9}    ${checking}

*** Keywords ***
Create Trading Arena Game

    When Create trading arena game name as ${game_name} with status ${status} where start date on ${minutes_to_start} and end date on ${day_to_end} open for vip tiers ${vip_tiers} and user type ${user_type} and trade filter ${instrument_pair} by wallet ${wallet_type} with min trade volume ${min_trade_volume} and leaderboard ${is_with_leaderboard}
    When Wait 60000 millisecond

Different vip tiers of user join trading arena game
    [Arguments]        ${user}  ${checking}

    When Get latest ${record_number} trading arena game records on ${status}
    When Wait 5000 millisecond
    When Get latest ${record_number} trading arena game records with user eligibility on ${status} of ${user}
    When Wait 5000 millisecond

    When Player join latest ${record_number} trading arena game with tiers level ${user}
    When Wait 5000 millisecond
    Then Should actual result "${user_join_trading_arena_game_record}" match expected "${checking}" result

First, I believe you would want a Suite Setup instead of Test Setup which would create the game before all test case starts, instead of creating the game before each test case starts

Second, Suite Setup allows user defined keyword but you are passing arguments into Create Trading Arena Game at When Create trading arena game name as ${game_name}... while the keyword does not accept any arguments. Not sure why you are recusing the keyword under Create Trading Arena Game .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM