Skip to content

Suggestion: seeElementHasClass() #126

@ThomasLandauer

Description

@ThomasLandauer

I wrote a simple method for App\Tests\Support\Helper\Acceptance to check if an HTML element has a certain CSS class. Does the same as JavaScript .classList.contains():

public function seeElementHasClass(array|string $element, string $class): void
{
    $I = $this->getModule('WebDriver');
    $classesString = $I->grabAttributeFrom($element, 'class');
    $classesArray = explode(' ', $classesString);
    $this->assertContains($class, $classesArray);
}

public function dontSeeElementHasClass(array|string $element, string $class): void
{
    $I = $this->getModule('WebDriver');
    $classesString = $I->grabAttributeFrom($element, 'class');
    $classesArray = explode(' ', $classesString);
    $this->assertNotContains($class, $classesArray);
}

Maybe somebody could add it to the module? :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions