2017-01-17 17 views
0

我已經完成了使用Rake和Rspec並行執行自動化測試用例的概念示例。但是不知道如何將rake文件中傳入的參數傳遞給rspec文件。任何人都請幫忙。如何在Rspec中獲取Rake文件參數

樣品耙文件: -

require 'rspec/core/rake_task' 
RSpec::Core::RakeTask.new(:spec) 
namespace :spec do 
    task :foo, :arg1, :arg2 do |t, args| 
     do_something 
    end 

    desc "Run the unit specs" 
    RSpec::Core::RakeTask.new(:unit, :arg1, :arg2) do |t, args| 
    puts "#{args}" 
    t.pattern = "test_spec.rb" 
    end 

    desc "Run the integration specs" 
    RSpec::Core::RakeTask.new(:integration, :arg1, :arg2) do |t, args| 
    puts "#{args}" 
    t.pattern = "test_spec.rb" 
    end 
end 

task:int do 
    Rake::Task["spec:integration"].invoke(123,456) 
end 

task:uint do 
    Rake::Task["spec:unit"].invoke(8888,1111) 
end 

multitask :all => ["int", "uint"] 

Rspec的文件: -

require "selenium-webdriver" 
require "rspec" 

describe "Test Execution" do 

    before(:each) do 
    @driver = Selenium::WebDriver.for :firefox 
    @base_url = "http://xxxxxxxxxxxxx.com" 
    @accept_next_alert = true 
    @driver.manage.timeouts.implicit_wait = 30 
    @driver.manage.window.maximize 
    end 

    it "Executing testcase steps" do 

    @driver.get(@base_url + "/") 
    @driver.find_element(:id, "employee_email").send_keys "[email protected]" 
    @driver.find_element(:id, "password").send_keys "1234" 
    @driver.find_element(:id, "login_submit").click 
    end 

    after(:each) do 
    @driver.quit 
    end 
end 

在這裏,我想在耙文件傳遞的參數(123456 & 8888,1111)。 提前幫助!

+0

如何設置它作爲一個軌道的環境變量? – bsvin33t

回答

0

您必須指定的參數是這樣的:

namespace :mynamespace do 
    desc "my description" 
    task :my_task, [:arg1, :arg2] do |task, args| 
    do_something_with(args[:arg1], args[:arg2]) 
    end 
end