量角器/黄瓜:动态选择日历上的第一个可用日期-未解决承诺

问题描述 投票:0回答:1

我想制作一个可以动态选择日历中第一天(未禁用)的功能。但是,在运行测试之后,前两个步骤都可以,但是在第三步之后,我得到了一个错误“错误:功能超时,确保承诺在60000毫秒内分解”。我无法弄清楚为什么诺言得不到解决。

关于如何选择第一天的其他想法?

When('I select the return date', async () => {
    await calendar.returnDate.click();
    await browser.wait(EC.elementToBeClickable(calendar.searchBtn));

    await calendar.days.each(el => {            //calendar.days are all td in the calendar element.all(by.tagName("td"));
        el.getAttribute("class").then(function (attr) {
          console.log(attr);
            if (attr !== "is-disabled") {      //the disabled days in the calendar are having class="is-disabled"
            el.click();
           }
        })
    })
})
typescript protractor cucumber
1个回答
0
投票

执行所有步骤后,请在步骤定义中使用return语句。

When('I select the return date', async () => {
  await calendar.returnDate.click();
  await browser.wait(EC.elementToBeClickable(calendar.searchBtn));
  let enabled_day = element.all(by.id('your locator')).filter(e=>e.isDisplayed()).first();
  return enabled_day.click();
})

如果要检查Web元素数组的isDisplayed属性,请使用filter方法,然后再获取显示的第一个Web元素。

并且不要忘记在步骤定义的末尾添加return语句和Expect语句。

filter(filterFn: (element: ElementFinder, index?: number) => boolean | wdpromise.Promise<boolean>): ElementArrayFinder;
(method) ElementArrayFinder.filter(filterFn: (element: ElementFinder, index?: number) => boolean | promise.Promise<boolean>): ElementArrayFinder

将过滤器函数应用于ElementArrayFinder中的每个元素。返回带有所有通过过滤器功能的元素的新ElementArrayFinder。过滤器函数将ElementFinder作为第一个参数,将索引作为第二个arg。这实际上不会检索底层的元素列表,因此可以在页面对象中使用。

@alias — element.all(locator).filter(filterFn)

@view

<ul class="items"> <li class="one">First</li> <li class="two">Second</li> <li class="three">Third</li> </ul>

@example

element.all(by.css('.items li')).filter(function(elem, index) {
  return elem.getText().then(function(text) {
    return text === 'Third';
  });
}).first().click();

// Or using the shortcut $$() notation instead of element.all(by.css()):

$$('.items li').filter(function(elem, index) {
  return elem.getText().then(function(text) {
    return text === 'Third';
  });
}).first().click();

@@ param filterFn筛选器功能,用于测试是否应返回元素。 filterFn可以返回布尔值或可以解析为布尔值的Promise

@ returns一个ElementArrayFinder,它表示满足过滤器功能的元素的数组。

© www.soinside.com 2019 - 2024. All rights reserved.