ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

How to replace id-to-uuid on testing?

madruga0315Top Contributor
14 Oct 2011 09:07:58 GMT
14 Oct 2011 09:07:58 GMT

I just saw that on ZK 5.0.8 the id-to-uuid feature was removed (have been deprecated for some time now...)

What's the alternatives here?

From what I saw, there is two alternatives, ZTL and CustomIdGenerator. Unless I'm missing something here, they're not as cool as id-to-uuid...

CustomIdGenerator: Based on this smalltalk you start with 0 and iterate over each component creating, being able to predict the component id and use it to test. This approach just suck big time because it "freezes" my layout. Say I want to change just the layout, not the main components involved. Add some separator here, some divs there... and there's a couple of hours just to do test-fixing... (with id-to-uuid this kind of changes are transparent...)

ZTL: as the name says, it's good to test .zul files. I saw that you can point to the external .zul file that you want to test (which I believe is the main case for ZK users). But ZTL is not good for me, because I use selenium as an Functional test tool. To test the whole application. From zul files to DB access. On my tests I always assert if the view is correct, the DB is correct, and if Composers save some state, if the state is correct. With ZTL I can assert only the view.

I'm kind lost here... I can't move on to ZK 5.0.9 or even to ZK 6.0.0 without some good testing mechanism...
Any suggestion is very welcome!

Thanks,
Madruga

terrytornadoTop Contributor
14 Oct 2011 14:24:22 GMT
14 Oct 2011 14:24:22 GMT

Big Push!

I have problems to see the direction zk go's

madruga0315Top Contributor
19 Oct 2011 07:02:12 GMT
19 Oct 2011 07:02:12 GMT

Any helps on this matter????

IMHO it's a big deal...

Kind regards,
Madruga

jimmyshiau
20 Oct 2011 19:57:04 GMT
20 Oct 2011 19:57:04 GMT

Hi Madruga,
I have tested with ZK 5.0.8, it works fine, do you add the following setting to your zk.xml?

<desktop-config>
	<id-to-uuid-prefix></id-to-uuid-prefix>
</desktop-config>

madruga0315Top Contributor
21 Oct 2011 08:50:33 GMT
21 Oct 2011 08:50:33 GMT

Hi Jimmy,

I didn't tested, I just saw that id-to-uuid was removed on ZK 5.0.8 release notes "+ The id-to-uuid-prefix configuration is removed"

But I just tested with ZK 5.0.9 and it worked. I'm guessing that this feature was removed only in the 6.0 branch?

jimmyshiau
23 Oct 2011 23:01:30 GMT
23 Oct 2011 23:01:30 GMT

Yes, it just be deprecated, still works with ZK 5,
we are going to remove since ZK 6, it shall use IdGenerator to instead of it.

Evilsun
1 Nov 2011 15:02:06 GMT
1 Nov 2011 15:02:06 GMT

IdGenerator does not help with existing selenium tests as we already click concrete ID's in our tests ( generated by deprecated id-to-uuid-prefix ).

Also for new tests it is also useless, as we don't want our test to be dependent on order of components.
For example we have two TextBoxes on our page with ids - "userName" and "userEmail".
In the test we just need to verify that both are there regardless of layout. Layout may be changed by designers. "userEmail" may be moved above "userName" ant etc.

What can you suggest in our case?
id-to-uuid-prefix completely satisfies us, why was it removed?

jimmyshiau
7 Nov 2011 02:27:28 GMT
7 Nov 2011 02:27:28 GMT

You can use IdGenerator to instead of it, please refer to the following sample:

