简体   繁体   English

单击按钮提交表单后,Behat结束

[英]Behat ends when click on button submit form

I use Symfony2 and I have a problem with Behat. 我使用Symfony2,但是Behat有问题。 My Scenario is: 我的方案是:

Scenario: Add form 场景:添加表单
When Access path " symfony_route_path " 访问路径为 symfony_route_path ”时
Then Fill data form x 然后填写数据表格x
Then Push btn " id_btn_form_submit " 然后推送btn id_btn_form_submit

And Contexts: 和上下文:

(class FormContext extends DefaultContext that is a bit like -> https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ResourceBundle/Behat/DefaultContext.php ) (类FormContext扩展了DefaultContext,有点像-> https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ResourceBundle/Behat/DefaultContext.php

/**
 * @Then Fill data form x
 */
public function fillData()
{
    $this->fillField('field_x[name]', 'name');
    $this->fillField('field_y[address]', 'Address');
}

(class BaseContext extends RawMinkContext) (类BaseContext扩展了RawMinkContext)

/**
 * @Then Push btn :button
 */
public function pressBtn($button)
{
    $this->getSession()->getPage()->pressButton($button);
}

The output console performs to 'Fill data form x' (runs method completely), but not show 'Push btn'. 输出控制台执行“填充数据表单x”(完全运行方法),但不显示“ Push btn”。 someone has experienced a similar problem and could help me? 有人遇到过类似的问题并且可以帮助我吗? I thank you. 我谢谢你。

Try this: I click on "button". 试试这个:我点击“按钮”。

I have had some problems with it and solved it in this way 我遇到了一些问题并以这种方式解决了

About the translation, I'm not really sure if there are some best solution, but I would create a PortugueseContext and call the method you want from there, so... 关于翻译,我不确定是否有最佳解决方案,但是我会创建一个PortugueseContext并从那里调用想要的方法,所以...

public class overrideMinkContextPortuguese extends MinkContext
{
    /*
    * @When Precionar botao :button
    */
    public function precionarBotao($button)
    {
        $this->pressButton($button);
    }

But probably there is a best way... 但是也许有最好的方法...

It is done like below, you don't have to implement any additional method in context class. 就像下面这样完成,您不必在上下文类中实现任何其他方法。

Read this cheatsheet as well. 还要阅读此备忘单

Given I am on "url"
When I fill in "form_element" with "value"
Then I press "button"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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