小编Den*_*son的帖子

在expect语句中一起添加变量

我有一些字符串,我使用量角器/ jasmine/angularJS提取并转换为整数.我现在正在尝试将这些添加在一起并在期望声明中进行比较.但是我这样做会有一些承诺错误.

var result0 = element.all(by.binding('Inboxes.Inbox.Count')).first().getText().then(parseFloat);
    result0.then((value) => console.log("count: ", value));

    var result1 = element.all(by.binding('InboxItem.Count')).get(0).getText().then(parseFloat);
    result1.then((value) => console.log("count: ", value));

    var result2 = element.all(by.binding('InboxItem.Count')).get(1).getText().then(parseFloat);
    result2.then((value) => console.log("count: ", value));

    var result3 = element.all(by.binding('InboxItem.Count')).get(2).getText().then(parseFloat);
    result3.then((value) => console.log("count: ", value)).then(expect(result1 + result2 + result3).toEqual(result0));

    //compare badge counts to Inbox badge count
    expect(result1 + result2 + result3).toEqual(result0);
  });
 });
}); 
Run Code Online (Sandbox Code Playgroud)

我收到以下承诺错误.我认为既然承诺已经满足并且下面的计数打印出来(41,7,14和20)我可以将底部3(reulst1-3)加在一起并与result0进行比较,结果是结果总数1-3 .我有这些承诺的时间,因为我是新手,并不太了解它们.

Started
count:  41
count:  7
count:  14
count:  20
F

Failures:
1) Workflow Application When selecting Alerts panel should expand the …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs protractor

5
推荐指数
1
解决办法
144
查看次数

jasmine打印getText输出外部函数

我正在编写一个量角器规范,它使用angularJS和jasmine从页面获取文本,我后来想要从字符串转换为整数.我的第一个问题是访问函数外部的getText值.例如,在下面的代码中:

var post_count = element.all(by.binding('InboxItem.Count')).get(0);
 post_count.getText().then (function (text){
 console.log('mytext_inside_function = ' + text);
 return text;
});
console.log('mytext_outside_function = ' + post_count);
Run Code Online (Sandbox Code Playgroud)

我可以看到代码是异步执行的,console.log我的text_outside_function在my_text_inside_function之前运行,因此返回"对象对象"而不是数字7(这是文本而不是数字)

? protractor protractor.conf.js --suite inbox
[10:56:34] I/local - Starting selenium standalone server...
[10:56:35] I/launcher - Running 1 instances of WebDriver  
Started
mytext_outside_function = [object Object]
mytext_inside_function = 7
.
1 spec, 0 failures
Finished in 0.938 seconds
Run Code Online (Sandbox Code Playgroud)

我是茉莉花承诺的新手,不知道如何纠正这一点.我添加了.then(函数...对我的测试,但似乎没有解决承诺.我的最终目标是获取文本(7)然后将其从当前字符串转换为数字,以便我可以做计算(添加)它.

编辑....感谢Nick的建议.我想我做错了.我添加了mytext变量,我认为它在函数之外(可能是错误的).见下文..

 var post_count = element.all(by.binding('InboxItem.Count')).get(0);
 var mytext = post_count.getText().then (function (text){
 console.log('mytext_inside_function = ' + text);
 return text;
 });
 console.log('mytext_outside_function …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs protractor

2
推荐指数
1
解决办法
1018
查看次数

标签 统计

angularjs ×2

jasmine ×2

protractor ×2