量角器清除()不工作 [英] Protractor clear() not working

查看:19
本文介绍了量角器清除()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个测试:

  it('should filter the phone list as user types into the search box', function() {

    var results = ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
    results.then(function(arr) {
            expect(arr.length).toEqual(3);
    });

    var queryInput = ptor.findElement(protractor.By.input('query'));

    queryInput.sendKeys('nexus');

    results = ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
    results.then(function(arr) {
        expect(arr.length).toEqual(1);
    });

    queryInput.clear();
    queryInput.sendKeys('motorola');

    results = ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
    results.then(function(arr) {
        expect(arr.length).toEqual(2);
    });

});

it('should display the current filter value within an element with id "status"',
    function() {
        //expect(element('#status').text()).toMatch(/Current filter: s*$/);
        var queryInput = ptor.findElement(protractor.By.input('query'));
        queryInput.clear();

        expect(ptor.findElement(protractor.By.id('status')).getText()).toMatch('Current Filter:');

        //input('query').enter('nexus');

        //queryInput.clear();
        //queryInput.sendKeys('nexus');

        //expect(element('#status').text()).toMatch(/Current filter: nexuss*$/);
        //expect(ptor.findElement(protractor.By.id('status')).getText()).toMatch('^Current Filter:.');

        //alternative version of the last assertion that tests just the value of the binding
        //using('#status').expect(binding('query')).toBe('nexus');
    });

第一个测试,搜索框,效果很好.第二个测试 status 没有通过,因为在 queryInput 中输入的最后一个值被传递到第二个测试,并且 queryInput.clear() 不起作用.但是,在第二个测试中,如果我调用 queryInput.sendKeys("something"),则会显示something".如果我在第二个测试中取出 clear(),我会看到motorolaso​​mething".因此,虽然 clear() 似乎在工作,但如果我在第二个测试中只有 clear(),我的测试没有通过,当我运行第二个测试时,即使调用 clear(),我也会看到motorola"在第二次测试之前.

the first test, search box, works great. the second test, status, does not pass because the last value entered in queryInput is carried over to the second test, and the queryInput.clear() does not work. However, in the second test, if i make a call queryInput.sendKeys("something"), "something" will display. If I take out the clear() in the second test, I'll see "motorolasomething". So, while it seems the clear() is working, my test is not passing if I just have clear() in the second test, when i run the second test, I will see "motorola", even when clear() is called prior to the second test.

我想知道为什么 clear() 之后没有 sendKeys() 时在第二次测试中没有清除它.

I'm wondering why the clear() is not clearing in the second test when I do not have a sendKeys() after it.

推荐答案

clear() 的文档说明如下:

The Documentation of clear() says the following:

[ !webdriver.promise.Promise ] 清除( )

[ !webdriver.promise.Promise ] clear( )

安排一个命令来清除此元素的 {@code 值}.如果底层 DOM 元素既不是文本 INPUT 元素也不是 TEXTAREA元素.

Schedules a command to clear the {@code value} of this element. This command has no effect if the underlying DOM element is neither a text INPUT element nor a TEXTAREA element.

返回:当元素具有被清除了.

Returns: A promise that will be resolved when the element has been cleared.

所以为了清楚地做你想做的事,你必须遵守它返回的承诺!为此,您必须使用 then()

so in order to get clear to do what you want, you have to work with the promise that it returns! to do so you have to use then()

这是它的工作原理:

queryInput.clear().then(function() {
    queryInput.sendKeys('motorola');
})

所以 clear() 返回一个清除输入的承诺,而 then() 告诉承诺在输入被清除后立即执行什么操作.

so clear() returns you a promise to clear the input and then() tells the promise what to do as soon as the input is cleared.

这篇关于量角器清除()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