场景大纲:验证完整的广告详情
鉴于我在xxxxx分类主页上
我已进入搜索领域&点击搜索
当我点击完整的详细信息时
然后我应该看到<
AdvertId> <
标题> <
描述> <
国家或地区名称> <
价格>
<
ThumbnailImage> <
PartExchange> <
电话和GT; <
AltPhone> <
地点>正确而成功地显示
Examples:
|AdvertId|Headline|Description|CountryName|Price|ThumbnailImage|PartExchange|Phone|AltPhone|Location|
|219|V12 Vantage Coupe|Powerfold mirrors,Alcantara steering wheel,HID projector headlamps,Electronic brakeforce distribution (EBD),LED rear lamps,Emergency brake assist (EBA),Aston Martin 160 W audio system,Dynamic stability control with Track mode (DSC),Electrically adjustable front seats,Trip computer,Tyre pressure monitoring,Bluetooth telephone preparation,Auto dimming interior rear view mirror,Memory seats and exterior mirrors,Ventilated, carbon ceramic disc brakes with ABS,Aluminium, magnesium alloy, composite and steel body,Side airbags (sports seats only),iPod integration and MP3 connectivity,Carbon fibre door pulls,Rear parking sensors,Hard Disk Drive (HDD) Satellite navigation system,Cruise control,Alarm and immobiliser,Boot-mounted umbrella,Dual stage driver and passenger front airbags|Costa Rica|99000|http://img.pistonheads.com.s3-eu-west-1.amazonaws.com/Thumbnail/aston_martin/v12_vantage/aston_martin-v12_vantage-1012-1.jpg||08444119220||Costa Rica|
|221|V8 Vantage Coupe 4.7|Side Airbags,Dynamic stability control (DSC),Ventilated, grooved disc brakes with ABS,Aston Martin 160 W audio system, Alarm and immobiliser,Emergency brake assist (EBA),Electronic brakeforce distribution (EBD),Rear parking sensors,6 CD autochanger,Electrically adjustable front seats,LED Rear Lamps,Dual stage driver and passenger front airbags,Tyre pressure monitoring,Trip computer,Full leather interior|Denmark|52906|http://img.pistonheads.com.s3-eu-west-1.amazonaws.com/Thumbnail/aston_martin/v8_vantage/aston_martin-v8_vantage-966-1.jpg||08444119218||Denmark|
在尝试使用适当的正则表达式定义步骤定义时,我需要帮助。同样在场景中我只展示了两个例子。有没有办法只编写一行代码和步骤定义,这适用于任意数量的行示例?
非常感谢任何对这种绝望情况的回答。
答案 0 :(得分:1)
因此正则表达式可以告诉一个值结束而另一个值开始的位置,您应该在每个值周围添加引号。所以这一步将写成:
Then I should see "<AdvertId>" "<Headline>" "<Description>" "<CountryName>" "<Price>" "<ThumbnailImage>" "<PartExchange>" "<Phone>" "<AltPhone>" "<Location>" displaying correctly and successfully
然后您可以使用以下方式轻松匹配:
Then /I should see "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" displaying correctly and successfully/ do |advert_id, headline, description, country_name, price, thumbnail_image, part_exchange, phone, alt_phone, location|
请注意,您拥有的示例数量无关紧要。唯一重要的是你的例子的内容。除非您在其中一个值中加上引号,否则上述情况应该有效。
另一种方法是单独编写每张支票:
Then I should see the advert id "<AdvertID>" displaying correctly and successfully
Then I should see the headline "<Headline>" displaying correctly and successfully
etc
匹配:
Then /I should see the advert id "(.*)" displaying correctly and successfully/
Then /I should see the headline "(.*)" displaying correctly and successfully/
etc
单独编写每个单词可以更容易地找出失败的内容并更容易编写正则表达式。但是,如果检查不是独立的,单步可能是最佳选择。