javascript isPresent总是返回TRUE(量角器)

时间:2018-05-15 10:07:22

标签: javascript protractor automated-tests

所以,我正在访问一个应用程序。有multiple employee records。但是,没有重复的记录。我正在删除员工记录,然后尝试验证员工记录是否已实际删除。我正在尝试使用 xpath 并使用isPresent函数查找员工姓名。问题是虽然删除了员工记录,但输出总是返回

Employee present: true

以下是我正在使用的代码片段:

it('Delete Employee', function() {
        login_page.enterUsername(browser.params.username);
        login_page.enterPassword(browser.params.password);
        var employeelist_page = login_page.clickLoginButton();
        var greetings = employeelist_page.greetingText();
        expect(greetings).toContain('Hello');
        var empName = employeelist_page.getEmployeeName(Master Shifu);
        empName.getText().then(function(text) {
            console.log('Empoyee record to be deleted, found: ' + text);
        });
        employeelist_page.getEmployee(Master Shifu).click();
        //element(by.id('bDelete')).click();
        employeelist_page.clickDeleteButton();
        //browser.switchTo().alert().accept();
        var EC = protractor.ExpectedConditions;
        browser.wait(EC.alertIsPresent(), 5000, "Alert is not getting present :(")
                browser.switchTo().alert().accept().then(function(){
                    var employeelist_page1 = require('../page/employeelist_page.js');
                    employeelist_page1.getEmployee(Master Shifu).isPresent().then(function(isPresent){
                        if(isPresent){
                            console.log('Employee present: true');
                        } else {
                            console.log('Employee present: false');
                        }
                    });
                });

    });

以下是员工列表的HTML示例:

<ul id="employee-list">
<li class="ng-scope ng-binding" ng-class="employee.id == selectedEmployee.id && 'active'" ng-dblclick="editEmployee()" ng-click="selectEmployee(employee)" ng-repeat="employee in employees"> Tianna2 Jenkins </li>
<li class="ng-scope ng-binding" ng-class="employee.id == selectedEmployee.id && 'active'" ng-dblclick="editEmployee()" ng-click="selectEmployee(employee)" ng-repeat="employee in employees"> Anjali McClure </li>
<li class="ng-scope ng-binding" ng-class="employee.id == selectedEmployee.id && 'active'" ng-dblclick="editEmployee()" ng-click="selectEmployee(employee)" ng-repeat="employee in employees"> John Snow </li>
<li class="ng-scope ng-binding" ng-class="employee.id == selectedEmployee.id && 'active'" ng-dblclick="editEmployee()" ng-click="selectEmployee(employee)" ng-repeat="employee in employees"> Cole Prohaska </li>
<li class="ng-scope ng-binding" ng-class="employee.id == selectedEmployee.id && 'active'" ng-dblclick="editEmployee()" ng-click="selectEmployee(employee)" ng-repeat="employee in employees"> Annetta Hessel </li>

以下是输出:

* Empoyee record to be deleted, found: Master Shifu

员工在场:真实

1 个答案:

答案 0 :(得分:0)

尝试下面的脚本。我添加.then函数的原因是thenblock中的脚本将在clickdeleteButton操作完成后执行。删除后检查元素是否存在的脚本可能在删除之前执行。

Map