1

I have the following scenario's:

@wip
Scenario: Attempt to get account information of an activator without credentials
Given an activator with e-mail "dietervds@email.com" and password "testpassword" already exists
When I send a GET request to "/activators/1"
Then the response code should be 401

@wip
Scenario: Attempt to get account information of another activator then myself
Given an activator with e-mail "dietervds@email.com" and password "testpassword" already exists
And an activator with e-mail "eviltwin@email.com" and password "testpassword" already exists
And I am authenticating as "eviltwin@email.com" with "testpassword" password
When I send a GET request to "/activators/1"
Then the response code should be 401

The database is dropped and re-created from schema before every scenario.

The step 'given an activator with ...' inserts a new user into the database.
However! It doesn't always do that for both users.

This is the step implementation:

/**
 * @Given /^an activator with e-mail "([^"]*)" and password "([^"]*)" already exists$/
 */
public function anActivatorWithEMailAndPasswordAlreadyExists($email, $password)
{
    $activatorManager = $this->getContainer()->get('am.manager.activator');
    #$logger = $this->getContainer()->get('logger');
    #$logger->debug("Email: $email, password: $password");
    $activator = $activatorManager->createActivator($email, $password);
    $activatorManager->save($activator);
}

Now the weird thing:
In that last step, I should be getting two inserts: one for dietervds, one of eviltwin.

I get the two inserts when I:

  • Run only one scenario
  • Output something in logging (creating the 'logger' doesn't help, I need to output something. What I output doesn't have to be dynamic, it can just be a fixed string)

I only get one insert (for dietervds) when I:

  • Run the two scenarios together
  • Or when I don't output any logging in the step implementation

I am completely baffled by this.
Is there something obvious that's missing? Might it be some sort of caching problem in the step definitions? (the logging might change the signature or something, not sure)

Any feedback is welcome :-)

Cheers!

Dieter

4

1 回答 1

1

这一步 def 是否进行 ajax 调用?

当我向“/activators/1”发送 GET 请求时

如果是这样,您可以尝试在其中添加一些等待时间,让您的 dom 有时间加载结果

当您通过按下或跟随链接提交表单或执行 go to 以重定向浏览器时,Whens to Thens 效果最佳,这会启动完整的请求响应周期,从而触发机器人等待新的 dom 加载。

使用 ajax 不会以完全相同的方式发生。

如果您不使用 ajax,我建议您只使用内置的 step defs

When I follow "/activators/1" instead

有一种方法可以防止在您的 yaml 配置中进行缓存。这是我们用于 chrome 的示例配置,但它应该适用于任何浏览器驱动程序

default:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: https://yurwebsite.com
            goutte: ~            
            browser_name: "googlechrome"
            selenium2:
                capabilities: { "browser": "googlechrome", "version": "23", "applicationCacheEnabled": false }

最后一个布尔参数可以解决我们的浏览器缓存问题

于 2013-01-08T03:08:20.540 回答