无法检查量角器中的状态指示器

时间:2017-11-17 10:06:58

标签: angular typescript testing protractor end-to-end

我正在使用量角器进行端到端测试,需要在点击按钮之前检查状态指示灯是否消失。现在我无法做到。 我尝试使用invisibilityOf()以及stalenessOf(),但它无效。它显示错误'在点(540,823)处不可点击,其他元素将收到点击:< #api-status-indicator>'

这是我在PageObject中的代码:

public isNotPresent(elem) {
    return browser.wait(protractor.ExpectedConditions.stalenessOf(elem), 5000).then(function () {
        console.log("Status indicator is not present in DOM");
        return true; //success
    },function () {
        console.log("Status indicator is present in DOM");
        return false; //Failure
    });
}

public waitForStatusIndicator(){
    console.log('in method wait for status indicator');
    return this.isNotPresent(element(by.css('#api-status-indicator'))).then((isNotPresent)=>{
        return isNotPresent;
    });
}

我试图查看状态指示符的位置

PageObject.waitForStatusIndicator().then(function (isNotPresent) {
       if(isNotPresent == true) {
       someButton.click();
       return expect(browser.getCurrentUrl()).not.toBe(browser.baseUrl + "/login");
      }
})

我哪里错了?

1 个答案:

答案 0 :(得分:1)

如果该元素刚刚出现并且不在DOM中,那么首先需要等到它出现并且在您检查之前可见,它再次消失。

整体情况如下:

import java.text.DecimalFormat;
import java.util.Scanner;

public class TwoDimArray {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        // 1) Declare and allocate Storage
        //Each day name is assigned to the array as a String so each name must be enclosed in apostrophes and each string must be separated by commas.
        String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
        double[][] Temperature = new double[4][7];

        // 2) Populate Array
        for (int i = 0; i < Temperature.length; i++) {
            for (int j = 0; j < Temperature[0].length; j++) {
                //days[j] will print the proper day and "(i+1)" will print the proper day of the week
                System.out.print("Enter " + days[j] + " Temperature " + "for Week " + (i + 1) + ": " + "    ");
                Temperature[i][j] = scan.nextDouble();
            }

        }
        System.out.println();
        System.out.println("              Weekly Temperature Report ");
        System.out.println("Mon     Tue     Wed     Thurs    Fri    Sat     Sun    Average");

        double columnTotal, average;
        // 4) Output Array

        for (int i = 0; i < Temperature.length; i++) {
            System.out.println();
            columnTotal = 0;
            for (int j = 0; j < Temperature[0].length; j++) {
                System.out.print(Temperature[i][j] + "\t");
                columnTotal += Temperature[i][j];
            }
            average = columnTotal / 7;
            System.out.println(average);
        }

        System.out.println();
        System.out.println("------------------------------------------------------------------");
        int avg;
        for (int i = 0; i < Temperature[0].length; i++) {
            columnTotal = 0;
            avg = 0;
            for (int j = 0; j < Temperature.length; j++) {
                columnTotal = columnTotal + Temperature[j][i];

            }
            System.out.print((columnTotal / 4) + "    ");
            System.out.print(average / 4);

        }
    }
}

你的规格: 再也不需要任何public isNoLongerPresent(elem) { //NOTE: If any of the expected conditions don't happen, your code times out. //No need for false-check or similar var EC = protractor.ExpectedConditions; browser.wait(EC.presenceOf(elem), 5000); browser.wait(EC.visibilityOf(elem), 5000); //Note, that visibilityOf requires presence return browser.wait(EC.stalenessOf(elem), 5000); } public waitForStatusIndicator(){ console.log('in method wait for status indicator'); return this.isNoLongerPresent(element(by.css('#api-status-indicator'))); } 。量角器同步执行它,如果有任何then(),你的代码会超时。

false