I am new to Protractor and trying my sample code; but struggling to get the Assertion working in Protractor.
Even in some cases, getText()
of an element is returning an Object Array though in the page, there is only one element having the attribute.
Example of the Code:
describe('Launch Zoo Adaption Website and Provide Text Value',function()
{
beforeEach(async function(){
await browser.get("http://www.thetestroom.com/jswebapp/index.html");
});
it('Launch Zoo Adaption Website',async function()
{
var some_name = 'Zoo Adoption | Home';
some_name = browser.getTitle().then(async function(webpagetitle){
await console.log("Title:"+webpagetitle);
if (webpagetitle === 'Zoo Adoption | Home'){
return 'Some Other Name';
}
else{
return 'Some Name';
}
});
await expect(some_name).toEqual('Some Other Name');
//var ExpectedHomePageTitle='Zoo Adoption | Home';
//browser.driver.sleep(3000);
//await console.log("Actual Title:"+browser.getTitle());
//browser.driver.sleep(3000);
//await expect(browser.getTitle()).toEqual('Zoo Adoption | Home');
});
it('Provide Textfield value in Zoo Adaption HomePage',async function()
{
var ExpectedTextinInputField='Hello India';
await element(by.model("person.name")).sendKeys(ExpectedTextinInputField);
await element(by.binding("person.name")).getText().then(async function(text){
console.log("Expected Text:"+text);
await expect(text).toEqual(ExpectedTextinInputField);
});
await console.log("Actual text displayed in dynamic field:"+(element(by.binding('person.name'))).getText());
});
});
Console Output:
Started Title:Zoo Adoption | Home .Expected Text:Hello India Actual text displayed in dynamic field:[object Object]
.
2 specs, 0 failures Finished in 3.695 seconds
Please help me understand:
a. Why there is no Assertion happening for my code?
b. Why getText() is returning Array of Object?