【问题标题】:How to pass multiple arguments to a test case in CumulusCI test automation framework?如何将多个参数传递给 CumulusCI 测试自动化框架中的测试用例?
【发布时间】:2019-05-31 23:05:30
【问题描述】:

问题陈述:

无法使用 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

【问题讨论】:

  • 我一周前在salesforce stackexchange link 上添加了这个问题,但是还没有回答;因此希望把它贴在这里得到更多的关注。
  • 我无法重现该问题。当我运行您的确切测试并提供缺少关键字的虚拟实现时,当我使用您在问题中显示的确切命令行时,测试会将“edge”记录为浏览器。也许是您的Setup local kw1 关键字正在改变${browser} 的值。换句话说,传递多个变量的方式就是你的做法。
  • 为了排除 cci 中的错误,我建议您从一个非常简单的测试开始,该测试只记录变量的值。我的猜测是,它们将显示在命令行上设置的值。然后,您可以开始重新添加代码以查看变量何时更改。也许是资源文件,也许是您的其他关键字之一。

标签: selenium robotframework


【解决方案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} 变量的值。

【讨论】:

    【解决方案2】:

    非常感谢@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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多