Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 如何检测页面资产的404错误?_Selenium_Behat_Mink_Goutte - Fatal编程技术网

Selenium 如何检测页面资产的404错误?

Selenium 如何检测页面资产的404错误?,selenium,behat,mink,goutte,Selenium,Behat,Mink,Goutte,我刚开始学比哈特和貂皮。我正在使用MinkExtension与痛风和硒,以及DrupalExtension 到目前为止,一切顺利。我可以加载页面,查找各种元素,测试链接等 但我不知道如何检查各种资产上的404,特别是图像,还有css和js文件 任何提示或示例都将不胜感激。使用Goutte web crawler时,您可以这样做: $crawler = $client->request('GET', 'http://your-url.here'); $status_code = $clien

我刚开始学比哈特和貂皮。我正在使用MinkExtension与痛风和硒,以及DrupalExtension

到目前为止,一切顺利。我可以加载页面,查找各种元素,测试链接等

但我不知道如何检查各种资产上的404,特别是图像,还有css和js文件


任何提示或示例都将不胜感激。

使用Goutte web crawler时,您可以这样做:

$crawler = $client->request('GET', 'http://your-url.here');
$status_code = $client->getResponse()->getStatus();
if($status_code==404){
  // Do something
}

您可以尝试以下方法:

<?php

use Behat\Behat\Context\Context;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Client;

class FeatureContext extends WebTestCase implements Context {

  /**
   * @var Client
   */
  private $client;

  /**
   * @When /^I send a "([^"]*)" request to "([^"]*)"$/
   *
   * @param $arg1
   * @param $arg2
   */
  public function iSendARequestTo($arg1, $arg2) {
    $this->client = static::createClient();
    $this->client->request($arg1, $arg2);
  }

  /**
   * @Then /^the output should contain: "([^"]*)"$/
   *
   * @param $arg1
   */
  public function theOutputShouldContain($arg1) {
    $this->assertContains($arg1, $this->client->getResponse()->getContent());
  }

  /**
   * @Then /^the status code should be "([^"]*)"$/
   *
   * @param $arg1
   */
  public function theStatusCodeShouldBe($arg1) {
    $this->assertEquals($arg1, $this->client->getResponse()->getStatusCode());
  }
}

请在此(部分)中检查以下方法:

以下是使用上述方法以Behat编写的示例场景:

  @roles @api @regression
  Scenario: Verify Anonymous User access to /user/login
    Given I am not logged in
    Then I check the HTTP response code is 200 for '/user/login'

  @roles @api @regression
  Scenario: Verify Anonymous User access to /admin
    Given I am not logged in
    Then I check the HTTP response code is 403 for '/admin'

  @roles @api @regression
  Scenario: Verify Administrator access to /admin
    Given I am logged in as a user with the admin role
    And I am on "/admin"
    Then the response status code should be 200
可以使用一个微框架,它可以帮助在Behat中进行RESTfulAPI测试。它支持使用Behat和Guzzle进行行为驱动的API测试

检查以下各项:

相关的:
  @roles @api @regression
  Scenario: Verify Anonymous User access to /user/login
    Given I am not logged in
    Then I check the HTTP response code is 200 for '/user/login'

  @roles @api @regression
  Scenario: Verify Anonymous User access to /admin
    Given I am not logged in
    Then I check the HTTP response code is 403 for '/admin'

  @roles @api @regression
  Scenario: Verify Administrator access to /admin
    Given I am logged in as a user with the admin role
    And I am on "/admin"
    Then the response status code should be 200
  Scenario: Saying
    When I request "/examples/_001_helloworld/say"
    Then the response status code should be 404
    And the response is JSON
    And the type is "array"