Reputation: 645
I'm new to Cucumber/Capybara, I want to know How Can I Import data from txt/xls files using Cucumber/Capybara
for example I need to use next Scenario to Upload several files one after another :
feature
Scenario: Upload
When I Choose A name "name"
When I Choose "/home/path"
Then I Click Upload
step_definitions
When(/^I Choose A name "([^"]*)"$/) do |title|
fill_in('video_title', :with => title)
fill_in('video_description', :with => title)
end
When(/^I Choose "([^"]*)"$/) do |file|
find(:xpath, '//*[@id="file"]', :visible => false).set(file)
end
Then(/^I Click Upload$/) do
click_button('Upload')
end
so if i can add step definition to import from txt or xls that will be much easier then repeating Scenario for every file
Upvotes: 0
Views: 623
Reputation: 419
I'm not sure I understand your question. To clarify, are you saying that you want to do this same basic thing for several files? If so, here's how I would do it:
Feature:
Scenario Outline: Upload
When I upload a video named "<name>" from path "<path>"
Examples:
| name | path |
| foo | /path/1 |
| bar | /path/2 |
| baz | /path/3 |
Steps:
When(/^I choose a name "(.*)"$/) do |name|
fill_in('video_title', :with => name)
fill_in('video_description', :with => name)
end
When(/^I choose "([^"]*"$/) do |file|
find(:xpath, '//*[@id="file"]', :visible => false).set(file)
end
When(/^I click "([^"]*"$/ do |button|
click_button(button)
end
When(/^I upload a video named "[^"]*" from path "[^"]*"$/ do |title, path|
step 'I choose a name "' + title + '"'
step 'I choose "' + path + '"'
step 'I click "Upload"'
end
This is assuming you're using the other steps in some other scenario. If you're not, it would make more sense to just define the one step 'I upload a video named "" from path ""'.
If this doesn't answer your question, please let me know what you need different and I'll see if I can help.
Upvotes: 1