gpt4 book ai didi

symfony - 没有匹配 XPath "//html"的元素 (Behat\Mink\Exception\DriverException)

转载 作者:行者123 更新时间:2023-12-03 17:34:03 25 4
gpt4 key购买 nike

我真的不明白为什么 Mink/Behat 找不到“登录”文本。

我的场景很简单:

Scenario: Valid Registration
Given I am on "/register/"
Then the response status code should be 200
Then print current URL
Then show last response
Then I should see "Login"

输出看起来正确:
Scenario: Valid Registration                  # features/registration.feature:9
Given I am on "/register/" # Behat\MinkExtension\Context\MinkContext::visit()
Then the response status code should be 200 # Behat\MinkExtension\Context\MinkContext::assertResponseStatus()
Then print last response # Behat\MinkExtension\Context\MinkContext::printLastResponse()
│ http://127.0.0.1:8000/app_test.php/register/

│ <!DOCTYPE html>
│ <html>
│ <head>
│ <meta charset="UTF-8" />
│ </head>
│ <body>
│ <div>
│ <a href="/app_test.php/login">Login</a>
│ </div>
│ </body>
│ </html>
Then I should see "Login" # Behat\MinkExtension\Context\MinkContext::assertPageContainsText()
There is no element matching XPath "//html" (Behat\Mink\Exception\DriverException)

这里有趣的是,看起来 Mink 无法找到 HTML 节点,即使它在响应中。

这是我的 behat.yml
default:
suites:
default:
contexts:
- Behat\MinkExtension\Context\MinkContext
- AppBundle\Behat\WebApiContext
- AppBundle\Behat\HookContext
- AppBundle\Behat\UserContext
- AppBundle\Behat\WorkspaceContext
- AppBundle\Behat\WorkspaceAccessContext
- AppBundle\Behat\OrganisationContext
- AppBundle\Behat\ProjectContext
- AppBundle\Behat\ProjectAccessContext
- AppBundle\Behat\TaskContext
- AppBundle\Behat\ActivityContext
extensions:
Behat\WebApiExtension:
base_url: http://127.0.0.1:8000/app_test.php
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://127.0.0.1:8000/app_test.php
show_cmd: 'open %s'
goutte: ~
# sessions:
# default:
# symfony2: ~

任何想法将不胜感激。

更新:

如果我 curl URL,则响应 Content-Type 是 application/json。我认为这可能是问题所在。
$ curl http://127.0.0.1:8000/app_test.php/register/ -i
HTTP/1.1 200 OK
Host: 127.0.0.1:8000
Connection: close
X-Powered-By: PHP/5.6.6
Cache-Control: no-cache
Date: Mon, 08 Jun 2015 02:11:28 GMT
Content-Type: application/json
X-Debug-Token: e8497a
Set-Cookie: MOCKSESSID=3a989c1f8f24288959ac3cbac811374f1e9e1b2173ab68915f6c5e9bd766bd96; path=/

更新:

好的,将 fos_rest_bundle 优先级更改为 html, json 现在响应为 Content-Type: text/html
fos_rest:
disable_csrf_role: ROLE_API
routing_loader:
default_format: json,
include_format: true
body_listener: true
param_fetcher_listener: force
format_listener:
rules:
-
path: '^/'
priorities: ['html', 'json', 'xml']
fallback_format: html
prefer_extension: true
view:
formats:
rss: false
json: true
xml: true
templating_formats:
html: true
force_redirects:
html: false
serializer:
serialize_null: true

curl 输出:
$ curl http://127.0.0.1:8000/app_test.php/register/ -i
HTTP/1.1 200 OK
Host: 127.0.0.1:8000
Connection: close
X-Powered-By: PHP/5.6.6
Cache-Control: no-cache
Date: Mon, 08 Jun 2015 02:15:44 GMT
Content-Type: text/html; charset=UTF-8
X-Debug-Token: 6827bd
Set-Cookie: MOCKSESSID=806389b88e7a2acf1f1a8d4c7089e7b93e10ed6b28f3035f0367d36b5871807b; path=/

最佳答案

我偶然发现了同样的问题。原来,还有curl example.com绝对没有返回任何东西。只是空白。这意味着没有一行 HTML Behat/Mink 可以解析。

我通过修复我的安装来修复它并使页面完全可访问。

关于symfony - 没有匹配 XPath "//html"的元素 (Behat\Mink\Exception\DriverException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30689119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com