量角器比较字符串数字 [英] Protractor compare string numbers
问题描述
今天,我遇到了一个有趣的问题:创建测试用于很简单的行为:'最近的'排序。所有测试需要知道的:
- 每个项目都有ID
- 上一个ID少于下一个在这种情况下排序
方法:将ID写入item的属性,
问题: getAttribute()
c $ c> getAttribute() promise产生的字符串值和Jasmine不能比较(从框中)字符串数字。
想要找到优雅的方式来与 toBeLessThan()
比较,而不是使用少量的链 .then()
将与比较这些事情完成。
感谢家人< 3
我忘了promise的本质,但tnx给Michael Radionov我记得我想做什么。
expect(first.then(r => (r))).toBe(next.then(r => Number(r)));
我猜这笔划很简单。
UPDATE
ES6:
它应该测试数字,async函数(){
let first = Number(await $('#first')。getText());
let second = Number(await $('第二个)getText());
expect(first).toBeGreaterThan(second);
})
$ b b
Today I've faced interesting problem of create test for pretty simple behavior: 'Most recent' sorting. All what test need to know:
- Every item have ID
- Previous ID is less then next in this case of sorting
Approach: writing ID in to attribute of item, getting that id from first item with getAttribute()
and either way for second.
Problem: getAttribute()
promise resulting with string value and Jasmine is not able to compare (from the box) string numbers.
I would like to find elegant way to compare them with toBeLessThan()
instead of using chains of few .then()
that will be finished with comparing that things.
Root of no-type-definition evil
Thanks guys <3
I forgot of native nature of promises but tnx to Michael Radionov I've remembered what I want to do.
expect(first.then( r => Number(r) )).toBe(next.then( r => Number(r) ));
I guess this stroke looks simple.
UPDATE
ES6:
it('should test numbers', async function () {
let first = Number(await $('#first').getText());
let second = Number(await $('#second').getText());
expect(first).toBeGreaterThan(second);
})
这篇关于量角器比较字符串数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!