角网格中材料API的一些有用cucumber/capybara表达式

角网格中材料API的一些有用cucumber/capybara表达式,cucumber,angular-material,angular5,capybara-webkit,Cucumber,Angular Material,Angular5,Capybara Webkit,我已经开始使用最新的Angular(5)和Material,并且遇到了一些有用的函数来帮助测试 这是我的“material.rb”文件: .modal对话框是我自己在所有模态对话框上添加的标记,但是您可以用“mat dialog container”替换它 以下是我如何使用它们的几个步骤: @javascript Scenario: A new idea can be created in a stream When she clicks "MyQ" And she clicks "

我已经开始使用最新的Angular(5)和Material,并且遇到了一些有用的函数来帮助测试

这是我的“material.rb”文件:

.modal对话框是我自己在所有模态对话框上添加的标记,但是您可以用“mat dialog container”替换它

以下是我如何使用它们的几个步骤:

@javascript
Scenario: A new idea can be created in a stream
   When she clicks "MyQ"
   And she clicks "New Idea in a stream"
  And a modal dialog appears
   And she clicks chip "Stream 1"
  And she enters "New Task 1" in "name"
  And she enters "Do this" in "description"
  And she clicks "Ok"
  And eventually the modal dialog disappears

   @javascript
    Scenario: A non-empty team cant be deleted
       When she clicks action "DELETE" in card with title "Team 1"
      And a modal dialog appears
      And she clicks "Ok"
      And eventually the modal dialog disappears
      And a modal dialog appears
      And she clicks "Ok"
      Then eventually the modal dialog disappears
      And eventually there are 2 grid tiles

作为对其他人的建议,有很多问题。首先,
最终
是不必要的,因为所有水豚的匹配者和它的大多数发现者都有等待/重试行为。因此,增加
Capybara.default\u max\u wait\u time
或在调用中指定
wait
参数,以增加它等待匹配器/期望/查找成功的最长时间。第二,你应该把所有的“inxxx”转换成他们自己的步骤,使用水豚作用域,然后调用其他步骤,这样它们是可重用的,第三,你应该使用期望而不是发现来明确你实际上在测试什么。实现所有这些都会带来如下好处:

Given("she clicks chip {string}") do |name|    
  find("mat-chip", :text => name).click() 
end

Given("eventually there are {int} grid tiles") do |count| 
  expect(find('mat-grid-list > div')).to have_selector('mat-grid-tile', count: count.to_i, wait: 20) # wait up to however long "eventually" can be
end

Given("{string} in modal dialog") do |modal_step|
  within(".modal-dialog") do
    step(step_in_modal)
  end
end

When("{step} in card with title {string}") do |card_step, title|
   within("mat-grid-tile mat-card-title", text: title) do
     step(card_step)
   end
end

When("she clicks action {string}") do |action|
  find(:xpath, "../../..").find("mat-card-actions > button > span", :text => action).click()
end

When("she clicks action number {int}") do |action|
  find(:xpath, "../../..").find("mat-card-actions > button:nth-child(#{action})").click()
end

When(/^a modal dialog appears$/) do
 expect(page).to have_css(".modal-dialog")
end

When(/^the modal dialog disappears$/) do
  expect(page).to have_no_css?(".modal-dialog") # pass `wait` option if you need a longer time here and don't want to increase `Capybara.default_max_wait_time`
end

我认为更改水豚的默认等待时间是一个新手错误。在测试中使用“最终”一词实际上是为了测试的消费者,而不是实现。如果您希望立即发生某些事情,请使用默认的等待,该等待应快速超时。如果您想告诉最终用户将有一个等待,那么实现您自己的活套是一个非常好的主意(并将“最终”放在测试中)。使用一点ruby代码就可以达到同样的目的,这是一个额外的好处:-)此外,更改默认等待时间只会意味着您的测试失败的速度要慢得多,如果确实有什么问题,这真的很糟糕。@PaulHamilton编写自己的循环器是毫无意义的,当您需要更长的最大等待时间时,只需为该调用指定
wait
参数,更不用说您最终会得到比大多数人编写
最终
类型方法更好的错误消息。至于
default\u max\u wait\u time
-是的,对于正常行为,应将其设置为最低级别,然后在特定调用中使用
wait
参数覆盖,或者对块使用
wait\u time
覆盖-否则,测试失败的时间可能更长,但测试不应该失败,最好是可靠地通过测试,而不是不合格的测试
Given("she clicks chip {string}") do |name|    
  find("mat-chip", :text => name).click() 
end

Given("eventually there are {int} grid tiles") do |count| 
  expect(find('mat-grid-list > div')).to have_selector('mat-grid-tile', count: count.to_i, wait: 20) # wait up to however long "eventually" can be
end

Given("{string} in modal dialog") do |modal_step|
  within(".modal-dialog") do
    step(step_in_modal)
  end
end

When("{step} in card with title {string}") do |card_step, title|
   within("mat-grid-tile mat-card-title", text: title) do
     step(card_step)
   end
end

When("she clicks action {string}") do |action|
  find(:xpath, "../../..").find("mat-card-actions > button > span", :text => action).click()
end

When("she clicks action number {int}") do |action|
  find(:xpath, "../../..").find("mat-card-actions > button:nth-child(#{action})").click()
end

When(/^a modal dialog appears$/) do
 expect(page).to have_css(".modal-dialog")
end

When(/^the modal dialog disappears$/) do
  expect(page).to have_no_css?(".modal-dialog") # pass `wait` option if you need a longer time here and don't want to increase `Capybara.default_max_wait_time`
end