0

I am new to writing tests in Protractor. I would like to be able to send a number to an element. I keep getting an error "Failed: input must be a string". The input type for the element is number. Any help/feedback would be much appreciated.

Here is my code:

//spec
describe('Send number', function () {
    var page = require('./page');
    it('Should pass a number to element', function () {
        var num = page.num;
        element(by.id(num)).sendKeys('200');
        expect(num).toBe('200');
    });
});

//page
var page = function(){
    this.num = element(by.model('num'));
}
module.exports = new page();
hackslash
  • 13
  • 4
  • 1
    if `page` refers to the function, then `page.num` does not exist. It depends how you import the page module. Could you provide the code that makes clear what each variable is? – trincot Dec 24 '18 at 11:09
  • Please checkout this answer for the differences between `toBe` and `toEqual`. In this situation if you are comparing a number to a string, think about using `toEqual`. TLDR; `toBe` is like `===` and `toEqual` is like `==`. https://stackoverflow.com/questions/22413009/jasmine-javascript-testing-tobe-vs-toequal – cnishina Dec 24 '18 at 22:57

1 Answers1

0

Your '200' is a string, a quick test if a number is present

it('should be a number', () => {
    let x = 1234;
    let y = [];
    y.push(x);
    expect(y[0]).toEqual(jasmine.any(Number));
  });

You can do more, but the point is using quotes will cast to string.

wraig
  • 71
  • 4