Top Level Namespace
Defined Under Namespace
Modules: AutoTest Classes: Time
Instance Method Summary collapse
- #add_path(value) ⇒ Object
- #add_to_sessions_array(session) ⇒ Object
- #clean_and_seed_db ⇒ Object
- #delete_groups(new_path) ⇒ Object
- #delete_ids(new_path) ⇒ Object
- #delete_links_half_way(new_path, indx, user) ⇒ Object
- #delete_links_without_input(new_path, number_of_links, session) ⇒ Object
- #delete_single_links(new_path) ⇒ Object
-
#enlarge_path(path_to_enlarge) ⇒ Object
> could be optimized depending on enlarging_counter add another part to the path.
- #enlarging_counter ⇒ Object
- #err_message ⇒ Object
- #find_next_path(session, path_to_try, lno) ⇒ Object
- #find_next_user(root_path, session) ⇒ Object
- #get_sessions(i, key) ⇒ Object
- #get_sessions_array ⇒ Object
- #inc_enlarging_counter ⇒ Object
- #init_enlarging_counter ⇒ Object
- #init_err_file ⇒ Object
- #init_hash_sessions(key, value) ⇒ Object
- #init_path ⇒ Object
- #init_sessions ⇒ Object
- #init_sessions_array ⇒ Object
- #init_user_inputs ⇒ Object
-
#jump_to_last_user(old_path) ⇒ Object
create a new path that starts with the last user of the old path that produced the error.
- #logger ⇒ Object
- #login(login_attributes, browser, user) ⇒ Object
- #max_enlarging_counter(whole_path) ⇒ Object
- #path ⇒ Object
- #replace_same_users!(new_path) ⇒ Object
- #search_sessions ⇒ Object
- #sessions(index, key, value) ⇒ Object
- #try_path(path_to_try) ⇒ Object
- #user_count(path_to_count) ⇒ Object
- #user_inputs(key) ⇒ Object
Instance Method Details
#add_path(value) ⇒ Object
81 82 83 |
# File 'lib/simulation.rb', line 81 def add_path(value) @path << value end |
#add_to_sessions_array(session) ⇒ Object
69 70 71 |
# File 'lib/simulation.rb', line 69 def add_to_sessions_array(i,session) @sessions_array[i] = session end |
#clean_and_seed_db ⇒ Object
931 932 933 934 935 936 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 931 def clean_and_seed_db DatabaseCleaner.strategy = :truncation DatabaseCleaner.start DatabaseCleaner.clean load "#{Rails.root}/db/test_seeds.rb" end |
#delete_groups(new_path) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 470 def delete_groups(new_path) for i in 0..get_sessions_array.size - 1 do no_of_group = 1 no_of_groups = 1 tmp = [] while no_of_group <= no_of_groups do count = 0 no_of_groups = 0 next_path = [] new_path.each_with_index do |n,ind| if n.class != String then if n.keys[0].split(":").second == user_inputs("get_login_path") && n.keys[0].split(":").first.to_i == i then count = count + 1 end if !(n.keys[0].split(":").first.to_i == i && count == no_of_group) then next_path << n else tmp << n end else next_path << n end end error_not_found = try_path(next_path) if error_not_found && tmp != [] then no_of_group = no_of_group + 1 else new_path = next_path end new_path.each do |n| if n.class != String && n.keys[0].split(":").first.to_i == i && n.values[0] == user_inputs("get_logout_path") then no_of_groups = no_of_groups + 1 end end tmp = [] end end return new_path puts new_path end |
#delete_ids(new_path) ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 446 def delete_ids(new_path) for i in 0..get_sessions_array.size - 1 do found_session = false index_to_delete = nil new_path.each_with_index do |n, index| if n.class == String && n.to_i == i then index_to_delete = index if !found_session && index_to_delete != index then new_path.delete_at(index_to_delete) end found_session = false else if (n.class != String && n.keys[0].split(":").first.to_i == i) then found_session = true end end end if !found_session then new_path.delete_at(index_to_delete) end found_session = false end end |
#delete_links_half_way(new_path, indx, user) ⇒ Object
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 531 def delete_links_half_way(new_path, indx, user) next_path = [] index = 0 id = 0 first_path = [] middle_path = [] while id <= user && index < new_path.size do if new_path[index].class == String then id = id + 1 if id < user || new_path[index + 1].class == String then if new_path[index + 1].class == String then id = id - 1 end first_path << new_path[index] index = index + 1 else if id == user then middle_path << new_path[index] index = index + 1 end end elsif id < user then first_path << new_path[index] index = index + 1 else middle_path << new_path[index] index = index + 1 end end if indx == nil then tmp = middle_path[0..middle_path.size/2] else tmp = middle_path[0..indx] end middle_path = tmp last_path = [] for i in index..new_path.size-1 do last_path << new_path[i] end next_path = first_path + middle_path + last_path return [next_path, middle_path.size] end |
#delete_links_without_input(new_path, number_of_links, session) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 379 def delete_links_without_input(new_path, number_of_links, session) next_path = [] no_inputs = true tmp = [] got_one = false done = false new_path.each do |n| done = false # check if the line is an ID if n.class == String then # check if it´s the right session if n.to_i == session then # add the line to the path next_path << n # save, that the part before was processed done = true # save, that the right session id has been found got_one = true else # for other session ids add the line to the tmp array tmp << n end else current_session = n.keys[0].split(":").first.to_i # if the right session id hasn´t been found, add the line to the path if current_session != session && !got_one then next_path << n # else add the line to the tmp array else tmp << n # check for input data for forms if n.values[0].class == Array && current_session == session then no_inputs = false end # if the part of the session to be deleted is finished, # has no inputs and is smaller or equal to the wanted number of links, # delete the links of the session, other links get added to the path if n.values[0] == user_inputs("get_logout_path") && no_inputs && current_session == session then if tmp.select{|x| x.class != String && x.keys[0].split(":").first.to_i == session}.size == number_of_links then tmp.delete_if{|x| x.class != String && x.keys[0].split(":").first.to_i == session} next_path << tmp tmp = [] done = true got_one = false else next_path << tmp tmp = [] done = true got_one = false end elsif n.values[0] == user_inputs("get_logout_path") && current_session == session then next_path << tmp tmp = [] done = true no_inputs = true got_one = false end end end end if !done then next_path << tmp end return next_path.flatten end |
#delete_single_links(new_path) ⇒ Object
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 511 def delete_single_links(new_path) i = 0 while i < new_path.size do if (new_path[i].class != String && !(new_path[i].values.include? user_inputs("get_logout_path")) && !(new_path[i].keys[0].include? user_inputs("get_login_path"))) then next_path = new_path[0..i-1]+new_path[i+1..new_path.size] error_not_found = try_path(next_path) if !error_not_found then new_path = next_path else i = i + 1 end else i = i + 1 end end return new_path end |
#enlarge_path(path_to_enlarge) ⇒ Object
> could be optimized
depending on enlarging_counter add another part to the path
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 851 def enlarge_path(path_to_enlarge) if enlarging_counter < max_enlarging_counter(path_to_enlarge)-1 then inc_enlarging_counter else return path_to_enlarge end last_path = jump_to_last_user(path_to_enlarge) additional_path = [] id_count = 0 index = 0 while id_count < enlarging_counter do additional_path << path_to_enlarge[index] index = index + 1 if path_to_enlarge[index].class == String && (path_to_enlarge[index].end_with? "ID") then id_count = id_count + 1 end end return additional_path + last_path end |
#enlarging_counter ⇒ Object
827 828 829 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 827 def enlarging_counter @counter end |
#err_message ⇒ Object
944 945 946 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 944 def @err_message end |
#find_next_path(session, path_to_try, lno) ⇒ Object
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 791 def find_next_path(session, path_to_try, lno) root = "" stop = false while lno < path_to_try.size && !stop do line = path_to_try[lno] if line.class != String && line.keys[0].split(":").first.to_i == session then root = line.keys[0].split(":").second.delete("0-9") stop = true elsif line.class == String && line.split(":").first.to_i == session then stop = true end lno = lno + 1 end return root end |
#find_next_user(root_path, session) ⇒ Object
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 807 def find_next_user(root_path, session) index = 0 u = 0 user_size = Kernel.const_get(user_inputs("user_class")).find(:all).size while u < user_size do user = Kernel.const_get(user_inputs("user_class")).find(:first, :conditions => "id > #{index}") index = user.id session.visit user_inputs("get_login_path") user_inputs("get_login_attributes").each do |la| session.fill_in la[1], :with => user.send(la[0].to_sym) end session.all('input').find_all{ |i| i[:type] == "submit"}.first.click if session.current_path == root_path then return user end u = u + 1 end return false end |
#get_sessions(i, key) ⇒ Object
915 916 917 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 915 def get_sessions(i, key) @sessions["#{i}"]["#{key}"] end |
#get_sessions_array ⇒ Object
61 62 63 |
# File 'lib/simulation.rb', line 61 def get_sessions_array @sessions_array end |
#inc_enlarging_counter ⇒ Object
831 832 833 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 831 def inc_enlarging_counter @counter = @counter + 1 end |
#init_enlarging_counter ⇒ Object
835 836 837 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 835 def init_enlarging_counter @counter = 0 end |
#init_err_file ⇒ Object
938 939 940 941 942 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 938 def init_err_file err_file = File.new("lib/auto_test/log/errors.log", "r") err_file.gets @err_message = err_file.gets.split(/:/,2).first end |
#init_hash_sessions(key, value) ⇒ Object
907 908 909 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 907 def init_hash_sessions(key, value) @sessions["#{key}"] = value end |
#init_path ⇒ Object
77 78 79 |
# File 'lib/simulation.rb', line 77 def init_path @path = [] end |
#init_sessions ⇒ Object
903 904 905 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 903 def init_sessions @sessions = Hash.new end |
#init_sessions_array ⇒ Object
65 66 67 |
# File 'lib/simulation.rb', line 65 def init_sessions_array @sessions_array = [] end |
#init_user_inputs ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/simulation.rb', line 29 def init_user_inputs @user_inputs = Hash.new file = File.new("lib/auto_test/log/user_input.log", "r") while line = file.gets do b = line.split(/:/,2) @user_inputs["#{b[0].strip}"] = b[1].chop end @user_inputs.each do |k,v| if v.start_with? "[" then x = v.split("],[") result = [] x.each do |i| result << i.delete("[]\"").split(",") end result.each do |r| if r.class == String then r.strip! else r.each do |s| s.strip! end end end @user_inputs[k] = result end end end |
#jump_to_last_user(old_path) ⇒ Object
create a new path that starts with the last user of the old path that produced the error
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 874 def jump_to_last_user(old_path) # session of the last link that leads to the error last_session = old_path[old_path.size-1].keys[0].split(":").first.to_i new_path = [] tmp = [] old_path.each do |e| # search the last user of the last session if (e.class == String) && (e.end_with? "ID") && (e.to_i == last_session) then tmp = [] tmp << e end if (e.class != String) then tmp << e end end new_path = tmp return new_path end |
#logger ⇒ Object
3 4 5 |
# File 'lib/auto_test.rb', line 3 def logger Rails.logger end |
#login(login_attributes, browser, user) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simulation.rb', line 6 def login(login_attributes, browser, user) if user_inputs("use_db_users") then user_inputs("get_login_attributes").each do |field| browser.text_field(:label => field[1]).set user.send(field[0].to_sym) end sleep 1 else index = user_inputs("get_login_names").index(user_inputs("get_unique_login_attribute_name")) user.class.find(:all).each do |u| user_inputs("get_login_data").each do |d| if d[index] == u.send(user_inputs("get_unique_login_attribute_name").to_sym) then user_data = user_inputs("get_login_data")[index] end end end user_inputs("get_login_attributes").each_with_index do |field, i| browser.text_field(:label => field[1]).set user_data[i] end end sleep 2 browser.(:type => 'submit').click end |
#max_enlarging_counter(whole_path) ⇒ Object
839 840 841 842 843 844 845 846 847 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 839 def max_enlarging_counter(whole_path) count = 0 whole_path.each do |e| if e.class == String && (e.end_with? "ID") then count = count + 1 end end return count end |
#path ⇒ Object
73 74 75 |
# File 'lib/simulation.rb', line 73 def path @path end |
#replace_same_users!(new_path) ⇒ Object
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 574 def replace_same_users!(new_path) users = Array.new(get_sessions_array.size) last_paths = Array.new(get_sessions_array.size) i = 0 while i < new_path.size do if new_path[i].class == String then session = new_path[i].split(":").first.to_i if users[session] == new_path[i] then hash = Hash.new hash[last_paths[new_path[i].split(":").first.to_i]] = user_inputs("get_logout_path") new_path[i] = hash else users[session] = new_path[i] end else last_paths[new_path[i].keys[0].split(":").first.to_i] = new_path[i] end i = i + 1 end end |
#search_sessions ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/simulation.rb', line 85 def search_sessions path_to_search = File.new("lib/auto_test/log/new_path.log") sessions = Array.new while line = path_to_search.gets do line.gsub!(/[{}\"]/,'') if line.class == String then session = line.split(":").first.to_i else session = line.gsub!(/[{}\"]/,'').split(":").first.to_i end if !(sessions.include? session) then sessions << session end end return sessions end |
#sessions(index, key, value) ⇒ Object
911 912 913 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 911 def sessions(index, key, value) @sessions["#{index}"]["#{key}"] = value end |
#try_path(path_to_try) ⇒ Object
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 595 def try_path(path_to_try) clean_and_seed_db lno = 0 init_sessions init_sessions_array number_of_sessions = user_inputs("get_number_of_sessions").to_i for i in 0..number_of_sessions-1 do sess = Capybara::Session.new(:rack_test,Rails.application) add_to_sessions_array sess init_hash_sessions(i, Hash.new) end user = Array.new(number_of_sessions) session_paths = Array.new(number_of_sessions, "") old_session_paths = Array.new(number_of_sessions, "") session_index = 0 error_not_found = true begin lno = 0 # puts lno while lno < path_to_try.size do hash = Hash.new line = path_to_try[lno] if line.class == String then session = get_sessions_array[line.split(":").first.to_i] else session = get_sessions_array[line.keys[0].split(":").first.to_i] session_path = line.keys[0].split(":").second end session_index = get_sessions_array.index(session) lno = lno + 1 # puts lno if line.class == Hash then if line.values[0] == "Anmelden" then session.visit user_inputs("get_login_path") hash["#{session_index}:#{session.current_path}"] = session.all('input').find_all{ |i| i[:type] == "submit"}.first.value if user_inputs("use_db_users") then user_inputs("get_login_attributes").each do |field| session.fill_in field[1], :with => user[session_index].send(field[0].to_sym) end else index = user_inputs("get_login_names").index(user_inputs("get_unique_login_attribute_name")) user[session_index].class.find(:all).each do |u| user_inputs("get_login_data").each do |d| if d[index] == u.send(user_inputs("get_unique_login_attribute_name").to_sym) then user_data = user_inputs("get_login_data")[index] end end end user_inputs("get_login_attributes").each_with_index do |field, i| session.fill_in field[1], :with => user_data[i] end end session.all('input').find_all{ |i| i[:type] == "submit"}.first.click elsif line.values[0] == user_inputs("get_logout_path") then hash["#{session_index}:#{session.current_path}"] = user_inputs("get_logout_path") session.visit user_inputs("get_logout_path") elsif line.values[0].class == Array then inputs = line.values[0] if !session.all('input').empty? then i = 0 while i < inputs.size do if inputs[i].strip.start_with? "radio___" then session.choose inputs[i + 1].strip elsif inputs[i].strip.start_with? "select___" then session.select inputs[i + 1].strip, :from => inputs[i].gsub("select___",'').strip elsif inputs[i].strip.start_with? "checkbox___" then session.check inputs[i + 1].strip else input = session.all('input').find{ |inp| inp[:name] == inputs[i].strip} input.set(inputs[i+1].strip) end i = i + 2 end hash["#{session_index}:#{session.current_path}"] = path_to_try[lno - 1].values[0] session.all('input').find_all{ |i| i[:type] == "submit"}.first.click else hash = path_to_try[lno-1] end else if session.current_path.delete("1-9") != session_path.delete("1-9") then session.visit session_path end link = line.values[0].split(/\+\+\+/) href = link[0].to_s text = link[1] path = session.current_path root = find_next_path(session_index, path_to_try, lno) old_p = href.split("/") # => check for ids in string links = session.all('a').select{ |l| (l[:href].to_s.delete("0-9") == href.delete("0-9")) && l.text == text} links_selected = links + [] j = 1 compare_string = "" new_split = session_paths[session_index].split("/") old_split = old_session_paths[session_index].split("/") while old_p[j] == old_split[j] && old_p[j] != nil do if new_split[j] != nil then compare_string << ("/" + new_split[j]) if old_p[j].to_i.to_s == old_p[j] then links_selected = links_selected.select{ |l| l[:href].to_s[0..compare_string.size-1] == compare_string } end end j = j + 1 end for i in 0..get_sessions_array.size - 1 do compare_string = "" if i != session_index then old_sess_p = old_session_paths[i].split("/") new_sess_p = session_paths[i].split("/") j = 1 while old_p[j] == old_sess_p[j] && old_p[j] != nil do compare_string << "/" + new_sess_p[j] j = j + 1 end links_selected = links_selected.select{ |l| l[:href].start_with? compare_string } if new_sess_p[j] != nil then compare_string << ("/" + new_sess_p[j] ) end # if the string is an id if old_p[j].to_i.to_s == old_p[j] && new_sess_p[j] != nil && new_sess_p[j].to_i.to_s == new_sess_p[j] then links_selected = links_selected.select{ |l| !(l[:href].start_with? compare_string) } end end end if links.size > 0 then if links_selected.size > 0 then link = links_selected[session_index % links_selected.size] else link = links[session_index % links.size] end old_session_paths[session_index] = href session_paths[session_index] = link[:href].to_s hash["#{session_index}:#{path}"] = "#{link[:href]}+++#{link.text}" link.click next_path = session.current_path.delete("0-9") if next_path != root then session.visit path end else hash = path_to_try[lno - 1] end end path_to_try[lno-1].replace(hash) else # if there´s no authorization, no Strings will be saved in the path if user_inputs("use_db_users") then id = line.split(":").second.to_i begin user[session_index] = Kernel.const_get(user_inputs("user_class")).find(id) rescue index = lno + 1 root_path = "" while root_path == "" && index < path_to_try.size do if path_to_try[index].class != String then if path_to_try[index].keys[0].split(":").first.to_i == session_index then if path_to_try[index].keys[0].split(":").second != user_inputs("get_login_path") then root_path = path_to_try[index].keys[0].split(":").second end end index = index + 1 else index = index + 1 end end user[session_index] = find_next_user(root_path, session) end else user[session_index] = Kernel.const_get(user_inputs("user_class")).find(id) end if user[session_index] == false then return error_not_found else path_to_try[lno - 1] = "#{session_index}:#{user[session_index].id}ID" end end end rescue => e if == e..to_s.split(/:/,2).first then #puts "Found Error again, go on..." error_not_found = false else f = File.new("lib/auto_test/log/debugging.log", "w") f.puts path_to_try f.close # puts "Different Error:" + e.message.to_s # puts lno # puts line error_not_found = true end return error_not_found end return error_not_found end |
#user_count(path_to_count) ⇒ Object
893 894 895 896 897 898 899 900 901 |
# File 'lib/spec/requests/error_reduction_spec.rb', line 893 def user_count(path_to_count) count = 0 path_to_count.each do |e| if e.class == String then count = count + 1 end end return count end |
#user_inputs(key) ⇒ Object
57 58 59 |
# File 'lib/simulation.rb', line 57 def user_inputs(key) @user_inputs[key] end |