How to test a Angular js date picker from Protractor

前端 未结 3 1224
遇见更好的自我
遇见更好的自我 2020-12-02 00:49

I\'m new to Protractor and here I\'m trying to test an angularjs date picker from Protractor.

I tried to find a way to do this and this article was the only thing I

3条回答
  •  醉话见心
    2020-12-02 01:12

    I think you can avoid manipulating the datepicker manually and instead set the date either by just sending the keys with a today's date value:

    var picker = element(by.model("invoice.fromdate"));
    
    // get today's date
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!
    var yyyy = today.getFullYear();
    
    if(dd<10) {
        dd='0'+dd
    } 
    
    if(mm<10) {
        mm='0'+mm
    } 
    
    today = mm+'/'+dd+'/'+yyyy;
    
    picker.clear();
    picker.sendKeys(today);
    

    Or, by setting the associated model's value directly:

    picker.evaluate("invoice.fromdate= '" + today + "'");
    

提交回复
热议问题