1

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?

VLL
  • 9,634
  • 1
  • 29
  • 54
Arka
  • 101
  • 1
  • 8
  • How do you know assertion is not happening? – demouser123 Jul 04 '18 at 09:22
  • Possible duplicate of [Protractor: element.getText() returns an object and not String](https://stackoverflow.com/questions/29478905/protractor-element-gettext-returns-an-object-and-not-string) – demouser123 Jul 04 '18 at 09:23
  • As in the output, I can't see any comments related to Assertions. Because if any assertion has taken place then I expect to see something like 1 assertion or 2 assertion in console. – Arka Jul 04 '18 at 13:35

1 Answers1

0
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 title = browser.getTitle();
       expect(title).toEqual('Zoo Adoption | Home');
    });
it('Provide Textfield value in Zoo Adaption HomePage',async function()
    {
         var ExpectedTextinInputField='Hello India';
        await element(by.css("input[type=""]")).sendKeys(ExpectedTextinInputField);
        await element(by.class("ng-binding")).getText().then(async function(text){
            console.log("Expected Text:"+text);
            await expect(text).toEqual(ExpectedTextinInputField);
        });     
});

Refer here for a clear explanation on creating and executing tests with the protractor.

Madhan Raj
  • 1,404
  • 1
  • 7
  • 13