marcortola / behat-seo-contexts
Behat 扩展,用于测试一些页面 SEO 因素:meta 标题/描述、canonical、hreflang、meta robots、robots.txt、重定向、sitemap 验证、HTML 验证、性能...
4.0.0
2022-11-28 17:15 UTC
Requires
- php: >=7.1
- ext-dom: *
- behat/behat: ^3.0
- behat/mink-extension: ^2.0
- matriphe/iso-639: ^1.2
- rexxars/html-validator: ^2.1
- vipnytt/robotstxtparser: ^2.0
Requires (Dev)
- behat/mink-browserkit-driver: ^1.3
- behat/mink-goutte-driver: ^1.0
- behat/symfony2-extension: ^2.0
- phpmd/phpmd: ^2.7
- phpstan/phpstan: ^0.12
- phpstan/phpstan-webmozart-assert: ^0.12.7
- sebastian/phpcpd: ^4.1
- sensiolabs/security-checker: ^6.0
- symplify/easy-coding-standard: ^6.1
- thecodingmachine/phpstan-strict-rules: ^0.12
- webmozart/assert: ^1.9
README
Behat 扩展,用于测试一些页面 SEO 因素。
包含测试的上下文
- 标题 / meta 描述
- canonical
- hreflang
- meta robots
- robots.txt
- 索引测试:测试 meta robots + robots.txt + X-Robots-Tag 头
- 重定向
- sitemap 验证(包含多语言)
- HTML 验证
- 资产性能
- 可访问性
- 用户体验
- 更多...
安装
基本要求
- PHP 7.1+
- Behat 3+
- Mink + Mink 扩展
如何安装
- 安装 Composer
- 执行
$ composer require marcortola/behat-seo-contexts --dev
- 将所需的上下文添加到
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
特色步骤
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
本地化Context
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
示例
此库已自测,您可以在features 目录中找到示例。请随意探索以了解每个步骤定义。
实用技巧
- 如果您在 Symfony 项目中工作,请使用Symfony KernelDriver以提高性能。