Coder Social home page Coder Social logo

marcortola / behat-seo-contexts Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 4.0 154 KB

Behat extension for testing some On-Page SEO factors: meta title/description, canonical, hreflang, meta robots, robots.txt, redirects, sitemap validation, HTML validation, performance...

License: MIT License

PHP 80.98% Gherkin 19.02%
behat-context seo canonicalization sitemap-validation robots-txt hreflang-checker html-validation meta-tags

behat-seo-contexts's Introduction

Behat SEO Contexts

Latest Version Build Status Quality Score

Behat extension for testing some On-Page SEO factors.

Includes contexts for testing:

  • title / meta description
  • canonical
  • hreflang
  • meta robots
  • robots.txt
  • indexation: tests meta robots + robots.txt + X-Robots-Tag header
  • redirects
  • sitemap validation (inc. multilanguage)
  • HTML validation
  • assets performance
  • accessibility
  • UX
  • more...

Installation

Basic requirements:

  • PHP 7.1+
  • Behat 3+
  • Mink + Mink extension

How to install it

  1. Install Composer
  2. Execute:
$ composer require marcortola/behat-seo-contexts --dev
  1. Add the Context you need to behat.yml:
# behat.yml
default:
    # ...
    suites:
        default:
          contexts:
            - MarcOrtola\BehatSEOContexts\Context\MetaContext
            - MarcOrtola\BehatSEOContexts\Context\LocalizationContext
            - MarcOrtola\BehatSEOContexts\Context\RobotsContext
            - MarcOrtola\BehatSEOContexts\Context\IndexationContext
            - MarcOrtola\BehatSEOContexts\Context\RedirectContext
            - MarcOrtola\BehatSEOContexts\Context\SitemapContext
            - MarcOrtola\BehatSEOContexts\Context\HTMLContext
            - MarcOrtola\BehatSEOContexts\Context\PerformanceContext
            - MarcOrtola\BehatSEOContexts\Context\SocialContext
            - MarcOrtola\BehatSEOContexts\Context\AccessibilityContext
            - MarcOrtola\BehatSEOContexts\Context\UXContext

Featured steps

MetaContext
Then the page canonical should not be empty
Then the page canonical should be :expectedCanonicalUrl
Then the page title should not be empty
Then the page title should be :expectedTitle
Then the page meta description should not be empty
Then the page meta description should be :expectedMetaDescription
Then the page meta robots should be noindex
Then the page meta robots should not be noindex
LocalizationContext
Then the page hreflang markup should be valid
RobotsContext
Given I am a :crawlerUserAgent crawler
Then I should not be able to crawl :resource
Then I should be able to crawl :resource
Then I should be able to get the sitemap URL
IndexationContext
Then the page should be indexable
Then the page should not be indexable
RedirectContext
Given I follow redirects
Given I do not follow redirects
Then I should be redirected to :url
SitemapContext
Given the sitemap :sitemapUrl
Then the sitemap should be valid
Then the index sitemap should be valid
Then the multilanguage sitemap should be valid
Then the index sitemap should have a child with URL :childSitemapUrl
Then /^the sitemap should have ([0-9]+) children$/
Then the multilanguage sitemap should pass Google validation
Then the sitemap URLs should be alive
Then /^(\d+) random sitemap URLs? should be alive$/
HTMLContext
Then the page HTML markup should be valid
Then /^the page HTML5 doctype declaration should (not |)be valid$
PerformanceContext
Then /^browser cache should be enabled for (.+\..+|external|internal) (png|jpeg|gif|ico|js|css) resources$/
Then /^Javascript code should load (async|defer)$/
Then HTML code should be minified
Then CSS code should be minified
Then Javascript code should be minified
Then CSS code should load deferred
Then critical CSS code should exist in head
SocialContext
Then /^the (Twitter|Facebook) Open Graph data should satisfy (minimum|full) requirements$/
AccessibilityContext
Then the images should have alt text
UXContext
Then the site should be responsive
Then the site should not be responsive

Examples

This library is self-tested, and you can find examples inside the features directory. Feel free to explore it to discover each step definition.

Useful tips

behat-seo-contexts's People

Contributors

andreitic avatar bystro avatar leymannx avatar marcortola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

behat-seo-contexts's Issues

Remove assertValidSitemap into dedicated step

In the very first sitemap step public function theSitemap which is needed for all subsequent steps the sitemap gets validated rather strictly against multiple schemas. Which is a real cool thing, but let's better make that a dedicated step.

Because the validation simply is too strict, I think. Assuming a sample sitemap without the initial <?xml> tag for example, this will simply fail the strict validation. But still it may be a valid sitemap, eaten by Google without any problem, and which URLs still can be checked afterwards in the public function theSitemapUrlsAreAlive step without any problem.

Why the rebranding?

Glad I found the package again, thought it was lost forever.

It was initially named novecode/behat-website-contexts, right?

Keep up the good work!

Incorrect namespace in readme

Hey mate,

Using this lib and following the instructions in the readme shows;

MarcOrtola\BehatSEOContexts\Context\

as the namespace. Looks like you've declared;

MOrtola\BehatSEOContexts\Context\

instead.

Thanks!

Add step to check given number of random sitemap URLs

@Then the sitemap URLs are alive can become a pretty time-consuming step given a huge sitemap of let's say 1000 URLs.

Let's add a step that checks only a given number of random URLs to reduce the time this step will take.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.