2008-10-03 41 views
6

Tôi đang cố gắng để có được Selenium RC làm việc với Firefox 3 trên Linux với PHP/Apache nhưng tôi đang gặp sự cố. Dưới đây là những gì tôi đã thực hiện:Làm thế nào để có được Selenium làm việc với PHP/Firefox3 trên Linux

  • Tôi đã cài đặt phần mở rộng Firefox Selenium-IDE.
  • Trên máy chủ web (trong trường hợp của tôi thực sự là cùng một máy chạy Firefox), tôi đã khởi động máy chủ Selen với: java -jar selenium-server.jar -interactive
  • Tôi có một tập lệnh PHP như sau :

PHP:

require_once 'Testing/Selenium.php'; 

$browser = new Testing_Selenium("*custom /usr/lib/firefox-3.0.3/firefox", "https://www.example.com"); 
$browser->start(); 

Khi tôi chạy kịch bản PHP, nó khởi động một tab Firefox mới, nhưng tôi nhận được thông báo lỗi này:

The requested URL /selenium-server/core/RemoteRunner.html was not found on this server. 

Tôi đã thành công hơn với Firefox 2 (bằng cách sử dụng "*firefox" thay vì "*custom" nhưng không muốn sử dụng nó cho dự án hiện tại của mình.

Trả lời

12

Tôi không chắc chắn về các nghi thức trả lời câu hỏi của riêng bạn ... nhưng đã thử nghiệm một cách thử và sai, đây là cách tôi quản lý để có được Selenium làm việc với PHP/Firefox3 trên Ubuntu.

  1. tôi tải RC và sao chép vào thư mục client php đến/usr/share/php như 'Selenium'
  2. tôi điều hướng đến thư mục Selenium Server trong việc tải xuống, và bắt đầu selen với java -jar selenium-server.jar
  3. tôi đã tạo một hồ sơ Firefox mới (bằng cách chạy firefox -ProfileManager). Tôi gọi là hồ sơ mới 'Selenium'
  4. Trong hồ sơ đó, tôi chỉnh sửa các ưu đãi Firefox Mạng để proxy tất cả các giao thức thông qua cổng localhost 4444.
  5. Tôi tạo ra kịch bản php của tôi và chạy nó với lệnh này:

    php -d include_path=".:/usr/share/php:/usr/share/php/Selenium/PEAR" test.php

Tôi đã liệt kê tập lệnh thử nghiệm đầu tiên (cơ bản, không phải PHPUnit, không phải OO) bên dưới để tham khảo.

require_once 'Testing/Selenium.php'; 

$oSelenium = new Testing_Selenium(
    "*custom /usr/lib/firefox-3.0.3/firefox -P Selenium", 
    "https://www.example.com"); 
$oSelenium->start(); 

$oSelenium->open("/"); 

if (!$oSelenium->isElementPresent("id=login_button")) { 
     $oSelenium->click("logout"); 
     $oSelenium->waitForPageToLoad(10000); 
     if (!$oSelenium->isElementPresent("id=login_button")) { 
       echo "Failed to log out\n\n"; 
       exit; 
     } 
} 

$oSelenium->type("login", "my_username"); 
$oSelenium->type("password", "my_password"); 
$oSelenium->click("login_button"); 
$oSelenium->waitForPageToLoad(10000); 

$oSelenium->click("top_nav_campaigns"); 

$oSelenium->stop(); 
1

Tôi sử dụng phpunit, selenium RC php api để chạy testcases của tôi. testcase của tôi trông giống như



[email protected]~/selenium/ide_scripts$ 
cat mytest.php 
'FF on linux', 
     'browser' => '*firefox', 
     'host' => '10.211.55.8', 
     'port' => 4444, 
     'timeout' => 30000, 
    ), 
    array(
     'name' => 'FF on windows', 
     'browser' => '*firefox', 
     'host' => '10.211.55.5', 
     'port' => 4444, 
     'timeout' => 30000, 
    ), 
    */ 
    array(
     'name' => 'Google Chrome on windows', 
     'browser' => '*googlechrome', 
     'host' => '10.211.55.5', 
     'port' => 4444, 
     'timeout' => 30000, 
    ), 
    /* 
    array(
     'name' => 'IE on windows', 
     'browser' => '*iexplore', 
     'host' => '10.211.55.5', 
     'port' => 4444, 
     'timeout' => 30000, 
    ), 
    array(
     'name' => 'Safari on MacOS X', 
     'browser' => '*safari', 
     'host' => 'localhost', 
     'port' => 4444, 
     'timeout' => 30000, 
    ), 
    array(
     'name' => 'Firefox on MacOS X', 
     'browser' => '*chrome', 
     'host' => 'localhost', 
     'port' => 4444, 
     'timeout' => 30000, 
    ), 
    */ 
    array(
     'name' => 'Google Chrome on MacOS X', 
     'browser' => '*googlechrome', 
     'host' => 'localhost', 
     'port' => 4444, 
     'timeout' => 30000, 
    ) 
); 

    protected function setUp() 
    { 
    //$this->setBrowser("*chrome"); 
    $this->setBrowserUrl("http://www.facebook.com/"); 
    } 

    public function testMyTestCase() 
    { 
    $this->open("/index.php?lh=94730c649368393b6954cb9fc0802e0a&eu=iKjrC7Q2aC-8tcU7PVLilg"); 
    $this->type("email", "[email protected]"); 
    $this->type("pass", "mypassword"); 
    $this->click("persistent"); 
    $this->click("//input[@type='submit']"); 
    $this->waitForPageToLoad("30000"); 
    sleep(10); 
    $this->open("http://apps.facebook.com/myapp/"); 
    sleep(4); 
    $this->click("link=Play"); 
    $this->waitForPageToLoad("30000"); 
    sleep(4); 
    $this->click("navAccountLink"); 
    sleep(4); 
    $this->click("link=Logout"); 
    $this->waitForPageToLoad("30000"); 
    sleep(4); 
    } 
} 
?> 
[email protected]~/selenium/ide_scripts$ 
phpunit mytest.php 

này sẽ kết nối với các trình duyệt chạy bên trong máy ảo

Các vấn đề liên quan