csslaravellaravel-duskbrowser-testing

Assert css of an element using Dusk


I need to assert the styles of an element directly from the Dusk tests. In my application, I changed some styles of elements based on a specific condition. e.g. For invalid users, I changed the background to red. Now, I need to assert the css styles from Dusk.
Note that I don't want to check the class attribute. I want to check the styles that the class added to the element.


Solution

  • It has been solved. I used the web driver developed by Facebook. So, using it, I've selected the proper tag using xpath. Then, I get the stylesheet property of the selected tag using the web driver. Here is the source code. Note that adding the facebook web driver is required.

    $the_tag = $browser->driver->findElements(WebDriverBy::xpath('//*[@class="user-item d-flex justify-content-between align-items-center mb-3"]'))[0];
    $this->assertEquals($the_tag->getCSSValue("background"),"red");