From: Doug F. <dou...@do...> - 2004-02-17 19:21:52
|
This sounds like a good start. I suggest a multi-phase approach: we can refactor the existing code, one object at a time (session, request, response), before we get into scripting. We may have to modify the infrastructure when we start embedding Python, but it should be pretty well in place. Quoting Joe Griffin <joe...@us...>: > Here's a first draft of the 'spec' for Addanc's Python Code Support. > > Comments/ectc. requested. > > I want to review the sample syntax a bit more. And generate a more 'test' > scripts. > > Joe > > ================================================= > Proposal for Python Code Support in Addanc Scripts > > Background/Justification > > The existing Addanc scripting support can handle only simply record/playback > scenarios for form fields and query strings. > > More realistic and revealing tests could be accomplished if the Addanc > scripting > support gave programmatic access to transaction status and content (headers, > form fields, querystrings, body/DOM, and attachments). Branching and > "on-the-fly" request generation would further enhance the testing > capabilities. > > The Addanc scripting model can be extended by using embedded Python and > "describing" the behavior of each page using python code operating on a > standard set of objects like a session object, a transaction object, and a > response object. > > Python Code Support > > The Addanc script will include Python Code Support (PCS) if there exists a > file > in the same directory as the script .XML file with the same "root" name as > the > script file but with a .py extension; e.g, my_script.xml and my_script.py > both > in the /home/myacct/addanctest directory. > > For the purposes of this discussion, we will use this nomenclature: > - Script Description File (SDF) will refer to the .XML file > - Script Code File (SCF) will refer to the .py file > > The Script Code File (SCF) is a Python source file containing one or more > function definitions. Functions in the SCF file are associated with > transactions ing the SDF via the Transaction ID. Functions with the names > <transaction_id>_pre() and <transaction_id_>_post() should be defined in the > SCF for any transaction in the SDF file that requires preparation or special > post handling. > > The <transaction_id>_pre(session_object, request_object[, response_object]) > will > be called after the request object has been built using the "default" values > from the SDF file but before starting the transaction. The response_object > will > be the response_object after the _post() processing is performed on the > previous transaction. > > The <transaction_id>_post(session_object, response_object) will be called > after > the transaction is completed or has failed. > > PCS Objects > > Addanc's Pythoc Code Support exposes three objects: > - a Session Object packaging information the extends over the lifetime of > a VC, > - a Request Object packaging the information/data to be sent to s SUT as > part of the HTTP request/response sequence. > - a Response Object packaging information received from ther SUT as part > of the HTTP request/response sequence > > The Session Object supports the following properties/members: > .globals - Contains generic script globals for this session > .cookies - Container for cookies > .session_status - One of OK|REQUEST_ERROR|RESPONSE_ERROR|INTERNAL_ERROR > .next_page - Page Id of the next transaction to execute. > If .eq. None - stop this VC. > If current PAGE has multiple transactions, execution branching > will happen only if this property is changed to a value that > differs from the current Page Id) > .next_wait - Defines delay time after receiving current transaction before > starting request for next transaction. (AKA Sleep or read > time.) > > The Request Object has the following properties/members: > .operation - One of POST|GET > .query_string_dict - dictionary of Query String key/val pairs > .field_dict - dictionary of form field key(field)/val pairs > .headers - dictionary of header key/val pairs > .url - target URL > > The Response Object has the following properties/members: > .url_feched - url of informatrion returned as result of request > .redirect_count - NUmber of URLs visited to resolve Response Object > .HTTPstatus - HTTP status of result > .headers - Dictionary of headers returned > .source - Raw text response returned > > > ======================================================= > Simple PCS Example: > > Snippet from file PCS_test_001.xml > > <page id='WestWingHome'> > <url > id="Potus">http://addanc.testsite.downright.com/cgi-bin/potus-v1</url> > <wait>2.000</wait> > </page> > > <page id='WestWingLogin'> > <url id="PotusLogin" > op="post">http://addanc.testsite.downright.com/cgi-bin/potus-v1 > <formfield name="loginid" type="text">joeg</formfield> > <formfield name="passwd" type="password">geoj</formfield> > </url> > <wait>2.000</wait> > </page> > > > > Sinppet fom filePCS_test_001.py: > > #filePCS_test_001.py > > def Potus_pre(session_object, request_object): > """ Called BEFORE executing operation on page """ > # Build a dictionaries of Login Identies for the post test > # Dictionary is indexed by ID, returns password > session_object.globals.identies = {} > session_object.globals.identies['joeg':'geoj'] > session_object.globals.identies['doug':'guod'] > session_object.globals.identies['addanc':'cnadda'] > > return > > import random > > def Potus_post(session_object, response_object): > """ Called AFTER executing operation on page """ > if session_object.session_status == OK: > # Set the wait time to a random 1 to 5 second delay > session_object.next_wait.set(1 + random.random()*4.0) > return > else: > # Stop test if transaction not OK > session_object.next_txn.set(None) > return > > def PotusLogin_pre(session_object, request_object): > """ Called BEFORE executing operation on page """ > # Choose a random user ID to log in anf collect identity info > indexID = random.randrange(0, len(session_object.globals.identies)) > user = session_object.globals.identies[indexID].getkey() > passwd = session_object.globals.identies[user] > # Set the fields > request_object.field_dict['loginid'] = user > request_object.field_dict['passwd'] = passwd > > return > > > def PotusLogin_post(session_object, response_object): > """ Called AFTER executing operation on page """ > if session_object.session_status != OK: > # Stop test if transaction not OK > session_object.next_txn.set(None) > return > > > ================== End Example ======================== > > > -- > Joe Griffin > Addanc > Downright Software Collective > > > > ------------------------------------------------------------------------ > This email and any files transmitted with it are confidential and > intended solely for the use of the individual or entity to whom they > are addressed. If you have received this email in error please notify > sec...@do.... > ------------------------------------------------------------------------ > This mail sent through Downright Software's implementation of HORDE/IMP. > For info, see: http://horde.org/imp/ > > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > Addanc-developer mailing list > Add...@li... > https://lists.sourceforge.net/lists/listinfo/addanc-developer > -- Doug Fort http://www.dougfort.net ------------------------------------------------------------------------ This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify sec...@do.... ------------------------------------------------------------------------ This mail sent through Downright Software's implementation of HORDE/IMP. For info, see: http://horde.org/imp/ |