如何在CumulusCI测试自动化框架中将多个参数传递给测试用例?

时间:2019-05-27 10:44:34

标签: selenium robotframework

问题陈述:

无法使用CumulusCI命令将多个变量值传递给我的测试用例:

`cci task run robot...
  1. 我正在参考此部分来构建命令:https://cumulusci.readthedocs.io/en/latest/tasks.html#id49

  2. 如果我必须以与上述相同的方式仅传递一个变量,请举例说。只是LocalOrRemote,那么代码就可以正常工作,因此看来这与我传递多个变量的方式有所不同。

  3. 我的测试自动化技术栈是Robot Framework,CumulusCI,Selenium

示例代码:

*** Settings ***
Resource  C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Suite Setup  Run Keywords  Suite Setup KW1  AND  Suite Setup OS And Browser  ${LocalOrRemote}  ${Browser}


*** Test Cases ***
Verify whether I am able to set environment and browser
    [Tags]  LocalEdge
    [Documentation]  This test should run on the local edge browser
    Keyword X
    Keyword Y


*** Keywords ***
Suite Setup KW1
    do something
Suite Setup OS And Browser
    [Arguments]  ${LocalOrRemote}  ${Browser}
    Log Many  ${LocalOrRemote}  ${Browser}
    run keyword if  '${LocalOrRemote}'=='Local'  Setup Local Browser  ${Browser}  
    ...  ELSE IF  '${LocalOrRemote}'=='Remote'  Setup Remote Browser  ${Browser}
    ...  ELSE  FAIL  "Incorrect environment value passed! Please refer the instructions in README for running the test suite"

我用来调用测试的命令:

cci task run robot -o suites mypath/MyTestFile.robot -o include LocalEdge -o vars LocalOrRemote:Local,Browser:edge

我正面临的问题:

${Browser}的值不作为边缘接收,但默认为chrome,这意味着该命令无法将我想要的值传递给TC。

KEYWORD BuiltIn . Log Many ${LocalOrRemote}, ${Browser}
Documentation:  
Logs the given messages as separate entries using the INFO level.
Start / End / Elapsed:  20190522 16:36:53.877 / 20190522 16:36:53.878 / 00:00:00.001
16:36:53.877    INFO    Local   
16:36:53.877    INFO    chrome

2 个答案:

答案 0 :(得分:1)

  

如何在CumulusCI测试自动化框架中将多个参数传递给测试用例?

您的操作方式是正确的方法:-o vars var1:value1,var2:value2

这是一个非常简单的示例:

*** Test cases ***
Example
    Should be equal  ${LocalOrRemote}  Local
    Should be equal  ${Browser}        edge

将其保存到文件中,然后使用以下机器人任务运行它:

cci task run robot -o vars LocalOrRemote:Local,Browser:edge -o suites example.robot 

您将看到变量已正确初始化。如果打开了错误的浏览器,则您的其中一个库必须更改${Browser}变量的值,而无需意识到。

答案 1 :(得分:0)

感谢一吨@Bryan的指示。就在那一刻,您对自己的创作感到震惊,却忘了尝试在框架中进行基本调试。

无论如何,正如您正确指出的,这里的问题是资源的放置。请遵守以下之前和之后的代码段。问题(到目前为止,我不能说它是一个问题或缺点)与Salesforce.robot资源的放置有关。为了使Cci命令传递第二个变量的正确值,我不得不将此资源放在测试用例本身中。当我通过环境文件加载该资源时,Cci命令未传递第二个变量的正确值;很奇怪。

*** Settings ***
Documentation  ###My setup before: 
Resource  C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Suite Setup  Run Keywords  Suite Setup KW1  AND  Suite Setup OS And Browser  ${LocalOrRemote}  ${Browser}
Documentation  ###My setup after: 
Resource  C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Resource  cumulusci/robotframework/Salesforce.robot  #had to place this resource here
Suite Setup  Run Keywords  Suite Setup KW1  AND  Suite Setup OS And Browser  ${LocalOrRemote}  ${Browser}

*** Test Cases ***
Verify whether I am able to set environment and browser
    [Tags]  LocalEdge
    [Documentation]  This test should run on the local edge browser
    Log  "TC passed"

之前的设置:

C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot

*** Keywords ***
Suite Setup KW1
    Import Resource  cumulusci/robotframework/Salesforce.robot  #the resource that was causing the issue
    Import Resource  C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
    import resource  C:/Dev/myproject/robotframework/ValidationKeywords.robot
    Import Library  cumulusci.robotframework.CumulusCI  ${ORG}
    import library  SeleniumLibrary  timeout=7 seconds  implicit_wait=5 seconds
    import library  OperatingSystem
    import library  BuiltIn

C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot

*** Keywords ***
Suite Setup OS And Browser
    [Arguments]  ${LocalOrRemote}  ${Browser}
    Log Many  ${LocalOrRemote}  ${Browser}  #used to default Browser value passed to chrome

`

之后的设置:

C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot

*** Keywords ***
Suite Setup KW1
    #Import Resource  cumulusci/robotframework/Salesforce.robot  # had to comment this resource here and place it before the Suite Setup
    Import Resource  C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
    import resource  C:/Dev/myproject/robotframework/ValidationKeywords.robot
    Import Library  cumulusci.robotframework.CumulusCI  ${ORG}
    import library  SeleniumLibrary  timeout=7 seconds  implicit_wait=5 seconds
    import library  OperatingSystem
    import library  BuiltIn

C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot

*** Keywords ***
Suite Setup OS And Browser
    [Arguments]  ${LocalOrRemote}  ${Browser}
    Log Many  ${LocalOrRemote}  ${Browser}  #now returns the correct Browser value