Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

added a few accesibility checks. more to come. #202

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/Context/AccesibilityContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Behatch\Context;

use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Exception\ResponseTextException;
use Behat\Mink\Exception\ElementNotFoundException;
use WebDriver\Exception\StaleElementReference;
use Behat\Behat\Tester\Exception\PendingException;

class AccesibilityContext extends BaseContext
{
/**
* @Then all images should have an alt attribute
*/
public function allImagesShouldHaveAnAltAttribute()
{
$images = $this->getSession()->getPage()->findAll('xpath', '//img[not(@alt)]');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, could you tell me this would refer to test image without alt?
I pull your code and test my website. There are alt attribute, but still said There are images without an alt attribute

if ($images !== null) {
throw new \Exception("There are images without an alt attribute");
}
}

/**
* @Then the title should not be longer than :arg1
*/
public function theTitleShouldNotBeLongerThan($arg1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use explicite argument name, like $length

{
$title = $this->getSession()->getPage()->find('css', 'h1')->getText();
if (strlen($title) > $arg1) {
throw new \Exception("The h1 title is more than '$arg1' characters long");
}
}

/**
* @Then all tables should have a table header
*/
public function allTablesShouldHaveATableHeader()
{
$tables = $this->getSession()->getPage()->findAll('xpath', '//table/*[not(th)]');
if ($tables !== null) {
throw new \Exception("There are tables without a table header");
}
}

/**
* @Then all tables should have at least one data row
*/
public function allTablesShouldHaveAtLeastOneDataRow()
{
$tables = $this->getSession()->getPage()->findAll('xpath', '//table/*[not(td)]');
if ($tables !== null) {
throw new \Exception("There are tables without a data row");
}
}
}
5 changes: 5 additions & 0 deletions src/class_aliases/Context/AccesibilityContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

@trigger_error('The Sanpi\\Behatch\\Context\\AccesibilityContext class is deprecated since version 2.3 and will be removed in 3.0. Use the Behatch\\Context\\AccesibilityContext class instead.', E_USER_DEPRECATED);

class_alias('\\Behatch\\Context\\AccesibilityContext', '\\Sanpi\\Behatch\\Context\\AccesibilityContext');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think it's necessary.

48 changes: 48 additions & 0 deletions tests/features/accesibility.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@accesibility
Feature: toegankelijkheid verschillende types paginas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use english language.


@accesibility
Scenario Outline: max 1 h1 and min 1 h2 on page
Given I am on "<url>"
Then I should see 1 "h1" elements
And I should see an "h2" element

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

| url |
| / |

@accesibility
Scenario Outline: h1 length check
Given I am on "<url>"
Then the title should not be longer than 70

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

| url |
| / |

@accesibility
Scenario Outline: alt check on images
Given I am on "<url>"
Then all images should have an alt attribute

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

| url |
| / |

@accesibility
Scenario Outline: check table headers
Given I am on "<url>"
Then all tables should have a table header

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

| url |
| / |

@accesibility
Scenario Outline: check table data
Given I am on "<url>"
Then all tables should have at least one data row

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

| url |
| / |