我试图利用空手道中的cucumber功能,将Excel/csv表格作为示例部分中的文件传递
我试图在功能文件的“场景大纲”部分使用“示例” 在Feature文件中,我尝试用以下格式表示它。这会像预期的那样工作我试图利用空手道中的cucumber功能,将Excel/csv表格作为示例部分中的文件传递,cucumber,karate,Cucumber,Karate,我试图在功能文件的“场景大纲”部分使用“示例” 在Feature文件中,我尝试用以下格式表示它。这会像预期的那样工作 Feature: save data to db Background: no definition Scenario Outline: to validate file is getting read by example section Given url 'https://www.googleapis.com/geolocation/v1/geolocate' And p
Feature: save data to db
Background: no definition
Scenario Outline: to validate file is getting read by example section
Given url 'https://www.googleapis.com/geolocation/v1/geolocate'
And param key = 'AIzaSyB2jt4BQ9McqBXAe8dYcp1CwKf0oGFlWuc'
And def dogs = read('classpath:external_table/json.feature')
And request { "homeMobileCountryCode": '<homeMobileCountryCode>'
,"homeMobileNetworkCode": '<homeMobileNetworkCode>' } dogs
When method post
And print response
Then status 200
Examples: {'datafile':'src/test/java/external_table/testdata.xlsx'}
功能:将数据保存到数据库
背景:没有定义
场景大纲:通过示例部分验证文件是否已被读取
给定url'https://www.googleapis.com/geolocation/v1/geolocate'
和参数键='AIzaSyB2jt4BQ9McqBXAe8dYcp1CwKf0oGFlWuc'
和def dogs=read('classpath:external_table/json.feature')
并请求{“HomeMobileContrycode”:“
,“homeMobileNetworkCode”:“}
当方法发布时
并打印回复
然后状态200
示例:{'datafile':'src/test/java/external_table/testdata.xlsx'}
首先,语法是错误的。示例表应该从下一行开始,而不是从“示例”一词的同一行开始
其次,示例表中没有标题,因此在场景步骤中将其用作占位符
第三,有一个占位符“”,它看起来像一个占位符,在场景步骤中定义,而示例表中没有
我不熟悉空手道,无法正确修改场景轮廓。请参阅此链接以了解这一点--首先,语法是错误的。示例表应该从下一行开始,而不是从“示例”一词的同一行开始 其次,示例表中没有标题,因此在场景步骤中将其用作占位符 第三,有一个占位符“”,它看起来像一个占位符,在场景步骤中定义,而示例表中没有
我不熟悉空手道,无法正确修改场景轮廓。请参阅此链接以了解这一点--不,它将无法按预期工作。正如其他人已经回答的那样,语法是错误的 我不明白你为什么要在这里回答这个问题时再问一次: 也许你的领导坚持认为需要使用Excel。从经验来看,使用Cucumber原生示例或空手道的数据驱动功能(您可以在JSON数组上循环)要简单得多,请参考以下内容:
如果您仍然坚持要使用Excel,并且不愿意编写一个小型Java实用程序来将Excel(或CSV)转换为JSON,那么请放弃使用空手道,它不是适合您的工具。祝你一切顺利。不,它不会像预期的那样工作。正如其他人已经回答的那样,语法是错误的 我不明白你为什么要在这里回答这个问题时再问一次: 也许你的领导坚持认为需要使用Excel。从经验来看,使用Cucumber原生示例或空手道的数据驱动功能(您可以在JSON数组上循环)要简单得多,请参考以下内容:
如果您仍然坚持要使用Excel,并且不愿意编写一个小型Java实用程序来将Excel(或CSV)转换为JSON,那么请放弃使用空手道,它不是适合您的工具。一切都好。如果你真的需要用CSV或Excel中的示例来处理驱动场景,这里是一种方法
Scenario: Commpile statistics for premier league teams
Given I am working with the premier league
When I compile teams statistics
Then I should see team statistics
And there should be no errors
为了实现这一点,我们必须将所有细节从场景向下推到步骤定义,最好是这些步骤定义的辅助方法。所以我们最终会有类似的结果
Given "I am working with the premier league" do
@teams = load_premier_league_teams
end
然后是助手方法
def load_premier_league_teams
get_the_teams_from_the_spreadsheet
end
def compile_statistics(teams)
results = []
teams.each do |t|
results << compile_team_stats(t)
...
end
现在,所有关于处理电子表格的内容都是在Cucumber之外用编程语言处理的
然后在When步骤中,您可以对每个团队执行以下操作
When "I compile the teams statistics" do
@results = compile_statistics(@teams)
end
并编写另一个助手方法
def load_premier_league_teams
get_the_teams_from_the_spreadsheet
end
def compile_statistics(teams)
results = []
teams.each do |t|
results << compile_team_stats(t)
...
end
def编译_统计数据(团队)
结果=[]
各队,各队|
结果如果你真的需要用CSV或Excel中的示例来处理驱动场景,这里是一种方法
说出你的例子,最好用企业能理解的名字
编写一个使用该名称的场景-不要使用场景大纲
获取一个步骤来完成获取Excel和示例的所有工作,使用名称来指导获取正确示例的步骤
让我们通过一个简单的英超足球队列表来了解这一点,并假设您必须从Excel电子表格中动态获取这些球队
Scenario: Commpile statistics for premier league teams
Given I am working with the premier league
When I compile teams statistics
Then I should see team statistics
And there should be no errors
为了实现这一点,我们必须将所有细节从场景向下推到步骤定义,最好是这些步骤定义的辅助方法。所以我们最终会有类似的结果
Given "I am working with the premier league" do
@teams = load_premier_league_teams
end
然后是助手方法
def load_premier_league_teams
get_the_teams_from_the_spreadsheet
end
def compile_statistics(teams)
results = []
teams.each do |t|
results << compile_team_stats(t)
...
end
现在,所有关于处理电子表格的内容都是在Cucumber之外用编程语言处理的
然后在When步骤中,您可以对每个团队执行以下操作
When "I compile the teams statistics" do
@results = compile_statistics(@teams)
end
并编写另一个助手方法
def load_premier_league_teams
get_the_teams_from_the_spreadsheet
end
def compile_statistics(teams)
results = []
teams.each do |t|
results << compile_team_stats(t)
...
end
def编译_统计数据(团队)
结果=[]
各队,各队|
结果