public String nextComponentUuid(Desktop desktop, Component comp) {
	String id = comp.getId();
	return Strings.isBlank(id)? null: comp.getPage().getId()+ "_"+id;

Evilsun
10 Nov 2011 17:05:46 GMT
10 Nov 2011 17:05:46 GMT

Hmmm ... it's not a way , cose on a call of idGenerator there is no properties read , including id , from zul file - and there no id , currently i am using custom UiFactory with following workarond (separated by pluses ) to read id from zul first ,before IdGenerator call :

package com.dart.weider;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.ext.BeforeCompose;
import org.zkoss.zk.ui.http.SerializableUiFactory;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.metainfo.Property;

/**
 * User: evilsun
 * Date: 11/1/11
 */
public class UIFactory extends SerializableUiFactory {

    /**
     * Assigning component ID fist - to be passed to UUIDGenerator.
     *
     * @param page
     * @param parent
     * @param compInfo
     * @return
     */
    @Override
    public Component newComponent(Page page, Component parent,
                                  ComponentInfo compInfo) {
        final Component comp = compInfo.newInstance(page, parent);

        // ++++++++++++++++++++++++++++++++++++++++++
        for (Object property : compInfo.getProperties()) {
            Property prop = (Property) property;
            if (prop.getName().equals("id")) {
                prop.assign(comp);
            }
        }
        // ++++++++++++++++++++++++++++++++++++++++++

        if (parent != null) comp.setParent(parent);
        else comp.setPage(page);

        if (comp instanceof BeforeCompose)
            ((BeforeCompose) comp).beforeCompose();
        compInfo.applyProperties(comp); //include comp's definition
        return comp;

    }

}

Is there any common way to avoid using UIFactory ?

jimmyshiau
11 Nov 2011 01:27:13 GMT
11 Nov 2011 01:27:13 GMT

Hi Evilsun,

I can retrieve the component id in the IdGenerator.
what version of ZK do you use?

crc83
14 Nov 2011 09:16:17 GMT
14 Nov 2011 09:16:17 GMT

@madruga0315
If you need ztl for integration tests, please check this branch
http://www.zkoss.org/forum/listComment/17556-ZTL-issues

Maurus
24 Jan 2012 10:56:26 GMT
24 Jan 2012 10:56:26 GMT

Hi Evilsun,

I have the same problems with the UUIDs as you.
Did you find a solution to your problem?
If so how did you solve it?

Evilsun
24 Jan 2012 13:44:58 GMT
24 Jan 2012 13:44:58 GMT

The only solution i've found is to assign id to component in extended UIFactory , so that component goes to UUIDGenerator with not empty id . The code is above.

Maurus
26 Jan 2012 07:15:47 GMT
26 Jan 2012 07:15:47 GMT

Hi Evilsun,

many thanks for your answer.

I tried your solution and it works great for compounds for which I can set an id in the zul file.

How exactly are you using your extended UIFactory?
The only way I found was to paste your code into AbstractUiFactory.
Is there a way to use your extended UIFactory without changing ZK code?

How are you dealing with compounds for which you can not set an id in the zul file e.g.
combo boxes (I use PureTest for my tests. PureTest sends the HTML request to the server and so I need the request parameters and their value).

Combo box in zul file:

<combobox id="type" width="150px"/>

Combo box in HTML:

<tbody class="z-rows" id="zc_0_1e_38">
<tr class="z-row" style="border: medium none;" id="zc_0_3_3r">
<td class="z-row-inner" style="border: medium none;" colspan="2" id="zc_0_1e_3s-chdextr">
<div class="z-row-cnt z-overflow-hidden" id="zc_0_1e_3s-cell">
<span class="z-label" style="font-weight: bold;" id="zc_0_1e_3s">
Type</span>
</div>
</td>
<td class="z-row-inner" style="border: medium none;" id="zc_0_1e_3t-chdextr">
<div class="z-row-cnt z-overflow-hidden" id="zc_0_1e_3t-cell">
<i class="z-combobox" style="width: 150px;" id="zc_0_1e_3t">
<input type="text" value="Bug" autocomplete="off" class="z-combobox-inp" id="zc_0_1e_3t-real" style="width: 125px;"/>
<i class="z-combobox-btn" id="zc_0_1e_3t-btn" style="-moz-user-select: none;"/>
<div tabindex="-1" style="z-index: 1801; width: 150px; height: auto; position: absolute; top: 372px; left: 758.683px; display: none;" class="z-combobox-pp" id="zc_0_1e_3t-pp">
<table cellspacing="0" cellpadding="0" border="0" id="zc_0_1e_3t-cave" style="height: auto; width: 100%;">
<tbody>
<tr class="z-comboitem" id="zc_0_1e_6k">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
-- select --</td>
</tr>
<tr class="z-comboitem" id="zc_0_1d_63">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
Bug</td>
</tr>
<tr class="z-comboitem z-comboitem-seld" id="zc_0_1e_64">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
Improvement</td>
</tr>
<tr class="z-comboitem" id="zc_0_e_65">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
New Feature</td>
</tr>
</tbody>

The request parameter obtained with Firebug (bold are the ones belonging to the combo box above):

cmd_0	onMove
cmd_1	onZIndex
cmd_2	onMove
cmd_3	onChange
cmd_4	onSelect
cmd_5	onChange
cmd_6	onChange
cmd_7	onSelect
cmd_8	onChange
cmd_9	onSelect
data_0	{"left":"591px","top":"0px"}
data_1	{"":1800}
data_2	{"left":"590px","top":"0px"}

data_3	{"value":"Improvement","start":0}
data_4	{"items":["zc_0_1e_64"],"reference":"zc_0_1e_64"}

data_5	{"value":"fff","start":3}
data_6	{"value":"Blocker","start":0}
data_7	{"items":["zc_0_3_6r"],"reference":"zc_0_3_6r"}
data_8	{"value":"xxxxx","start":0}
data_9	{"items":["zc_0_1e_67"],"reference":"zc_0_1e_67"}
dtid	Desktop_
opt_0	i
opt_1	i
opt_2	i
uuid_0	zc_k_1d_bg
uuid_1	zc_k_1d_bg
uuid_2	zc_k_1d_bg
uuid_3	zc_0_1e_3t
uuid_4	zc_0_1e_3t
uuid_5	zc_k_1b_6w
uuid_6	zc_0_1e_3d
uuid_7	zc_0_1e_3d
uuid_8	zc_0_1d_3u
uuid_9	zc_0_1d_3u

Evilsun
26 Jan 2012 10:54:48 GMT
26 Jan 2012 10:54:48 GMT

You can specify your custom UIFactory in zk.xml , without need to change ZK's AbstractUiFactory one.

    <system-config>
        <ui-factory-class>com.dart.weider.UIFactory</ui-factory-class>
    </system-config>

Later i'll look into the code - to see how we working with compounds .i'm not sure , but we are using Selenium to test , so it can choose / press comboboxes by XPath , not by Id .
Anyway i'll reply on this .

Evilsun
27 Jan 2012 13:32:05 GMT
27 Jan 2012 13:32:05 GMT

Indeed , we are choosing combo items via XPath .