nagappan
Joined: 01 Jan 2008 Posts: 8 Location: Mountain View
|
Posted: Fri Jan 04, 2008 5:09 pm Post subject: Multiple test cases in single script and related logging |
|
|
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 <module>
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 <module>
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.
|
|