你如何在protractor.js中解析或字符串化值?

时间:2016-04-08 03:44:46

标签: angularjs protractor

我试图使用protractor.js而我似乎无法将字符串与整数进行比较而不会收到类似 it('should equal', function() { var n = $('#total').getAttribute('value') //returns '4' var rows = element.all(by.repeater('service in services')); // returns 4 //var rowCount = rows.count().toString() expect(n).toEqual(rows.count()) //'4' != 4 .... I want it to match }); 的错误

Map<ClaimMapping, String> claims = new HashMap<ClaimMapping, String>();
claims.put(ClaimMapping.build("http://wso2.org/claims/role", "http://wso2.org/claims/role", null, false), "customer");

AuthenticatedUser user = AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("xxxxxx");
context.setSubject(user);

如何将整数作为字符串,反之亦然?

2 个答案:

答案 0 :(得分:0)

我用过:

function toNumber(promiseOrValue) {
    // if it is not a promise, then convert a value
    if (!protractor.promise.isPromise(promiseOrValue)) {
        return parseInt(promiseOrValue, 10);
    }
    // if promise - convert result to number
    return promiseOrValue.then(function (stringNumber) {
        return parseInt(stringNumber, 10);
    });
} 

来自Protractor compare string numbers

答案 1 :(得分:0)

我会将它们都转换为int然后进行比较:

expect(n.then( v => parseInt(v))).toEqual(rows.count().then( v => parseInt(v)))
// getAttribute and count both return promises