为什么 Selenium RC 在虚拟机上看不到站点

发布于 2024-10-08 17:48:33 字数 2758 浏览 0 评论 0原文

我无法让 Selenium 查看虚拟主机上托管的网站 机器。以下测试导致错误,我不知道为什么:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class ActualTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://10.48.77.48/"); // IP of virtual machine
        $this->setHost('192.168.101.1'); // IP of my Mac
    }

    public function testGetHomePage()
    {
        $this->open("/", true);
    }
}

它返回以下错误消息,表明它无法 找到虚拟机:

$ phpunit ActualTest.php
PHPUnit 3.5.6 by Sebastian Bergmann.

E

Time: 7 seconds, Memory: 6.75Mb

There was 1 error:

1) ActualTest::testGetHomePage
PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete().
XHR ERROR: URL = http://10.48.77.48/ Response_Code = 404 Error_Message = Page Not Found.


/home/craiga/ombudsman/app/systemtests/ActualTest.php:16

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

我可以通过网络上任何位置的任何浏览器访问该网站,无需任何 问题,但由于某种原因,Selenium 启动的浏览器不能。 无论我从虚拟机启动测试还是会出现此错误 或Mac。

我可以进行以下测试来连接到 Google,没有任何问题:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class VanitySearchTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://www.google.com.au/");
        $this->setHost('192.168.101.1'); // IP of my Mac
    }

    public function testSearchForSelf()
    {
        $this->open("/");
        $this->type("q", "craig anderson");
        $this->click("btnG");
        $this->waitForPageToLoad("30000");
        try {
                $this->assertTrue($this->isTextPresent("craiga.id.au"));
        } catch (PHPUnit_Framework_AssertionFailedError $e) {
                array_push($this->verificationErrors, $e->toString());
        }
    }
}

此测试连接到我的 Mac 的默认页面,也通过了 没有任何问题:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class MacTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://192.168.101.1/");
        $this->setHost('192.168.101.1'); // IP of my Mac
    }

    public function testMacHomePage()
    {
        $this->open("/");
        try {
                $this->assertTrue($this->isTextPresent("It works!"));
        } catch (PHPUnit_Framework_AssertionFailedError $e) {
                array_push($this->verificationErrors, $e->toString());
        }
    }
}

有谁知道为什么会发生这种情况?我很高兴 提供有关我的设置的任何信息。我正在使用硒 服务器 1.0.3,以及来自 pear 的最新 phpunit。

I'm having trouble getting Selenium to see sites hosted on a virtual
machine. The following test causes an error, and I have no idea why:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class ActualTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://10.48.77.48/"); // IP of virtual machine
        $this->setHost('192.168.101.1'); // IP of my Mac
    }

    public function testGetHomePage()
    {
        $this->open("/", true);
    }
}

It returns the following error message, indicating that it couldn't
find the virtual machine:

$ phpunit ActualTest.php
PHPUnit 3.5.6 by Sebastian Bergmann.

E

Time: 7 seconds, Memory: 6.75Mb

There was 1 error:

1) ActualTest::testGetHomePage
PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete().
XHR ERROR: URL = http://10.48.77.48/ Response_Code = 404 Error_Message = Page Not Found.


/home/craiga/ombudsman/app/systemtests/ActualTest.php:16

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

I can access this site any browser anywhere on the network without any
problem, but for some reason the browser launched by Selenium can't.
This error occurs whether I launch the test from the virtual machine
or the Mac.

I can get the following test to connect to Google without any problem:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class VanitySearchTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://www.google.com.au/");
        $this->setHost('192.168.101.1'); // IP of my Mac
    }

    public function testSearchForSelf()
    {
        $this->open("/");
        $this->type("q", "craig anderson");
        $this->click("btnG");
        $this->waitForPageToLoad("30000");
        try {
                $this->assertTrue($this->isTextPresent("craiga.id.au"));
        } catch (PHPUnit_Framework_AssertionFailedError $e) {
                array_push($this->verificationErrors, $e->toString());
        }
    }
}

This test, which connects to my Mac's default page, also passes
without any problems:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class MacTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser("*firefox");
        $this->setBrowserUrl("http://192.168.101.1/");
        $this->setHost('192.168.101.1'); // IP of my Mac
    }

    public function testMacHomePage()
    {
        $this->open("/");
        try {
                $this->assertTrue($this->isTextPresent("It works!"));
        } catch (PHPUnit_Framework_AssertionFailedError $e) {
                array_push($this->verificationErrors, $e->toString());
        }
    }
}

Does anyone have any idea why this might be happening? I'm happy to
provide whatever information I can about my setup. I'm using Selenium
Server 1.0.3, and the latest phpunit from pear.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挖鼻大婶 2024-10-15 17:48:33

从下面一行删除一个 http

$this->setBrowserUrl("http://http://10.48.77.48/"); // IP of virtual machine

并尝试...让我知道它是否有效

Remove one http from below line

$this->setBrowserUrl("http://http://10.48.77.48/"); // IP of virtual machine

and try...Let me know if it works

把人绕傻吧 2024-10-15 17:48:33

尝试删除尾部斜杠,

$this->setBrowserUrl("http://10.48.77.48/")

因此它看起来像:

$this->setBrowserUrl("http://10.48.77.48")

我有时在设置浏览器 URL 时遇到尾部斜杠问题。

如果这不起作用,我的另一个想法是 Selenium 在开始测试之前对服务器执行 ping 操作,看看它是否启动。它出现问题,因为它尝试 ping http://10.48.77.48/ 但不起作用。确保您能够从您的计算机上 ping 通该地址。

Try removing the trailing slash from

$this->setBrowserUrl("http://10.48.77.48/")

So it would look like:

$this->setBrowserUrl("http://10.48.77.48")

I sometimes have issues with trailing slashes when setting up the browser url.

If that doesn't work, the other idea I have is that Selenium pings the server before it starts the test to see if it's up. It's having issues because it's trying to ping http://10.48.77.48/ and it's not working. Make sure you are able to ping that from your machine.

余罪 2024-10-15 17:48:33

解决了。我的应用程序未正确响应 HEAD 请求。要测试您的应用程序,请运行以下命令:

curl --head http://10.48.77.48/

如果它返回 404,则您的应用程序可能未正确处理 HEAD 请求。

Solved. My application wasn't responding correctly to HEAD requests. To test your application, run the following:

curl --head http://10.48.77.48/

If it returns a 404, your application probably isn't handling HEAD requests properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文