如何从量角器测试 Angular js 日期选择器 [英] How to test a Angular js date picker from Protractor

查看:19
本文介绍了如何从量角器测试 Angular js 日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Protractor 的新手,在这里我正在尝试测试 Protractor 的 angularjs 日期选择器.

我试图找到一种方法来做到这一点,

<输入class="表单控制 ng-pristine ng-valid ng-not-empty ng-touched"ng-model="invoice.fromdate"数据日期格式="yyyy-MM-dd"数据日期类型=字符串"数据最大-="" 数据自动关闭="1"bs-datepicker=""ng-change="dateRange()"类型=文本">

解决方案

我认为您可以避免手动操作日期选择器,而是通过使用 今天的日期值:

var picker = element(by.model("invoice.fromdate"));//获取今天的日期今天无功 = 新日期();var dd = today.getDate();var mm = today.getMonth()+1;//一月是0!var yyyy = today.getFullYear();如果(dd<10){dd='0'+dd}如果(毫米<10){毫米='0'+毫米}今天 = mm+'/'+dd+'/'+yyyy;选择器.清除();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 + "'");

这篇关于如何从量角器测试 Angular js 日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