量角器不清除输入字段的内容

时间:2015-04-13 14:58:25

标签: javascript html testing protractor

当我的页面加载时,它有很多字段包含有关客户的信息(由其他人编写)。在名字字段'杰里'出现。我想要量角器删除它然后写下我的名字,并期望它在那里。到目前为止,我有这个:

var firstName = element(by.css('#cust04'));
firstName.clear();
firstName.sendKeys('John');
expect(firstName.getAttribute("value")).toEqual("Johns");

目前它说Expected JerryJohn to equal Johns。任何想法为什么它不会工作?附:我知道现在与约翰而不是约翰相提并论。

2 个答案:

答案 0 :(得分:1)

你是不是在量角器2.0上尝试这个,因为我遇到了类似的问题,下面是解决这个问题的方法。我不知道为什么它对我有用,但确实如此。

var firstName = element(by.css('#cust04'));
firstName.click().clear().sendKeys('John');
expect(firstName.getAttribute("value")).toEqual("John");

如果您在输入文本之前遇到预期问题,那么您可以在预期之前执行此操作。我只有几个例子,我必须在预期之前做额外的等待。

var usernameHasText = EC.textToBePresentInElementValue(firstName, 'John');
browser.wait(usernameHasText, 5000, "Failed to type in the username");

答案 1 :(得分:0)

试试这段代码:

  firstName.clear().then(function(){
        var firstName = $('#cust04');
        firstName.sendKeys('John');
        expect(firstName.getAttribute("value")).toEqual("John");
    });

clear() - 返回promise,因此您需要解决它。 此外,您在代码中声明了错误的值(对于lastName)。 我还建议你使用:

  

browser.ignoreSynchronization = false;

标志,在这种情况下你不需要在这里使用.then阻止,因为在这种情况下量角器将等到promise将被解决。

相关问题