6

Rails + AngularJS を使用しており、すべてのエンド ツー エンド テストで分度器を使用するように切り替えました。テスト用に開発データベースの代わりにテストデータベースを使用するのに役立つ分度器レール宝石を使用してセットアップしました。

問題は、「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")

)

これらのテストをきれいにクリーンアップするにはどうすればよいですか?

私が持っていた 1 つのアイデアは、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() を呼び出します。それはうまくいきますが、より良い方法はありますか?

4

1 に答える 1