数据表在黄瓜中的背景

时间:2019-10-23 15:02:47

标签: java selenium cucumber

如何在后台创建数据表并在场景中访问其数据?

我正在运行具有各种值和数据的方案,想知道我是否可以访问在backgorund表中输入的值

Background: 
Given Essas informacoes:
  | Price | Name | Insurance     | Damage           | Type     | Email |
  |       |      |  3.000.000,00 | Full Coverage    | Gold     |       |
  |       |      | 10.000.000,00 | No Coverage      | Silver   |       |
  |       |      | 25.000.000,00 | Partial Coverage | Platinum |       |
  |       |      |               |                  | Ultimate |       |
  |       |      |               |                  |          |       |
And E o navegador aberto
And O site carregado
And Tendo selecionado Truck
@ValidarCotas  
Scenario: Selecionar cotacao de seguro de tipo diferente de acordo com valores variados
        Given Esta na tela do formulario de Truck
        And Preenchido os dados do veiculo e os dados do segurado
        When Preencho os campos do formulario de dados do seguro  "**<Insurance>**" "**<Damage>**"
        And Seleciono cota de seguro "<Type>"
        Then Valido se a cota foi enviada para o email
        And Valido se o valor da cota for o mesmo que eu selecionei no site
        When Fecho o navegador

2 个答案:

答案 0 :(得分:0)

您需要在此处使用“方案大纲”,它可以用于多次运行相同的方案,并具有不同的值组合。

Scenario Outline: eating
  Given there are <start> cucumbers
  When I eat <eat> cucumbers
  Then I should have <left> cucumbers

  Examples:
    | start | eat | left |
    |    12 |   5 |    7 |
    |    20 |   5 |   15 |

如果每个测试用例中都有多个可重复的“给定”步骤,请使用“背景”。

答案 1 :(得分:0)

根据我的理解,您想在多个场景中重用示例。 AFAIK,当黄瓜与黄瓜一起使用时不支持。

一种方法是通过在外部文件中移动示例并在您的方案中引用该方案(在使用gherkin with qafBDD2 with qaf但不支持黄瓜的方案中进行引用)在方案之间重用示例。

例如:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
  <bean id="org_alfresco_module_custom_propertyBootstrap" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>alfresco.web-extension.messages.customslingshot</value>
         </list>
      </property>
   </bean>   
</beans>

有关更多详细信息,请参见documentation