gpt4 book ai didi

java - ZATS :How to get the dynamically generated zk-Elements?

转载 作者:行者123 更新时间:2023-11-30 07:48:14 28 4
gpt4 key购买 nike

我正在使用 ZATS 测试复杂的 zk-UI。 Gui 由几个相关的 ZUL 组成,并包括动态生成的列表框,我需要测试哪些项目。这是我的 GUI 的结构:

equipmentView.zul -> ribbon.zul -> entityList.zul -> < listbox>
                                                    -> folderTree.zul -> < tree >

因此,当用户操作树项时,列表框会使用react并生成实体列表。这是我的测试:

    <!-- Entity Detail List -->
<listbox name="listboxName" model="@load(dm.selectedListContent)" mold="paging" pagingPosition="bottom" autopaging="true" vflex="true" emptyMessage="No Data to show" sclass="basiclist reportList"
selectedItem="@bind(dm.selectedEntity)">

<!-- List header -->
<listhead children="@load(dm.listHeader)">

<!-- Create Header Elements -->
<template name="children" var="header">

<!-- set width of icon or releaseSessionButton fix to 50px -->
<listheader if="${header.macro or header.icon}" label="@load(header.label)" width="50px" />

<!-- width for label attributes are auto -->
<listheader if="${not header.macro and not header.icon}" label="@load(header.label)" />

</template>

</listhead>

<!-- List Content -->
<template name="model" var="node">

<listitem sclass="reportList" children="@load(dm.listHeader)" onDoubleClick="@command('moveToNextRibbonElement')">

<!-- Create List Cell foreach column -->
<template name="children" var="headerInfo">

<!-- Show Icon in Listcell -->
<listcell if="${headerInfo.icon}" iconSclass="@load(node.columnValues.get(headerInfo.name))" />

<!-- Show attribute value as label in listcell -->
<listcell if="${not headerInfo.macro and not headerInfo.icon}" visible="@load(not node.changed)" label="@load(node.columnValues.get(headerInfo.name))" />
<!-- Unsaved changed unsaved entities are to be displayed in italics -->
<listcell if="${not headerInfo.macro and not headerInfo.icon}" visible="@load(node.changed)" label="@load(node.columnValues.get(headerInfo.name))" style="font-style:italic"/>

<!-- Load macro releaseSessionButton in listcell -->
<listcell if="${headerInfo.macro}">

<!-- Load Macro -->
<releaseSessionButton currentRS="@init(sessionScope.CurrentActiveReleaseSession)" entity="@init(node.dto)" />

</listcell>

</template>

</listitem>

