量角器clear()无法正常工作 [英] Protractor clear() not working

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

问题描述

我有两个测试:

  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: nexus\s*$/);
        //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');
    });

第一个测试,搜索框,效果很好.第二个测试状态为不通过,因为在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] 清除()

计划要清除的命令此元素的{@code value}.如果以下命令无效,则此命令无效:底层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.

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

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