如何在 Senchat 测试中 select 来自组合框的项目

How to select an item from a combobox in Senchat Test

有没有办法 select 组合框中的项目而不需要项目的实际值?

假设我们有一个包含橙子、苹果和柠檬的组合,这些项目的实际值是我们不知道的键,有没有办法通过索引来实现 select?

或者根据 displayValue 检索值?

像这样的东西有效:

  this.comboBox().setValue(7);

但是如果我只有我想要的 displayValue select 怎么办?让我们说 'Oranges',我如何从组合中 select?

你可以这样做:ST.ComboBox('${ST_LOCATOR}').setValue('STRING_VALUE') 其中 STRING_VALUE 是组合框中可用的选项之一。

请注意 STRING_VALUE 不是您在 UI 中看到的值。你可以在 UI 3D Pie 和组件 3d_pie 中。第二个是您必须使用的那个。

如果该组件不是真正的 ComboBox,而是一个更复杂的组件,您将必须找到 DOM 元素和单击操作等的解决方法。

执行此操作的一种方法是通过 execute()。这个想法是在组合框的存储中找到正确的记录,从中检索 id,然后使用 id 设置正确的值。

在浏览器内场景中,您可以直接通过检查组合框的存储来执行此操作。但是,在基于 WebDriver 的场景中,您无法从规范中访问应用 运行ning 的上下文,因此 execute() 是最简单的方法(没有其他方法可以通过API) 才能进去。这是一个简单的例子:

// Component
Ext.define('Sandbox.view.test.combobox.Base', {
    extend: 'Ext.form.field.ComboBox',
    id: 'futureCmp',
    displayField: 'text',
    valueField: 'id',
    store: {
        fields: ['id', 'text'],
        data: [
            [1, 'Apples'],
            [2, 'Oranges']
        ]
    }
});

// Spec
it('should select correct value from displayField', function () {
    var combo = ST.comboBox('@futureCmp');

    combo
        .execute(function (cmp) {
            // we're in the target context now, so we *can* 
            // interact with Ext JS now
            // we could return an object if needed, but we only need the id
            return cmp.getStore().findRecord('text', 'Oranges').get('id');
        })
        .and(function () {
            // "executeResult" is the value returned from execute()
            // in this case, it's the id of the item we want to select
            var id = this.future.data.executeResult;
            combo.setValue(id);
            // assert that the value has been correctly selected
            combo.value(id);
        });
});

这种方法的好处在于它可以在场景类型之间移植;因为我们只使用 API,所以我们可以轻松地在基于浏览器和网络驱动程序的场景和 运行 相同的测试之间切换(事实上,这是从一些内部测试中借来的那个)。

最后,我们 在功能请求跟踪器中有一个项目,用于将 select() 样式方法添加到组合框未来 API,类似于 Grid 和 DataView 的可用内容。我不确定他们什么时候能进来,但我个人一直想要它:)