douqian1517 2019-03-27 00:15
浏览 45

如何访问behat场景大纲的示例值?

This should really be something simple and straight forward but I haven't been able to find an answer anywhere online. When using a scenario outline in Behat, how can I access the example values inside my test? For the below example, how would i access the email address in my test? My automated test will basically fill in a text field with an email address so I want to know how can i fill it with the email_value being used for this particular scenario that is being run?

Feature: Email validation
Background: Given I am on “www.somewebsite.com”
Scenario Outline: Confirm email validation

Given I fill in the email field with “”
When I submit the form
Then I should see “”

**Examples:**
|      |  |
|                   | A validation message that email is required|
| steve@            | A validation message that email must be valid |
| valid@email.com   | The review page |

This is a function my test case is calling, it's just finding the textfield and filling in an email address... Instead of filling it with "testing", I want to actually fill it out with the email_value from my outline. How can I access that value from within my function below?

public function fillForm()
    {
         $element = $this->driver->findElement($this->emailTextField);
         $element->click();
         $element->sendKeys("testing");

         #Please review your response and confirm.
    }

2) 2nd question somewhat related is that I want to check the submission_result to see if it doesn't contain the word "validation message" then I know it was a successfully (e.g. valid) email and will take me to a success page rather than display an error.

Thanks guys!

  • 写回答

1条回答 默认 最新

  • duanqiao1947 2019-03-27 16:32
    关注

    These are some out of the box defined steps, you need to check if you have everything you need and if not you need to define them yourself.

    As for different types of parameters

    Example:
    I fill in "field" for "value"

    the field and field are passed as parameters to the associated method, so you need to have access to that method if you want to print them or log them somewhere.

    For scenario outline:

      Scenario Outline:
        Given I fill in "" with "value_placeholder"
    
        Examples:
          | field_placeholder | value_placeholder |
          | field_identifier  | actual_value      |

    Use an editor that supports Behat and ctrl/command + click on the steps and see how to use them.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值