【发布时间】:2018-09-01 04:43:07
【问题描述】:
我有以下步骤大纲,我已开始使用并按以下格式构建:
步骤定义
@web1
Scenario Outline: A teacher filters the report
Given I am signed in as a teacher
And I navigate to the reports page
Then I click on the School Overview report
And I select an <option> from the dropdown
Examples:
|option|
|teacher|
|subject|
|class|
|year|
我想要实现的目标
对于每个选项,我希望选择不同的下拉选项(我已经在步骤定义中定义的逻辑),这样我就可以在上面将它们组合在一起,而不是为类似的操作创建多个场景.
以前,在我有多个场景做同样的事情时使用了相同的步骤定义 - 一个接一个地打开一个下拉菜单。现在,但是我不确定如何为此设置步骤定义文件..这是我尝试过的实验:
And(/^I select an <option> from the dropdown$/) do |table|
table.raw.each do |report_filter_types|
if report_filter_types.eql?("teacher")
# Making the teacher selection from the dropdown by selecting the first option
# @wait.until {@driver.find_element(:css => '.container-fluid > .filter-bar-element:nth-of-type(1) > .ember-view > .ember-view.ember-basic-dropdown-trigger > span:nth-of-type(1)').click}
#@wait.until {@driver.current_url.include?('teacher=')}
elsif report_filter_types.eql?("subject")
# Making the subject selection from the dropdown by selecting the first option
@wait.until {@driver.find_element(:css => '.container-fluid > .filter-bar-element:nth-of-type(2)').click}
@wait.until {@driver.find_element(:css => '.ember-view.ember-basic-dropdown-trigger > span:nth-of-type(1)').click}
@wait.until {@driver.find_element(:css => '.ember-basic-dropdown-content > .ember-view > li:nth-of-type(1)').click}
elsif report_filter_types.eql?("class")
# Making the classes selection from the dropdown by expanding it and then choosing the first option
@wait.until {@driver.find_element(:css => '.container-fluid > .filter-bar-element:nth-of-type(3) > .ember-view > .ember-view.ember-basic-dropdown-trigger > span:nth-of-type(1)').click}
@wait.until {@driver.find_element(:css => 'a.ember-view.grouped-classes-options').click}
@wait.until {@driver.find_element(:css => '.ember-view > li:nth-of-type(1) > .ember-view > li:nth-of-type(1) > .ember-view > li').click}
elsif report_filter_types.eql?("year")
# Making a year selection from the dropdown by expanding it and choosing the first option
@wait.until {@driver.find_element(:css => '.last > span:nth-of-type(1)').click}
@wait.until {@driver.find_element(:css => '.ember-basic-dropdown-content > .ember-view > li:nth-of-type(1)').click}
end
puts "Report filtered by #{report_filter_types}"
end
end
上面写着report_filter_types 的部分只是我定义了在应用程序中选择每个“个人”下拉菜单所需执行的操作。不知道我怎么能把它连接到桌子上!
上面的代码是以我将有单独的“场景”来打开每个下拉列表的格式设置的,但是我想利用上面的现有代码,对其进行调整并使用表格格式使其更整洁,更易于维护这项特征。
【问题讨论】: