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();