Class: TC_R001_01_AN_EXAMPLE_TEST

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
ZZnamezzTestCase
Defined in:
lib/taft_files/tests/v1/tc_r001_01_an_example_test.rb

Constant Summary

Constants included from ZZnamezzTestCase

ZZnamezzTestCase::WRITE_RESULTS

Instance Attribute Summary

Attributes included from ZZnamezzTestCase

#browser_has_been_opened, #failure_notes

Instance Method Summary collapse

Methods included from ZZnamezzTestCase

#browser, #browser=, #close, #close_all_browsers, #close_browser, #load_pages, #method_missing, #teardown, #xxabbrevxx_login

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ZZnamezzTestCase

Instance Method Details

#setupObject



8
9
10
11
12
13
14
# File 'lib/taft_files/tests/v1/tc_r001_01_an_example_test.rb', line 8

def setup
    # specify setup parameters
    @certificate = :regular # this is the default user for this test
    @initialBrowser = :none # if you want this test to navigate to your webapp automatically as part of setup, change this value to the value referring to your webapp

    super # must call super so that the common setup method in ZZnamezzTestCase is called
end

#test_r001_01_an_example_testObject



16
17
18
19
20
21
22
23
24
25
26
27
28
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/taft_files/tests/v1/tc_r001_01_an_example_test.rb', line 16

def test_r001_01_an_example_test

    ############################################################################################
    # PURPOSE :
    #   Verify that <description of your test's intent>
    # 
    # PRECONDITIONS :
    #   <list your preconditions>
    ############################################################################################

    filename = "data_for_example_test.csv" # file must be in the data/ directory
    data = @help.read_csv_test_data(filename)
    header = data.shift

    # Step 1 :
    #   Send a request to the yyrawnameyy API Options method

    random_row = data.random
    search_term = random_row[0]
    expected_result_count = random_row[1]

    # This is too raw - it would be better to bundle these lines into a separate "search_options" method,
    # with additional validation (e.g. to throw a clean error if the request failed)
    @client = @help.get_rest_client(:options, @certificate, search_term)
    json = client.get
    response = JSON.pretty_unparse(json)

    # Expected Result :
    #   The request has succeeded & returned the expected results

    # This is quite brittle
    # A better approach is to create a new class which would parse the response & convert
    # it into a bespoke Object, so that the various values could be accessed in a better OO-fashion.
    # E.g. response.number_of_results. The object could also have extra methods, 
    # e.g. response.check_results_are_valid, and so on.
    assert_equal(expected_result_count, response["number_of_results"], "The search request did not return the expected number of results")

    
    # Step 2 :
    #   Log in to yyrawnameyy

    

    # Expected Result :
    #   The yyrawnameyy homepage is displayed

    assert(xxabbrevxxHomepage.displayed?, "The yyrawnameyy homepage is not displayed")

    
    # Step 3 :
    #   Enter in a search term and click the Search button.

    data.each do |row|
        search_term = row[0]
        expected_result_text = row[2]
        puts "Will now search for '#{term}'; expect to see '#{expected_result_text}'"

        xxabbrevxxHomepage.term = search_term
        xxabbrevxxHomepage.click_search


        # Expected Result :
        #   Results are displayed

        assert(xxabbrevxxSearchResults.displayed?, "The yyrawnameyy search results page is not displayed")
        assert_equal(expected_result_text, xxabbrevxxSearchResults.result, "The yyrawnameyy search results page did not display the expected result")

    
        # Step 4 :
        #   Return to the previous page

        browser.back



        # Expected Result :
        #   The yyrawnameyy homepage is displayed
        
        assert(xxabbrevxxHomepage.displayed?, "The yyrawnameyy homepage is not displayed")

        
        # Step 5 :
        #   Repeat steps 3 and 4 for a few more search terms

        # Actions performed in above steps


        # Expected Result :
        #   Results are displayed for each term

        # Assertions performed in above steps
   
    end # end .each

end