2017-01-17 9 views
0

RakeとRspecを使用してオートメーションテストケースをパラレルで実行するという概念のサンプルを作成しました。しかし、rkeecファイルに渡されたパラメータを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 

iはすくいファイルに渡されたパラメータ(123456 & 8888,1111)を取得したいです。 アドバンスのヘルプ!

+0

どのように? – bsvin33t

答えて

0

あなたは、引数を指定するには、この方法を持っています:レールのenv VARとして設定に関する

namespace :mynamespace do 
    desc "my description" 
    task :my_task, [:arg1, :arg2] do |task, args| 
    do_something_with(args[:arg1], args[:arg2]) 
    end 
end 
関連する問題