source: tests/webtestlib @ 3b59591

Last change on this file since 3b59591 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 3.3 KB
Line 
1#!/bin/bash
2# (C)2009 DatuX - Released under GPL
3
4# Testlibrary voor webpaginas, gebruikt webinject.pl hiervoor.
5# Zie testscripts voor voorbeelden
6
7export PERL_LWP_SSL_VERIFY_HOSTNAME=0
8WEBINJECTDIR="webinject"
9WEB_TESTFILE="$WEBINJECTDIR/webtest_tmp.xml"
10WEB_TESTID=0;
11
12
13#Roep eerst web_new aan om een nieuwe test te beginnen
14#Variabellen voor web_add:
15# URL=Op de vragen url.
16# DESCRIPTION1= omschrijving
17# METHOD= get (standaard) of post
18# POSTBODY= post-data
19# VERIFYPOSITIVE= tekst voor goed resultaat
20# VERIFYNEGATIVE= tekst voor negatief resultaat
21# VERIFYRESPONSECODE= http reponsecode moet hier aan voldoen
22#Roep hierna scc_run aan om te tests uit te voeren.
23
24#voeg losse test toe
25web_add()
26{
27        (( WEB_TESTID++ ))
28        echo "<case " >> $WEB_TESTFILE
29       
30        echo "id='$WEB_TESTID'" >> $WEB_TESTFILE
31       
32        if [ "$DESCRIPTION1" ]; then
33                #echo -e "description1='\e[1;32m### scctest: $DESCRIPTION1\e[0m'" >> $WEB_TESTFILE
34                echo -e "description1='### webtest: $DESCRIPTION1 (op $URL)'" >> $WEB_TESTFILE
35                DESCRIPTION1=
36        fi     
37       
38        if [ "$METHOD" ]; then
39                echo "method='$METHOD'" >> $WEB_TESTFILE
40                METHOD=
41        fi     
42       
43        echo "url='$URL'" >> $WEB_TESTFILE
44        URL=
45       
46        if [ "$VERIFYPOSITIVE" ]; then
47                echo "verifypositive='$VERIFYPOSITIVE'" >> $WEB_TESTFILE
48                VERIFYPOSITIVE=         
49        fi
50       
51        if [ "$VERIFYPOSITIVE2" ]; then
52                echo "verifypositive2='$VERIFYPOSITIVE2'" >> $WEB_TESTFILE
53                VERIFYPOSITIVE2=               
54        fi
55       
56        if [ "$VERIFYNEGATIVE" ]; then
57                echo "verifynegative='$VERIFYNEGATIVE'" >> $WEB_TESTFILE
58                VERIFYNEGATIVE=
59        fi
60       
61        if [ "$VERIFYNEGATIVE2" ]; then
62                echo "verifynegative2='$VERIFYNEGATIVE2'" >> $WEB_TESTFILE
63                VERIFYNEGATIVE2=
64        fi
65
66        if [ "$VERIFYRESPONSECODE" ]; then
67                echo "verifyresponsecode='$VERIFYRESPONSECODE'" >> $WEB_TESTFILE
68                VERIFYRESPONSECODE=
69        fi
70       
71        if [ "$PARSERESPONSE" ]; then
72                echo "parseresponse='$PARSERESPONSE'" >> $WEB_TESTFILE
73                PARSERESPONSE=
74        fi
75
76        if [ "$POSTBODY" ]; then
77                if [ "$POSTTYPE" == "text/xml" ]; then
78                        #store xml request in seperate xml file:
79                        echo "$POSTBODY" > $WEBINJECTDIR/post$WEB_TESTID.xml
80                        echo "postbody='file=>post$WEB_TESTID.xml'" >> $WEB_TESTFILE
81                else
82                        echo "postbody='$POSTBODY'" >> $WEB_TESTFILE
83                fi
84                POSTBODY=
85        fi
86
87        if [ "$POSTTYPE" ]; then
88                echo "posttype='$POSTTYPE'" >> $WEB_TESTFILE
89                POSTTYPE=
90        fi
91
92        echo "/>" >> $WEB_TESTFILE
93       
94}
95
96#maak nieuwe testreeks aan.
97#nieuwe tests moe tje toevoegen met web_add
98web_new()
99{
100        echo "<testcases repeat='1'>" > $WEB_TESTFILE
101        WEB_TESTID=0
102       
103}
104
105#voert de huidge testreeks uit. returned 1 bij failed tests
106web_test()
107{
108        #beeindig testset eerst:
109        echo "</testcases>" >> $WEB_TESTFILE
110
111        if ! [ "$TIMEOUT" ]; then
112                TIMEOUT=3600
113        fi
114
115        cd $WEBINJECTDIR || return 1
116       
117        #maak config
118        echo "<globalhttplog>yes</globalhttplog>" > config.tmp.xml
119        echo "<timeout>$TIMEOUT</timeout>" >> config.tmp.xml
120
121       
122        #voer test uit:
123        echo "Running webinject tests:"
124        RET=0
125        if ! ./webinject.pl -c config.tmp.xml webtest_tmp.xml; then
126            echo "tip: controleer laatste logregels met:"
127            echo "cat webinject/http.log |egrep -v '^ $'|less"
128            RET=1
129        fi
130        cd ..
131        if grep FAILED $WEBINJECTDIR/results.xml &>/dev/null; then
132                echo "There where failed tests!";
133                RET=1
134        fi
135       
136        TIMEOUT=
137       
138        #deze is klaar, begin een nieuwe test
139        web_new
140        return $RET
141}
142
143
144web_new
145
146#Voorbeeld:
147# DESCRIPTION1=""
148# URL=""
149# VERIFYNEGATIVE=""
150# VERIFYPOSITIVE=""
151# METHOD="post"
152# POSTBODY=""
153# web_add
Note: See TracBrowser for help on using the repository browser.