</template>
</listbox>
public class EquipmentViewTest extends ZatsTestBase {
/**
* logger
*/
private Logger log = LoggerFactory.getLogger(this.getClass());

private DesktopAgent equipmentView;
// selectors
private String selectNavitemSearch = "navitem[label='Search']";
private String selectNavitemMasterdata = "navitem[label='Masterdata']";
private String selectTabFolder = "tab[label='Folder']";
private String selectFolderTree = "tree[id='folderTree']";
private String selectTabFilter = "tab[label='Filter']";
private String selectEntityList = "listbox[name='listboxName']; //listbox

// zats-agents
private ComponentAgent searchAgent;
private ComponentAgent masterAgent;
private ComponentAgent folderAgent;
private ComponentAgent folderTreeAgent;
private ComponentAgent filterAgent;
private ComponentAgent listboxAgent;

/**
* Initialization:<br>
* - login;<br>
* - agents initialization and test<br>
*/
@BeforeClass
private void initEquipmentViewTest() {
log.info("Test Suit 'Equipment View Test Suit': begin");
login();

// init equipmentView.zul desktop
equipmentView = client.connect("/ModuleResource/src/main/resources/web/view/equipmentView.zul");
Assert.assertNotNull(equipmentView);

// set Agents for "Search" and "Masterdata" navitems
searchAgent = equipmentView.query(selectNavitemSearch);
Assert.assertNotNull(searchAgent);

masterAgent = equipmentView.query(selectNavitemMasterdata);
Assert.assertNotNull(masterAgent);

// set Agents for "Folder" and "Filter" navitems
folderAgent = equipmentView.query(selectTabFolder);
Assert.assertNotNull(folderAgent);

filterAgent = equipmentView.query(selectTabFilter);
Assert.assertNotNull(filterAgent);

// set agent for folder tree
folderTreeAgent = equipmentView.query(selectFolderTree);
Assert.assertNotNull(folderTreeAgent);

// agent for the entity list
listboxAgent = equipmentView.query(selectEntityList);
Assert.assertNotNull(listboxAgent);

}

/**
* Logout
*/
@AfterClass
private void finish() {
logout();
log.info("Test Suit 'Equipment View Test Suit': end");
}

/**
* Verification of list items in the entityList.zul
*/
private Boolean verifyEntityList(String message) {

String expectedEmptyMessage = "No Data to show";
Boolean empty;

// list header test
ComponentAgent listHeaderName = listboxAgent.query("listheader[label='Name']");
Assert.assertNotNull(listHeaderName);
ComponentAgent listHeaderDescr = listboxAgent.query("listheader[label='Description']");
Assert.assertNotNull(listHeaderDescr);
ComponentAgent listHeaderState = listboxAgent.query("listheader[label='State']");
Assert.assertNotNull(listHeaderState);

// empty message
String actualEmptyMessage = listboxAgent.as(Listbox.class).getEmptyMessage();
Assert.assertEquals("empty messages must be equal", expectedEmptyMessage, actualEmptyMessage);

// get all list items

List<ComponentAgent> entityList = listboxAgent.queryAll("listitem");
Assert.assertNotNull("listbox must not be null", entityList);

int numberOfItems = entityList.size();
log.info("Number of the elements = " + numberOfItems+" in "+message);
if (numberOfItems < 1) {
Assert.assertEquals("list must be empty", numberOfItems, 0);
log.info("Entity List is empty.");
empty = true;
} else {
Assert.assertTrue("list must not be empty", numberOfItems > 0);
empty = false;
// TODO test the list items
}

return empty;

}

@Test(enabled = true, groups = {"TEST_GROUP_APPROVED"})
public void testFolderNoInput() {
String selectorFolder = "tree[id='folderTree']";

// "Search"-navitem is selected
Navitem searchNavitem = searchAgent.as(Navitem.class);
Assert.assertTrue(searchNavitem.isSelected());

// "Masterdata"-navitem is not selected
Navitem masterNavitem = masterAgent.as(Navitem.class);
Assert.assertFalse(masterNavitem.isSelected());

// "Folder"-tab is selected
Tab folderTab = folderAgent.as(Tab.class);
Assert.assertTrue(folderTab.isSelected());

// "Folder"-tab is not selected
Tab filterTab = filterAgent.as(Tab.class);
Assert.assertFalse(filterTab.isSelected());

// tree items closed
List<ComponentAgent> listOfTreeitemAgents = equipmentView.query(selectorFolder).queryAll("treeitem");
for (ComponentAgent agent : listOfTreeitemAgents) {
Assert.assertEquals(1, agent.as(Treeitem.class).getVisibleItemCount());
}
// list items verification of EQ
Boolean empty = verifyEntityList("testFolderNoInput");
Assert.assertTrue("the entity list must empty", empty);

// TODO CookiesTest

}

private void openTreeTest(List<ComponentAgent> treeitems) {
Boolean empty;
for (ComponentAgent item : treeitems) {
// listitem is closed
if (item.as(Treeitem.class).getVisibleItemCount() == 1) {
item.as(OpenAgent.class).open(true);
}
Assert.assertTrue("the listitem must be opend", item.as(Treeitem.class).isOpen());

// test the entityList - opened
empty = verifyEntityList("openTreeTest:opened");
Assert.assertTrue("the entity list must be empty", empty);

// test the entityList - clicked
item.click();
verifyEntityList("openTreeTest:clicked");

// //test the entityList - clicked
// item.as(SelectAgent.class).select();
// verifyEntityList();

// get all treeitems
List<ComponentAgent> fullList = item.queryAll("treeitem");
Assert.assertNotNull("list must not be empty", fullList);

List<ComponentAgent> newTreeitems = fullList.subList(1, fullList.size());
log.info("===>" + item.as(Treeitem.class).getLabel());
if (newTreeitems.size() > 1) {
openTreeTest(newTreeitems);
}

}
}

/**
* Folder-tab test
*/
@Test(enabled = true, groups = {"TEST_GROUP_APPROVED"}, dependsOnMethods = {"testFolderNoInput"})
public void testFolder() {
// test if the tab is selected
Tab folderTab = folderAgent.as(Tab.class);
if (!folderTab.isSelected()) {
// if tab is not selected - select
folderAgent.select();
}
Assert.assertTrue("tab must be selected", folderTab.isSelected());

// get the folders
List<ComponentAgent> folders = folderTreeAgent.queryAll("treeitem");
Assert.assertNotNull(folders);

// test the tree content
openTreeTest(folders);

}
}

无法通过 id(failed-GUIexception)/name(返回无列表项)/class(测试失败)来提取这些列表项,但我需要以某种方式执行此操作。有没有机会提取动态元素?有人尝试过 ID 生成器吗?是否可以使用包含通配符的选择器查询元素?谢谢

最佳答案

所以,为了解决这个问题,我刚刚实现了 IDGenerator。并使用 TAG_COUNTER 作为 zk 组件和没有 id 的页面的 uuid。 :)))

将这段代码添加到WEB-INF中的zk.xml中

<system-config>
<id-generator-class>com.mmm.mmm.initializer.IDGenerator</id-generator-class>
</system-config>



@Override
public String nextComponentUuid(Desktop desktop, Component comp, ComponentInfo compInfo) {

// get last id
String number = (String) desktop.getAttribute(LAST_ID);
if (number == null) {
number = "0";
}

// increment last id
int counter = Integer.parseInt(number);
counter++;

// write last id back to desktop
desktop.setAttribute(LAST_ID, String.valueOf(counter));

String componentID = "";
String id = comp.getId();
String tag = null;
if(compInfo != null){
tag = compInfo.getTag();
}

// add id if known
if (id != null && !id.isEmpty()) {
componentID = componentID + id;
}

// add tag if known
if (tag != null && !tag.isEmpty()) {

if (componentID.isEmpty()) {
componentID = componentID + tag;
} else {
componentID = componentID + ":" + tag;
}

}

// add counter
if (componentID.isEmpty()) {
componentID = componentID + "zkcomp_" + counter;
} else {
componentID = componentID + ":" + counter;
}

return componentID;
}

关于java - ZATS :How to get the dynamically generated zk-Elements?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649307/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com