如何从量角器测试角度js日期选择器 [英] How to test a Angular js date picker from Protractor
问题描述
我试图找到一种方法来做到这一点,一个href =https://www.npmjs.com/package/protractor-angulardatepicker =nofollow noreferrer>这篇文章是我发现的唯一的东西,它不是很清楚使用
如果有人知道如何测试请帮忙。
我需要的是选择今天的日期。 strong>
提前感谢:)
- 编辑 -
alecxe,这里是我的日期选择器的屏幕截图。遗憾的是无法提供页面的链接。 :(
< input
class =form-control ng-pristine ng-valid ng-not-empty ng-touch
ng-model =invoice.fromdate
data-date- format =yyyy-MM-dd
data-date-type =string
data-max- =data-autoclose =1
bs-datepicker =
ng-change =dateRange()
type =text>
我想你可以避免手动操作datepicker,而只需使用今天的日期值 :
var picker = element .model(invoice.fromdate));
//获取今天的日期
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+ 1; //一月是0!
var yyyy = today.getFullYear();
if(dd< 10){
dd ='0'+ dd
}
if(mm< 10){
mm ='0'+ mm
}
今天= mm +'/'+ dd +'/'+ yyyy;
picker.clear();
picker.sendKeys(今天);
或者,由直接设置关联模型的值:
picker.evaluate(invoice.fromdate ='+ today +');
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 found and It is not very clear to use
If someone know how to test please help.
What I need is to select today's date.
Thanks in advance :)
- edit -
alecxe, here is the screen shot of my date picker. Unfortunately cannot provide the link of the page. :(
<input
class="form-control ng-pristine ng-valid ng-not-empty ng-touched"
ng-model="invoice.fromdate"
data-date-format="yyyy-MM-dd"
data-date-type="string"
data-max-="" data-autoclose="1"
bs-datepicker=""
ng-change="dateRange()"
type="text">
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 + "'");
这篇关于如何从量角器测试角度js日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!