Experimenting with alterations to link styles

A particular test we are conducting involves examining the style changes of a link (a element) after a mouse over.

Initially, the link is displayed with a black font and no decoration. However, upon hovering the mouse over it, the font color changes to blue and the text becomes underlined. Below is the test in question:

it("should change font style on mouse over", function () {
    expect(scope.page.forgotPassword.getCssValue("color")).toEqual("rgba(11, 51, 60, 1)");
    expect(scope.page.forgotPassword.getCssValue("text-decoration")).toEqual("none");

    browser.actions().mouseMove(scope.page.forgotPassword).perform();

    expect(scope.page.forgotPassword.getCssValue("color")).toEqual("rgba(42, 100, 150, 1)");
    expect(scope.page.forgotPassword.getCssValue("text-decoration")).toEqual("underline");
});

The issue arises when approximately 1 out of 10 runs fail due to the following error messages:

Expected 'rgba(11, 51, 60, 1)' to equal 'rgba(42, 100, 150, 1)'.

Expected 'none' to equal 'underline'.

My suspicion is that the test reads the css styles before they have had a chance to change.

How can I enhance the reliability and stability of this test? Any assistance would be greatly appreciated.

Answer №1

Upon receiving a recommendation from @P.T., I have successfully implemented a unique reusable "Expected Condition":

checkForCssValue = function (elementFinder, cssProperty, cssValue) {
    return function () {
        return elementFinder.getCssValue(cssProperty).then(function(actualValue) {
            return actualValue === cssValue;
        });
    };
};

Here is an example of how this can be used:

browser.wait(checkForCssValue(scope.page.forgotPassword, "color", "rgba(42, 100, 150, 1)"), 1000);
browser.wait(checkForCssValue(scope.page.forgotPassword, "text-decoration", "underline"), 1000);

Answer №2

The delay in CSS update that you are experiencing with protractor/webdriver might be due to the asynchronous nature of the updates. Have you implemented any unique methods for handling CSS updates on hover? For instance, is there a specific animation or update delay being used?

In situations where protractor may not anticipate a delay in updates, it's advisable to approach your test differently. Rather than expecting an immediate result and racing against browser changes, consider reframing the test as "waiting until the desired value appears." While this approach may be slower in case of failure, it could prove beneficial.

It may be simpler to check for the change in the text-decoration property to 'underline' (assuming both properties update simultaneously). By waiting for one property change, you can validate the other as well.

Instead of:

expect(scope.page.forgotPassword.getCssValue("text-decoration")).toEqual("underline");

You could try the following untested code:

browser.wait(function() { 
 return scope.page.forgotPassword.getCssValue("text-decoration")).then(function(value) {
   return value === 'underline';
 });

(Alternatively, utilize the Expected Conditions infrastructure for this purpose ?)

To streamline the process, encapsulate the functionality within a function:

function waitForValue(valPromise, expectedVal) {
   return browser.wait(function() {
      return valPromise.then(function(value) {
         return value === expectedValue;
      });
   });
}

// Update your test with:
waitForValue(scope.page.forgotPassword.getCssValue("text-decoration"), 'underline');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can floated divs be prevented from collapsing without taking up any width?

Let's discuss an issue that is not related to block elements collapsing when their children are floated, and has nothing to do with clearing at all. Imagine having a set of floated divs like: <div class="column">Column 1</div> <div cl ...

A guide to resizing images to fit the page in React using Bootstrap

Currently, I am utilizing a function to iterate over each item in the props array and generate an image tag. My goal is to have every set of 3 images enclosed within a row div using Bootstrap to ensure proper page layout. However, I am struggling to implem ...

Automated static file versioning in Google App Engine/Python

Recently, I've been experimenting with Google's page speed service, and it has inspired me to implement automatic versioning of static files in my GAE/P application. This way, I can fully utilize longer caching times. Developing a script to perf ...

Tips on concealing the parent div while only displaying the child div

Within my HTML, I have a parent div and a child div. I am trying to hide the parent div while still displaying the child div (which is a canvas element). I've attempted using show, hidden, and visibility options but none of them seem to be working pro ...

Organize your table with CSS styling

Looking for a way to rearrange a table with 2 columns after every 2 rows so that the lines continue on the right side? Check out the example below: [1][2] [1][2][5][6] [3][4] => [3][4][7][8] [5][6] [7][8] Wondering if this can be achieved using o ...

Optimizing Spacing in Twitter Bootstrap 3.1 Nav-stacked Design

Being a novice in HTML coding, I decided to utilize an established API for my project. After some previous experience, I opted to use Twitter Bootstrap 3.1. Here is how my current nav-stacked section appears with a customized CSS to make it collapsible: ...

Testing Laravel Pagination Features

After creating a basic HTTP Test for my application, I encountered a challenge: <?php namespace Tests\Feature; use App\Models\Author; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Testing\ ...

The back button functionality in Android cannot be altered or overridden using JavaScript

Hey everyone, I'm currently in the process of developing a mobile application using phonegap. I'm facing an issue where I want to disable the functionality of the back button from navigating to the previous page. I simply want it to do nothing or ...

Incorporating pre-designed elements into the bottom section of my

I'm currently facing an issue while trying to integrate a footer content from a template into my slideout footer. The problem is that the template footer is currently spanning across the entire width of the page, and I am struggling to contain it with ...

What is the reason for the image not being positioned in the top left corner of the html page?

My simple HTML page consists of only one image: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Anz ...

How to locate and interact with the submitName element using Selenium WebDriver

Is there a way to access an input text element with a dynamic id, no name, but has the attribute submitName using Selenium web driver? The document contains multiple elements and I need to retrieve 4 of them. <input class="mandy" id="ms__id7" submitNam ...

Alternating row colors using CSS zebra striping after parsing XML with jQuery

After successfully parsing XML data into a table, I encountered an issue with applying zebra stripe styling to the additional rows created through jQuery. Despite my efforts to troubleshoot the problem in my code, I remain perplexed. Below is a snippet of ...

What could be causing the background to disappear when the window width is reduced?

Can someone please explain why, after reducing the width of the window on , there is no wooden background in the upper right corner? Thank you in advance. ...

Troubleshooting a Chromedriver issue upon shutting down an EC2 instance

My goal is to execute a straightforward script on an Ubuntu EC2 machine using Selenium. I have incorporated the following code snippet inside a loop because the script needs to run continuously in the background: from selenium import webdriver def play() ...

The navbar toggler icon is not displaying

<header class="container"> <div class="container pt-3 col-md-5 col-sm-5 col-xs-6 text-center"> <a href="#" class="site-logo"><img src="#"></a> <button class="navbar-toggler" type="button" data-toggle="collapse" ...

Tips for minimizing the arrow size in the infowindow on a Google Maps interface

As a newcomer to customizing Google Maps, I am looking to decrease the size of the arrow in the infowindow and position it in the bottom left corner for a better appearance. I am struggling to figure out how to adjust the height and width of the arrow and ...

Tips for executing a function in the HC-Sticky plugin?

Currently, I am utilizing the HC-Sticky JavaScript plugin and endeavoring to utilize the documented reinit method. However, I am facing difficulty in understanding how to execute it. In this CodePen demo, a basic setup is displayed along with an attempt t ...

Tips on adjusting the color of a link once it has been clicked?

Looking for a link with a specific style? a { color: #999; &:hover { color: #008da0; } &:visited { color: #999; } /* I added this to test if it's gonna fix it, but it didn't */ } Upon clicking the link, it turns blue and remains s ...

Button Fading in Selenium

Hey there, I'm encountering an issue where I am trying to click on a button that remains disabled until certain fields are filled in. I am using Firefox for this task. My script successfully populates the required fields, making the button clickable w ...

Adaptive website backdrop

I have created a unique background for my website design, which includes 3 slices labeled as div id top, middle, and bottom. You can view the design in this image. I am interested in making this background responsive. While I have come across examples of ...