短篇小说:我正在使用生菜和 splinter 为 django 应用程序编写功能测试。由于步骤调用中缺少同步,该方案失败。
问题:有没有办法在不增加人为等待时间的情况下防止此错误发生?
更长的故事:场景检查现有用户是否能够登录。
Scenario: User exists as admin
Given I access the url "/login/"
And The user "someuser" with password "something" exists as admin
When I fill username with "someuser" and password with "exists"
And I submit the form
Then I see the paragraph "You're successfully logged in!"
这里的关键步骤是:
@step(r'I see the paragraph "(.*)"')
def see_paragraph(step, text):
assert text in world.browser.html
当我收获生菜功能时,它随机失败。
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/lettuce/core.py", line 143, in __call__
ret = self.function(self.step, *args, **kw)
File "/vagrant/src/enext/apps/auth/features/authentication-steps.py", line 21, in see_paragraph
assert text in world.browser.html
AssertionError
当我尝试调试它时,我发现打印响应会使其每次都能正常工作,所以我无法重现错误。添加暂停似乎也可以解决问题。
@step(r'I see the paragraph "(.*)"')
def see_paragraph(step, text):
# print world.browser.html.encode('utf-8')
# either the next or the previous line fixes it
time.sleep(0.3)
assert text in world.browser.html
起初它看起来与测试数据库刷新有关,但我删除了其他场景,以及刷新,它一直在发生。