【问题标题】:Protractor - What expected condition to use here?量角器 - 在这里使用什么预期条件?
【发布时间】:2020-10-26 12:52:44
【问题描述】:

我有 3 个选项卡,我需要测试它们是否被点击,但我似乎找不到一个好的预期条件来使用。现在我正在使用浏览器。睡眠时间更长,因为标签需要几秒钟才能加载。

标签:

代码:

let locator = {

  upcomingTabButton : element(by.css('div.toolbar-content.toolbar-content-md ion-segment ion-segment-button:nth-child(1)')),
  pendingTabButton : element(by.css('div.toolbar-content.toolbar-content-md ion-segment ion-segment-button:nth-child(2)')),
  completedTabButton : element(by.css('div.toolbar-content.toolbar-content-md ion-segment ion-segment-button:nth-child(3)')),
  activeTab : element(by.css('ion-segment ion-segment-button.segment-button.segment-activated')),
  upcomingActiveTab: element(by.cssContainingText('ion-segment ion-segment-button.segment-button.segment-activated', 'UPCOMING')),


};


describe('When x tab button is pressed, ', function () {

  it('if x = PENDING tab, then it should be activated', () => {
    browser.sleep(1000);
    browser.wait(EC.elementToBeClickable(locator.pendingTabButton),5000);
    locator.pendingTabButton.click();
    browser.sleep(10000);
    expect(element(by.css('ion-segment ion-segment-button.segment-button.segment-activated')).getText()).toEqual('PENDING');
  });


  it('if x = UPCOMING tab, then it should be activated', () => {

    browser.wait(EC.elementToBeClickable(locator.upcomingTabButton),5000);
    locator.upcomingTabButton.click();
    //browser.wait(EC.presenceOf(locator.upcomingActiveTab),5000);
    browser.sleep(10000);
    expect(element(by.css('ion-segment ion-segment-button.segment-button.segment-activated')).getText()).toEqual('UPCOMING');

  });

  it('if x = COMPLETED tab, then it should be activated', () => {

    browser.wait(EC.elementToBeClickable(locator.completedTabButton),5000);
    locator.completedTabButton.click();
    //browser.wait(EC.presenceOf(locator.activeTab),5000);
    browser.sleep(10000);
    expect(element(by.css('ion-segment ion-segment-button.segment-button.segment-activated')).getText()).toEqual('COMPLETED');
  });
});

我尝试了一些预期的条件,但没有任何效果,因为我需要查看选项卡何时被选中,而我没有找到任何类似的 exp 条件。

我用browser.sleep(10000) 10秒,不过这样,不是很好用。

谁能帮帮我?

标签内容加载大约需要 5/6 秒

【问题讨论】:

    标签: android html ionic-framework automation protractor


    【解决方案1】:
    /**
     * wait until some element is present
     * 
     */
    this.waitElement = function(ElmFinder){
        var i = 0;
        var _retryOnErr = function(err) {
            console.log(' <<< warning: wait retrying iteration: ' + i + ' >>> ');
            browser.sleep(500);
            return false;
        };
    
        browser.wait(function() {
            i++;
            return ElmFinder.isDisplayed().then(function(present) {
                if (present) {
                    return true;
                } else {
                    console.log("element is not present");
                    return _retryOnErr();
                }
            }, _retryOnErr);
        }, 120*1000, 'Error waiting for element present: ').
        then(function(waitRetValue) {
            return waitRetValue; // usually just `true`
        }, function(err) {
            throw err + ' after ' + i + ' iterations.';
        });
    };
    

    【讨论】:

      猜你喜欢
      • 2015-05-28
      • 2015-02-28
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      相关资源
      最近更新 更多