Class: Batch_Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/RubySelenium.rb

Instance Method Summary collapse

Constructor Details

#initialize(ruby_tests_location = DEFAULT_RUBY_TEST_LOCATION) ⇒ Batch_Generator

Returns a new instance of Batch_Generator.



849
850
851
852
# File 'lib/RubySelenium.rb', line 849

def initialize(ruby_tests_location = DEFAULT_RUBY_TEST_LOCATION)
    @ruby_tests_location = ruby_tests_location
    @generate_location = COMMAND_GENERATE_LOCATION 
end

Instance Method Details

#build_tests_arrayObject



866
867
868
869
870
871
872
# File 'lib/RubySelenium.rb', line 866

def build_tests_array
    tests_array = []
    build_tests_list.each do |test|
        tests_array << File.readlines(test)
    end
tests_array
end

#build_tests_listObject



854
855
856
857
858
859
860
861
862
863
864
# File 'lib/RubySelenium.rb', line 854

def build_tests_list
    test_list = []
    Dir.entries(@ruby_tests_location).each do |file|
        if file.match(/^[\d]{3}_/) then test_list << "#{@ruby_tests_location}/#{file}" end 
    end
    if test_list.size == 0
        raise MissingRubyTestFiles, "Can't find any rubySelenium tests in directory #{@ruby_tests_location}"
    else 
        return test_list.sort 
    end   
end

#create_all_test_filesObject



903
904
905
906
907
908
909
910
# File 'lib/RubySelenium.rb', line 903

def create_all_test_files
    delete_html_files
    remove_go_commands_from_tests_array.each do |test|
        if LOGGING then File.open("generate_log.txt","a"){|f| f.puts Time.now, test.to_s} end
        eval test.to_s
    end
create_test_suite_file_for_all_files
end

#create_test_suite_file_for_all_filesObject



889
890
891
# File 'lib/RubySelenium.rb', line 889

def create_test_suite_file_for_all_files
    File.open("#{@generate_location}/seleniumTestSuite.html", "w"){|f| f.print generate_test_suite_for_all_files} 
end

#delete_html_filesObject



899
900
901
# File 'lib/RubySelenium.rb', line 899

def delete_html_files
    find_html_contents_of_generation_directory.each{|file| if File.exists?(file) then File.delete(file) end }
end

#find_html_contents_of_generation_directoryObject



893
894
895
896
897
# File 'lib/RubySelenium.rb', line 893

def find_html_contents_of_generation_directory
    html_array = []
    Dir.entries(@generate_location).each{|file| if file.split(".")[1] == "html" then html_array << "#{@generate_location}/#{file}" end }
html_array
end

#generate_test_suite_for_all_filesObject



880
881
882
883
884
885
886
887
# File 'lib/RubySelenium.rb', line 880

def generate_test_suite_for_all_files
    test_suite_content = []
    build_tests_list.each do |filename|
        test_name = filename.split("/")[1].split(".")[0]
        test_suite_content << "<tr><td><a href=\"#{test_name}.html\">#{test_name}</a></td></tr>\n"
    end
Templates.new("test_suite", "test_suite", test_suite_content).selenium_test_suite    	
end

#go(browser = "IE") ⇒ Object



912
913
914
915
916
# File 'lib/RubySelenium.rb', line 912

def go(browser = "IE")
    if browser == "IE" then myBrowser = IE_PATH elsif browser == "FireFox" then myBrowser = FF_PATH end
    create_all_test_files
    Thread.new{system("#{myBrowser} #{GO_PATH}/tests/seleniumTestRunner.html?auto=true")}
end

#remove_go_commands_from_tests_arrayObject



874
875
876
877
878
# File 'lib/RubySelenium.rb', line 874

def remove_go_commands_from_tests_array
    build_tests_array.each do |test|
        test.each{|line| if line.match(/^\w+\.go/) then test.delete(line) end}  
    end
end