From Documentation

Jump to: navigation, search




  • Author
    Ryan Wu, Engineer, Potix Corporation
  • Date
    March 27, 2009
  • Version
    In ZK 3.6.1 or later (recommend)

Contents

Overview

About this article

This article is one of the unit testing series. The best approach to learn how to test ZK application is read them in order.
In previous articles, How to Test ZK Application with Seleniumand ZK Unit Testing, we have introduced how to test your ZK application.
But it's a little complicated to build the whole test project.

Thus, this time, we create a shortcut for ZK users. This will help you build up your test easily.

  1. zunit - A project directory that contains several batch and libraries which are need while testing.
  2. A new feature (A way to use ID as UUID for unit test purpose) which was suggested by John Yesberg before is ready in ZK 3.6.1 Freshly.

Prerequisites

Environment

  • JDK (MUST 1.4 or later)
    Download JAVA
    Must set the JAVA_HOME to your environment parameter.
  • Apache Ant[1]
    You can download it from here.
    Extract it and set the ANT_HOME to your environment parameter.
  • Selenium Remote Control[2]
    Follow the steps here : Setting up the Selenium Remote Control.
    Start you Selenium RC Server
  • Download zunit project
    Download
    Follow the steps next paragraph.
  • Your test application
    Without this, you can't do any test. :)

Steps

After finishing the environment configuration, you can start the test by the following steps.

St selenium overview0.png

1.Create Project

zunit contains one folder and one batch file called createProject.bat.

createProject.bat ProjectName

Users can easily create a Test projects.
St seleniun create.PNG

2.Write Case

Follow this article and write a test class for your application(s).

We have introduced the IdGenerator before. That's a way to have fixed uuid of ZK page.

In ZK 3.6.1, we created a new feature, ZK will generate the id to html element if the component has it's own Id.

This feature is more convenient and much easier when "locating" the elements on the web page.

How to make id to uuid

Simply unmark the id-to-uuid-prefix in zk.xml, and you can define a prefix to you custom id.

<desktop-config>
	<id-to-uuid-prefix>_zid_${page}_</id-to-uuid-prefix>
</desktop-config>

if your case have included other ZUL page, you MUST add ${page} on it's prefix.

BTW, sure you can also use the IdGenerator together.

<system-config>
	<id-generator-class>org.zkoss.zkdemo.test2.DemoIdGenerator</id-generator-class>
</system-config>

Example

<?page id="mypage" title="Test Tree item"?>
<zk>
	<label id="mylabel">this is a label</label>
</zk>
Result
<span class="z-label" z.zcls="z-label" id="_zid_mypage_mylabel">this is a label</span>
Locator

Assume your page is mypage, and the label is mylabel, you can locate it like following:

Selenium.getText("_zid_mypage_mylabel");
Some tricks about locator

By the way, there are so many components in ZK. If you want to test them, you'd better follow the "ways" we used.
for instance,

  • Type some words into the *box component  :
    you must user Selenium.focus() then Selenium.type()".
  • Click the button (Default mold):
    you can get it to be located with "ButtenID!real".

It's more convenient to use the Firebug we introduced before to find the right elements.

3.Run Test

If you build (compile) your resource already, this step will ignore the compile progress and do start the junit test,
After that, it will create a junit report by using the junit-frames.xsl (XSLT stylesheet).

runProject.bat

St seleniun run.PNG

4.View report

The report file index.html will be created automatically in the report directory.

St selenium report.PNG

Optional command

Clean Project

This option only used in some cases your file was already compiled and have some error or exceptions.
It will delete the build and report directory and recreate them.

clean.bat

St seleniun clean.PNG

Build Test

This process is only doing compile to all the java file in unittests directory.

  • Make sure all the library you need is already put into lib directory.
build.bat

St seleniun build.PNG

Appendix

Reference

  1. Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's wrinkles.
  2. Selenium : Selenium Official Site

Download




Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.
You got stuck here?
Let us know why!
For questions please use the forum