Codeception / Codeception/module-webdriver

Suggestion: `seeElementHasClass()`

Open
#126 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
39
Forks
25
PR merge metrics
No merged PRs in 30d

Description

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()`:

```php
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? :-)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.