Ruby和Minitest的Webdriver。在测试套件之间共享测试用例代码

时间:2016-02-15 15:45:46

标签: ruby selenium-webdriver webdriver

我需要在一组套件之间共享测试代码,但问题是我不知道如何在单独的文件中定义测试用例,因此每个其他测试套件都可以使用相同的测试用例。

这是我的文件示例:

test_api.rb:

require_relative 'test_helper'
require 'rubygems'
require 'minitest/spec'
require 'minitest/autorun'
#require 'minitest/hell'
require 'uri'
require 'net/http'
require 'mysql2'
require 'json'
require 'digest/sha1'
require_relative 'cases_api_shared.rb'

class API_pc_qubit
    #parallelize_me!
    def setup

        ### DEFINITIONS

        ### URL
        ENV['ws_url'] = 'http://.../'

        ### DATA DEFINITION (USERNAME, PASSWORD, ETC)
        ENV['username'] = 'user'
        ENV['password'] = 'pass'

        ### DEVICE = PC
        ENV['APK_ID'] = "1"
        ENV['APK_SECRET'] = "secret"
    end

    def test_user_create

        # User registration test case

        case_user_create
    end

    def test_user_login

        # User login test case

        case_user_login
    end

    def test_content_search

        # Search for content test case

        case_content_search
    end

    def test_utils_channels

        # channels test case

        case_utils_channels
    end

    def test_content_list

        # Content list case

        case_content_list
    end

    def test_user_modify

        # Change user data test case

        case_user_modify
    end

    def test_user_change_suscription

        # Change user suscription test case

        case_user_change_suscription
    end

    def test_user_favorite

        # User profiles test case

        case_user_favorite
    end

    def test_commercial_buyandplay

        # Change user login password test case

        case_commercial_buyandplay
    end

    #def test_content_status
    #   
    #   # Test content status currenttime test case
    #   
    #   case_content_status
    #end

    def teardown

    end

end

这是cases_api_share.rb文件的示例:

   require_relative 'obj_api_shared.rb'

def case_user_create

    # User registration test case

    case code...
end

def case_user_login

    # User login test case

    another test code...
end

但是当我运行套件时,它没有在'cases_api_share'中运行代码:

ruby tests/test_api.rb 
Started with run options --seed 30622


Finished in 0.00055s
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

1 个答案:

答案 0 :(得分:1)

这可能是重复的。见here。 基于此,这是一个例子。

如果你想进行分组测试,有一种简单的方法,只需在测试文件中使用自动运行,并且需要测试文件。

#suit1.rb
require './test1.rb'
#suit2.rb
require './test1.rb'
require './test2.rb'
#test1.rb
require 'minitest/autorun'
class TestOne < MiniTest::Unit::TestCase
  def test_one
     assert_equal 1, 1
   end
end
#test2.rb
require 'minitest/autorun'
class TestTwo < MiniTest::Unit::TestCase
  def test_two
     assert_equal 2, 2
   end
end

您可以单独运行套装或每项测试:

ruby suit1.rb
ruby suit2.rb
ruby test1.rb
ruby test2.rb

您可以获取示例代码here