ldtp.myfastforum.org Forum Index ldtp.myfastforum.org
Linux Desktop Testing Project - http://ldtp.freedesktop.org
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   Join! (free) Join! (free)
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Multiple test cases in single script and related logging

 
Post new topic   Reply to topic    ldtp.myfastforum.org Forum Index -> LDTP Test scripts (http://ldtp.freedesktop.org)
View previous topic :: View next topic  
Author Message
nagappan



Joined: 01 Jan 2008
Posts: 8
Location: Mountain View

PostPosted: Fri Jan 04, 2008 5:09 pm    Post subject: Multiple test cases in single script and related logging Reply with quote

Logging is required to analyze the result of execution. LDTP provides logging using the Python Logger.
Sample LDTP runner xml test2.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<ldtp>
        <logfile>teststatus.xml</logfile>
        <category>
                <!-- optional tag starts -->
                <name>category1</name>
                <!-- optional tag ends -->
                <group>
                        <!-- optional tag starts -->
                        <name>group1</name>
                        <!-- optional tag ends -->
                        <script>
                                <!-- testcase>NOTE: Test case tag is not required here</testcase-->
                                <name>test2.py</name>
                        </script>
                </group>
        </category>
</ldtp>

LDTP script (FAIL) test2.py
Code:
from ldtp import *
import traceback

testCase = 'Gedit find button click'
log (testCase, 'teststart')

try:
   launchapp ('gedit')
   click ('*-gedit', 'btnFind')
   waittillguiexist ('dlgFind')
   click ('dlgFind', 'btnClose')
   raise LdtpExecutionError ('Hello')
   log (testCase, 'pass')
   log (testCase, 'testend')
except LdtpExecutionError, msg:
   log (str (msg), 'cause')
   log (traceback.format_exc (), 'error')
   log (testCase, 'fail')
   log (testCase, 'testend')

testCase = 'Gedit Replace button click'
log (testCase, 'teststart')

try:
   launchapp ('gedit')
   click ('*-gedit', 'btnReplace')
   waittillguiexist ('dlgReplace')
   click ('dlgReplace', 'btnClose')
   raise LdtpExecutionError ('Hello')
   log (testCase, 'pass')
   log (testCase, 'testend')
except LdtpExecutionError, msg:
   log (str (msg), 'cause')
   log (traceback.format_exc (), 'error')
   log (testCase, 'fail')
   log (testCase, 'testend')

NOTE: Based on the exception raised in this script, the pass / fail count will be handled by ldtprunner. If this script doesn't raise any exception, then ldtprunner considers it as pass. If exception is raised, then it is considered as fail case.

As per the above script, even though its failed, the respective exception is not raised, so we need to add the exception statement appropriately.

from prompt you can execute like:
$ ldtprunner test.xml

Output in teststatus.xml will be like
Code:
<ldtp>
<category name="category1">
<group name="group1">
<script name="test2.py">
<test name="Gedit find button click">
<CAUSE>'Hello'</CAUSE>
<ERROR>Traceback (most recent call last):
  File "test2.py", line 12, in &lt;module&gt;
    raise LdtpExecutionError ('Hello')
LdtpExecutionError: 'Hello'
</ERROR>
<pass>0</pass>
</test>
<test name="Gedit Replace button click">
<CAUSE>'Hello'</CAUSE>
<ERROR>Traceback (most recent call last):
  File "test2.py", line 29, in &lt;module&gt;
    raise LdtpExecutionError ('Hello')
LdtpExecutionError: 'Hello'
</ERROR>
<pass>0</pass>
</test>
</script>
<timeinfo start="17:17:01 PM on 04-Jan-2008" elapsed="0:0:20"></timeinfo>
<groupsstatus total="1" pass="1" fail="0"></groupsstatus>
</group>
</category>
<totaltimeinfo start="17:17:01 PM on 04-Jan-2008" elapsed="0:0:20"></totaltimeinfo>
<categorystatus total="1" pass="1" fail="0"></categorystatus>
</ldtp>


In the above output, if you notice, only 1 test case is available and that too its in pass status. Because, the exception is not thrown from the script. ldtprunner considers each script as individual test case.

Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    ldtp.myfastforum.org Forum Index -> LDTP Test scripts (http://ldtp.freedesktop.org) All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Create your own free forum | Buy a domain to use with your forum
Linux Desktop Testing Project - http://ldtp.freedesktop.org