The structure of the site (HTML) can be effectively tested as we can assert the elements position (layout). The content can be asserted as we inspect the DOM. And that is just the beginning: Behaviour (javascript) and look and feel (CSS) can be tested as well.
Your reports might have a component of behavior and look and feel but the most important part to test is structure and content. Jasper Reports has several exporters and one of them is HTML. The HTML is absolute positioned and that creates the perfect scenario for testing.
If a bug has to be addressed then be sure you provide an automated test to ensure it will never come back.
All you need to do is:
- Business Analyst provides a test scenario where assertion on a cell content are made: The number for the current balance for this period for this account must be $1,000.00.
- Developer runs the Jasper Report from Firefox (Firebug plugin installed and if you want to get serious about it XPath Checker plugin installed as well) using HTML output.
- Developer runs the Jasper Report from Firefox using HTML output. He right click on the element and select "Inspect Element":
<span style="position:absolute;left:388px;top:226px;width:72px;height:10px;text-align: right;"> <span style="font-family: 'DejaVu Sans', Arial, Helvetica, sans-serif; color: #000000; font-size: 8px;">100,000</span> </span>
- From Firebug you see right away a way to test both position and content. Here it is with XPATH:
//span[@style="position:absolute;left:388px;top:226px;width:72px;height:10px;text-align: right;"]/span
- There is an advantage and a problem with the above.
Advantage: It allows to assert not only the value but the position of the element
Disadvantage: If the element absolute position is changed the test case will need to be changed. If we are interested in just asserting the data and not the absolute position of the element then the xpath is better retrieved from Firebug: Right click on the element on the firebug left pane and select "Copy XPath" to get something like:
/html/body/table/tbody/tr/td[2]/div/span[71]/span
- Finally if you want to pleay with XPath a little bit more and assert really complicated scenarios start by right clicking something in the page content and selecting "View XPath". A new screen will come up from where you can see the xpath to get that element (be aware of the schema which you can remove for cleaner xpath expression). Go ahead and evaluate any random XPath from there as well.
No comments:
Post a Comment