【发布时间】:2014-10-14 23:36:57
【问题描述】:
我正在使用 Rails + AngularJS,并已切换到使用 Protractor 进行所有端到端测试。我使用protractor-rails gem 设置它,这有助于我使用测试数据库而不是开发数据库进行测试。
问题是在我运行测试后,例如:'create_client_spec.js.coffee' 然后我的表中剩下一个新客户端,在我的测试后没有清理。
helper = require('../../helper.js.coffee')
describe('create a new client', ->
beforeEach ->
helper.login()
afterEach ->
helper.logout()
it 'shows the client after creation', ->
browser.get('/api#/clients')
element(By.id("new_btn")).click()
element(By.id("name")).sendKeys("John Smith")
element(By.id("create_btn")).click()
expect(element(By.id("heading")).getText()).toContain("John Smith")
)
如何很好地清理这些测试?
我的一个想法是在 afterEach 中添加一个方法,以便在此文件中的每个测试之后删除新客户端。
更新:
我在 helper.js.coffee 中添加了以下内容
delete_client: ->
last=element.all(By.id("listing")).last()
last.element(By.id("delete")).click()
this.accept_dialog()
accept_dialog: ->
# Accept the dialog which is displayed
ptor = protractor.getInstance()
alertDialog = ptor.switchTo().alert()
alertDialog.accept()
然后我在注销之前在 afterEach 块中调用 helper.delete_client()。它有效,但有更好的方法吗?
【问题讨论】:
-
你知道protractor config中的
onCleanUp可选功能吗? -
不,我不知道这个 onCleanUp 选项,我可以在 onCleanUp 中调用 rake 任务吗?
-
我不确定,它会在你所有测试结束时自动调用,这就是我所知道的。
标签: angularjs testing jasmine protractor end-to-end