doumuyu0837 2010-12-21 04:22
浏览 87
已采纳

为什么Selenium RC无法在虚拟机上看到网站

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.

  • 写回答

3条回答 默认 最新

  • dongtao9095 2010-12-23 03:22
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败