0

1) I have the very strange mistake in my protractor code. And I don't understand what may be reason of it.

it('should filtering by interval correctly', function () {
    filter_field.click();
    var filter_field_text = filter_field.element(by.css('input'));

    var exist_value1 = element(by.xpath('//tr[@data-row-index="1"]/td[@data-column-index="5"]/div')).getText().then(function (value) {
        var floatValue = parseFloat(value);
        return (floatValue);
    });
    var exist_value2 = element(by.xpath('//tr[@data-row-index="1"]/td[@data-column-index="5"]/div')).getText().then(function (value) {
        var floatValue = parseFloat(value);
        return Math.round(floatValue) + 1;
    });
    filter_field_text.sendKeys(exist_value1);
    filter_field_text.sendKeys('-');
    filter_field_text.sendKeys(exist_value2);
    browser.sleep(3000);
    var filtered_values = element.all(by.xpath('//tr/td[@data-column-index="5"]/div'));
    filtered_values.each(function (element, index) {
        var current_value = element.getText().then(function (value) {
            var floatValue = parseFloat(value);
            return (floatValue);
        });
        expect(exist_value1 <= current_value).toBe(true);
    });
    if (true) console.log("Test done!");
});

I have wrong result: 'Expected false to be true' Although, absolutely similar code working fine:

it('should filtering by one-sided < interval correctly', function () {
    filter_field.click();
    var filter_field_text = filter_field.element(by.css('input'));
    var exist_value = element(by.xpath('//tr[@data-row-index="1"]/td[@data-column-index="5"]/div')).getText().then(function (value) {
        var floatValue = parseFloat(value);
        return (floatValue);
    });
    filter_field_text.sendKeys("<");
    filter_field_text.sendKeys(exist_value);
    browser.sleep(3000);
    var filtered_values = element.all(by.xpath('//tr/td[@data-column-index="5"]/div'));
    filtered_values.each(function (element, index) {
        var current_value = element.getText().then(function (value) {
            var floatValue = parseFloat(value);
            return (floatValue);
        });
        expect(exist_value <= current_value).toBe(true);
    });
    if (true) console.log("Test done!");
});

2) Also I have a question about complex expectations. Can I do something like:

expect(exist_value1 >= current_value & exist_value2 <= current_value).toBe(true);

In my tests it isn't work.

2 Answers2

0

Can you print all these values before the expect statement? The float value might be different if they are getting derived through some calculation. Use parseFloat(yourString).toFixed(2) to get the float value till 2 decimal places.

Rahul Vig
  • 716
  • 1
  • 7
  • 24
  • Yes, I print it before except, and I don't see mistakes. And, unfortunately, your method didn't helped me. What interesting is that in another tests comparison working without problems. – Лилия Сапурина Jul 28 '15 at 07:15
  • the I think the problem is here- `var floatValue = parseFloat(value); return Math.round(floatValue) + 1;` you should return parseFloat of `Math.round(floatValue)`. Math.round returns an Integer. – Rahul Vig Jul 28 '15 at 08:24
0

Today I found the answer for my question. If somebody have the same problem: comparison should be in the function, because it is a js method.

Here is the right code:

it('should sorting by interval correctly', function () {
filter_field.click();

if (column_body.get(0).isPresent()) {
  var exist_value1 = column_body.get(0).getText().then(function (value) {
    var floatValue = parseFloat(value);
    return (floatValue);
  });
  var exist_value2 = column_body.get(0).getText().then(function (value) {
    var floatValue = parseFloat(value);
    return Math.round(floatValue) + 1;
  });
  filter_field.sendKeys(exist_value1);
  filter_field.sendKeys('-');
  filter_field.sendKeys(exist_value2);
  var filtered_values = element.all(by.xpath(column_body_xpath));

  filtered_values.each(function (element) {
    var current_value = element.getText().then(function (value) {
      var floatValue = parseFloat(value);
      expect((exist_value1 <= floatValue) && (exist_value2 >= floatValue)).toBeTruthy();  //INTO SCOPES!!!
    });
  });
}
else {
  expect(true).toBe(false);
}

console.log("ps-grid-column-filter-range_spec_8");
  });