我是一名自动化开发人员,来自黄瓜/红宝石和specflow / c#背景。我有很少的Angular经验,而且没有更多的JS经验。我正在研究的项目是使用角度4,我开始关注Protractor来自动化UI测试。我看到一种奇怪的行为,需要帮助理解和解决正在发生的事情。
我的测试包含此代码。
it('Create Promo', function() {
page.createPromo();
// Clean Up
console.log('Got here 123');
page.deletePromo(page.title);
});
使用包含的page.createPromo
createPromo() {
this.title = this.addDateToString(this.title);
this.hrPromotions.click();
this.btnNewPromotion.click();
this.txtStartDate.sendKeys(this.dateToUSFormat(this.startDate));
this.txtEndDate.sendKeys(this.dateToUSFormat(this.endDate));
this.txtTitle.sendKeys(this.title);
this.txtPromoSpecial.sendKeys(this.promoSpecial);
this.lstCustomer.sendKeys(this.customer);
this.txtRegion.sendKeys(this.region);
this.lstCategory.sendKeys(this.category);
this.txtSKUs.sendKeys(this.skus);
this.lblStoreNumber.click();
this.btnCreatePromotion.click();
this.clickOKButton();
}
页面的功能会在组件加载后立即加载数据。量角器等待加载所需的数据,然后设置字段,创建按钮等。创建促销后,测试检查促销标题是否在现有促销列表中以验证促销是否成功创建。问题是Protractor在创建促销之前在列表中寻找促销标题。控制台输出显示以下内容:
Spec started
hi: AUTOMATION created this Promo 10-11-2017
Got here 123
[15:06:01] W/element - more than one element found for locator
by.cssContainingText("label", "HD105") - the first result will be used
AdminPortal App - Promotions Tests
✗ Create Promo
- Failed: No element found using locator: by.cssContainingText(".col-md-5",
"AUTOMATION created this Promo 10-11-2017")
在创建createPromo方法之前,查看日志“Got here 123”将被发送到控制台。在视觉上,在执行console.log命令之前,甚至没有使用sendKeys命令设置页面上的字段。有关W /元素查找多个元素的日志条目也来自createPromo方法。促销已创建,但到那时我认为已经执行了促销列表中标题的检查,因为日志条目显示无法找到该元素。
那为什么会这样呢?感觉命令正在执行而不等待之前的命令完成。