0

So, I am accessing an application. There are multiple employee records. However, there are no duplicate records. I am deleting an employee record and then trying to verify that the employee record has actually deleted. I am trying to find the employee name using xpath and using isPresent function. The problem is that though the employee record is deleted the output is always returning:

Employee present: true

Here is the piece of code that I am using:

    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');
                            }
                        });
                    });
    
        });

Here is the output:

Empoyee record to be deleted, found: Master Shifu Employee present: true

Here is the list of functions in employee page:

    require('./create_page.js');
    require('./edit_page.js');
    var employeelist_page=function(){
        this.greetingText=function(){
            return element(by.id('greetings')).getText();
        };
        this.clickCreateButton=function(){
            element(by.id('bAdd')).click();
            return require('./create_page.js');
        };
        this.clickEditButton=function(){
            element(by.id('bEdit')).click();
            return require('./edit_page.js');
        };
        this.clickDeleteButton=function(){
            element(by.id('bDelete')).click();
        };
        this.getEmployee=function(empname){
            //return element(by.cssContainingText("#employee-list > li", empname));
            return element(by.xpath("//ul[@id='employee-list']/li[contains(text(),'" + empname + "')]"));
            
        };
        this.getEmployeeName=function(empname){
            //return element(by.cssContainingText("#employee-list > li", empname));
            return element(by.xpath("//ul[@id='employee-list']/li[contains(text(),'" + empname + "')]")).getText();
            
        };
        //this.clickEmployeeName=function(){
            //element(by.xpath('//ul[@id="employee-list"]/li[contains(text(),"Vladimir Putin")]')).click();
        //  getEmployee().click();
        //};
        
    };
    module.exports=new employeelist_page();
6
  • Do you mean: Master Shifu or 'Master Shifu' ? May 15, 2018 at 22:44
  • Yes Vishal, it's 'Master Shifu'. While writing the question I replaced the variable value with this constant and at that time, I forgot the quotes.
    – Aalok
    May 16, 2018 at 6:03
  • Ok.Please share the 'getEmployee' method code as it is central to this problem. May 16, 2018 at 20:27
  • Hi Vishal, updated the question to include the functions on Employee page
    – Aalok
    May 18, 2018 at 0:23
  • Check for 'isDisplayed' instead of 'isPresent'. May 18, 2018 at 11:21

1 Answer 1

1

Put a expected Condition to wait for page re-load after confirmation of delete pop-up. Basically as I understand ,you need to give sometime to get the element removed from the DOM.

Example Code:

var EC =protractor.ExpectedConditions; 
// Waits for the element with id 'abc' to be no longer present on the dom. 

browser.wait(EC.stalenessOf($('#abc')), 5000,"Element still exists");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.