2

I need to validate the color of a email link text . Below is my code:

it('Contact Text Validation', function(){

    expect (Contact_info_on_Login_screen.isDisplayed())


    var Email_Link = element(by.css("body > app-root > app-login > div > div > div > div > div > div.card-header.py-3.d-flex.justify-content-between.align-items-center > div > p > a:nth-child(1) > span:nth-child(1)"));

    var Col_Email = (Email_Link.getCssValue('color')).then(function(){
        browser.sleep(2000).then(function(){

            console.log(" The color for Email Link is :" + Col_Email);
        });
    });

}

The color of the same element is as shown in the css property is as below.

enter image description here

the related html code is <p _ngcontent-c1="" class="m-4"> Questions about filling in the report data or access to the application, please call <a _ngcontent-c1="" class="text-link-blue" href=""><span _ngcontent-c1="">Admin</span> / <span _ngcontent-c1=""> Manager</span></a> at <a _ngcontent-c1="" class="text-link-blue" href=""> 123-456-7890</a>. For software issues, email <a _ngcontent-c1="" class="text-link-blue" href="">other person</a> . </p>

When I run this , I got the following output from Protractor:

[13:58:52] I/hosted - Using the selenium server at http://localhost:4444/wd/hub Started The color for Email Link is :ManagedPromise::643 {[[PromiseStatus]]: "pending"}

I am not sure what I am doing wrong. It should return the color code, instead it shows that the promise is pending.

daedsidog
  • 1,732
  • 2
  • 17
  • 36
nhrcpt
  • 862
  • 3
  • 21
  • 51

3 Answers3

3

You are incorrectly resolving a promise, the callback function receives the actual resolved value as an argument:

//                                             v-----HERE-----v
Email_Link.getCssValue('color').then(function (actualColorValue) {
    console.log("The color for Email Link is :" + actualColorValue);
});
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
2
Email_Link.getCssValue('color').then(function (Value) {
    console.log("color is :" + Value);
});

https://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getCssValue

you can validate attributes by two ways.

expect(element(element(by.css("body > app-root > app-login > div > div > div > div > div > div.card-header.py-3.d-flex.justify-content-between.align-items-center > div > p > a:nth-child(1) > span:nth-child(1)"))).getCssValue('color')).toBe('#000000');

or

            return Email_Link.getCssValue("color").then(function (value) 
                {               
                if (value[0]== "rgba(55, 199, 119, 1)") {
                    return true;
                }
                else {
                    return false;
                }
            });
Bharath Kumar S
  • 1,410
  • 2
  • 10
  • 29
1

try

Email_Link.getCssValue('color')).then(function(Col_Email){
  console.log(" The color for Email Link is :" + Col_Email);
};
ic3b3rg
  • 14,629
  • 4
  • 30
  • 53