【发布时间】:2014-03-12 22:42:29
【问题描述】:
我正在对 ExtJS 网络应用程序进行 UI 测试,而且我是初学者。 我正在尝试使用 CasperJS/PhantomJS 工具测试 ExtJS 小部件。 此外,我使用Resurrectio 生成所需的 CasperJs 脚本,并对它进行必要的更改。
由于 ExtJs 为它创建的 DOM 元素动态生成唯一的 id,我想知道如何在 CasperJs 脚本中提供这些 id 以进行测试。
例如,以下 Casper 脚本是由 Resurrectio 生成的:
casper.waitForSelector("#ext-gen1142 .x-tree-icon.x-tree-icon-parent",
function success() {
test.assertExists("#ext-gen1142 .x-tree-icon.x-tree-icon-parent");
this.click("#ext-gen1142 .x-tree-icon.x-tree-icon-parent");
},
function fail() {
test.assertExists("#ext-gen1142 .x-tree-icon.x-tree-icon-parent");
});
casper.waitForSelector("#gridview-1038",
function success() {
test.assertExists("#gridview-1038");
this.click("#gridview-1038");
},
function fail() {
test.assertExists("#gridview-1038");
});
这里的#ext-gen1142 和#gridview-1038 是动态创建的ID。应该如何在测试中提供数据?是否有任何存根或模拟工具可以在代码中与 ExtJs 一起使用,以便在测试期间在运行时提供这些 id?
我遇到了SinonJS。它可以使用还是我需要使用answer 中提到的 CSS 或 XPath 定位器?使用 CSS 或 Xpath 定位器有多可靠?
提前致谢!
【问题讨论】:
标签: extjs automated-tests phantomjs casperjs gui-testing