CasperJS测试ExtJS 4.1应用程序-Ext.getCmp()始终返回未定义的

CasperJS测试ExtJS 4.1应用程序-Ext.getCmp()始终返回未定义的,extjs,extjs4,phantomjs,casperjs,Extjs,Extjs4,Phantomjs,Casperjs,我正在使用capserjs测试我的ExtJS 4.1应用程序。我就是这样引用ext.js文件的 casperjs测试——include=ext-all.js testFile.js 如果我打开chrome开发者工具栏上的控制台选项卡&键入Ext.getCmp('id of component')我取回组件 但是如果我在casperjs测试中使用相同的方法,我总是无法定义 我最初尝试使用Ext.getCmp()获取一个组合框,该组合框返回undefined,之后我尝试使用Ext.getCmp()查

我正在使用capserjs测试我的ExtJS 4.1应用程序。我就是这样引用ext.js文件的

casperjs测试——include=ext-all.js testFile.js

如果我打开chrome开发者工具栏上的控制台选项卡&键入
Ext.getCmp('id of component')我取回组件

但是如果我在casperjs测试中使用相同的方法,我总是无法定义

我最初尝试使用
Ext.getCmp()
获取一个组合框,该组合框返回
undefined
,之后我尝试使用
Ext.getCmp()
查找文本框、标签,每次都返回undefined

我也尝试过使用组件查询,但即使这样也不起作用

我也看了看这方面的帮助,但我无法产生预期的结果

.then(function(){

     this.wait(5000, function(){
       this.capture('c:\\temp\\cmb.png');
         console.log('-----' + Ext);
       var sqCombo = Ext.getCmp('country-ddl'); // returns the ComboBox components

       sqCombo.setValue('UK'); // set the value
       sqCombo.fireEvent('select'); // because setValue() doesn't trigger the event
     })

   })
使用injectJs()

运行脚本后,我在控制台上看到:

   TITLE : ====> Test App
injected
evaluating
Console: [object Object]
Error: TypeError: 'undefined' is not an object (evaluating 'Ext.getCmp('shadowUser').text')
Error: Error: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required classes: myApp.view.OptionsView, myApp.view.HelpView, myApp.view.SupportView, myApp.view.AdminView
PASS Title is correct
TESTS COMPLETED

没有
--include=
选项。它被调用了,但这对您没有帮助,因为它会将extjs注入外部上下文,而外部上下文无法访问页面

需要时,需要使用Extjs脚本:

casper.then(function(){
    this.page.injectJs('ext-all.js');
    ...
});
如果Extjs已经包含在页面中(根据可用的Ext组件判断),那么您不需要注入任何东西。然后,您应该能够从页面上下文中使用它:

.then(function(){
    this.wait(5000, function(){
        this.capture('c:\\temp\\cmb.png');
        console.log('-----' + Ext);

        this.evaluate(function(){
            var sqCombo = Ext.getCmp('country-ddl'); // returns the ComboBox components

            sqCombo.setValue('UK'); // set the value
            sqCombo.fireEvent('select'); // because setValue() doesn't trigger the event
        });
    })
    .wait(5000, function(){
        this.capture('c:\\temp\\cmb2.png');
    });
})

请记住,
Ext
仅在可通过沙盒函数访问的页面上下文中可用。

@ArtjomB:更新了问题以显示我正在尝试做什么。我添加了selenium标记,因为我确信很多人肯定也遇到过同样的问题。我基本上是试图找到一个组合框,并希望设置一些值,然后触发select事件。因为ext组合框没有呈现为
select
,所以我很难找到组件。在运行测试用例时,我使用
--include
(如我的问题所示)选项包含了extjs。在这之后,我能够访问
Ext
对象,我在想,我将能够访问所有底层方法。我想知道我现在有什么选项可以访问组合框?感谢您抽出时间添加代码。现在我明白了为什么
--include
选项对我的情况没有帮助。我使用了您显示的代码,看起来系统没有执行
this.evaluate()
。在这个函数下,我包含了console.log(),在控制台上看不到任何东西。我遗漏了什么吗?如果您使用的是PhantomJS 2.0.0,那么就有一个隐藏错误的bug。使用PhantomJS 1.9.8或1.9.7查看是否存在错误。请注册到
resource.error
page.error
remote.message
casper.page.onResourceTimeout
事件()。可能有错误。我现在使用的是phantomjs版本1.9.8。我已经注册了所有错误的钩子。我还更新了这个问题,包括了在包括建议的更改之后我得到的关于错误的所有详细信息!!当然,它找不到
Ext
,因为它是在页面上下文中注入的。使用
evaluate()。我又更新了这个问题!!
.then(function(){
    this.wait(5000, function(){
        this.capture('c:\\temp\\cmb.png');
        console.log('-----' + Ext);

        this.evaluate(function(){
            var sqCombo = Ext.getCmp('country-ddl'); // returns the ComboBox components

            sqCombo.setValue('UK'); // set the value
            sqCombo.fireEvent('select'); // because setValue() doesn't trigger the event
        });
    })
    .wait(5000, function(){
        this.capture('c:\\temp\\cmb2.png');
    });
})