2011-07-06 8 views
12

Selenium을 사용하여 테스트가 아닌 몇 가지 웹 작업을 자동화하고 싶습니다. Selenium RC Server가 설치되어 있다고 생각하지만 PHP로 클라이언트 드라이버를 찾을 수 없으므로 "테스트 스크립트"를 작성할 방법이 없습니다 (http://seleniumhq.org/download/ 참조).Selenium을 PHP와 함께 사용하는 방법?

PHP로 Selenium을 사용하는 방법이 있습니까? 이것은 PHPUnit http://www.phpunit.de/manual/current/en/selenium.html이 필요하다고 제안하는 것 같습니다. 난 그냥 몇 가지 작업을 자동화하고, 테스트의 전체 제품군에 참여하지 싶습니다.

답변

11

는 다음과 같은 일

  1. 을 시도 얻을 셀레늄 PHP 클라이언트 드라이버 링크를 http://mvnrepository.com/artifact/org.seleniumhq.selenium.client-drivers

    를 클릭하세요 phpunit을 설치하고

  2. 작업 또한 PC에 Java sdk &을 설치하십시오.
  3. 이제 셀레늄 IDE를 사용하여 테스트 사례를 기록하십시오.
  4. 테스트 케이스를 PHP 파일로 내 보냅니다.
  5. 이러한 내 보낸 함수를 사용하면 테스트 사례 라이브러리를 만들 수 있습니다.
  6. 라이브러리에서 함수/테스트를 호출하는 제품군을 만듭니다.
  7. java 명령을 사용하여 Selenium Server를 시작하십시오.
  8. phpunit 사용하기 스위트를 실행하십시오.

에 refrence 위해 작성하는 방법이 파일은 here을 클릭하고 또한 당신은 셀레늄 서버를 실행하고 그것과 상호 작용하는 웹 드라이버 라이브러리를 필요로 자식 허브

+1

[php-webdriver] (https://github.com/facebook/php-webdriver) 라이브러리만으로도 충분하며 [Steward] (https://github.com)와 같은 도구를 사용하면 설정이 훨씬 쉬워집니다./lmc-eu/steward). Selenium IDE로 시간을 낭비하지 말고 PHP에서 원하는 시나리오를 작성하는 것이 좋습니다. –

0

이 링크를 확인하십시오 : 바이너리

+0

그것은 JAR 파일의 대한 기능을 추가합니다. PHP로 어떻게 작동하게합니까? – StackOverflowNewbie

+0

셀레늄에 항아리를 설치하십시오 ... –

+1

마크 - 저는 보통 자바에서는 작동하지 않으므로이 JAR 바이너리에 대해 다소 혼란 스럽습니다. 이 JAR을 Selenium에 어떻게 설치합니까? 그렇다면 PHP에서 Selenese 스크립트를 실행하려면 어떻게해야합니까? – StackOverflowNewbie

1

에보십시오.

공식적으로 셀레늄은 PHP를 지원하지 않지만 Nearsoft에서는 Json Wire Protocol과 상호 작용할 라이브러리를 만들었습니다. 우리는 공식 사이트의 다른 언어 및 드라이버의 예제와 가능한 비슷하게 만들려고했기 때문에 Java 페이지의 예제는 PHP에서 매우 유사한 구문을 갖습니다.

를 체크 아웃 : 당신이 그것을 좋아하는 경우에 https://github.com/Nearsoft/PHP-SeleniumClient

, 공유, 참여, 그것을 포크 또는 당신으로하십시오 할.

감사합니다.

12

facebook/php-webdriver은 셀레늄과 PHP를위한 멋진 클라이언트입니다.

웹 작업 (OP가 원하는대로)을 자동화하거나 php-webdriver를 테스트 프레임 워크에 통합 할 수 있습니다.

  • StewardPHPUnit에 직접 PHP - webdriver을 통합 : 이미이 제공하는 몇 가지 프로젝트가있다.
  • Codeception 테스트 프레임 워크는 php-webdriver 위에 BDD 계층을 제공합니다.
  • 맞춤 PHPUnit 통합을 설명하는 blogpost + demo project을 확인할 수도 있습니다.

모두에게

  1. 다운로드를 설치하고 facebook/php-webdriver를 설치합니다. composer require facebook/webdriver

  2. Download Selenium & 시작하십시오. java -jar selenium-server-standalone-#.jar

  3. Download Quick Java 프로젝트 디렉토리에 배치하십시오.


이 예에서 사용

, 우리는 javascriptcookies를 제외하고 모든 것을 해제하는 확장 quickjava를 사용합니다. 여기

더보기 기본 설정 :
https://github.com/ThatOneGuyDotNet/QuickJava/blob/master/defaults/preferences/defaults.js

더보기 예를 여기 명령은 :
https://github.com/facebook/php-webdriver/wiki/Example-command-reference

use Facebook\WebDriver\Firefox\FirefoxProfile; 
use Facebook\WebDriver\Firefox\FirefoxDriver; 
use Facebook\WebDriver\Remote\DesiredCapabilities; 
use Facebook\WebDriver\Remote\RemoteWebDriver; 

// Change this to the path of you xpi 
$extensionPath = $this->container->getParameter('kernel.root_dir').'/../bin/selenium/quickjava-2.0.6-fx.xpi'; 

// Build our firefox profile 
$profile = new FirefoxProfile(); 
$profile->addExtension($extensionPath); 
$profile->setPreference('thatoneguydotnet.QuickJava.curVersion', '2.0.6.1'); 
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Images', 2); 
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.AnimatedImage', 2); 
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.CSS', 2); 
//$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Cookies', 2); 
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Flash', 2); 
$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.Java', 2); 
//$profile->setPreference('thatoneguydotnet.QuickJava.startupStatus.JavaScript', 2); 
$profile->setPreference("thatoneguydotnet.QuickJava.startupStatus.Silverlight", 2); 

// Create DC + Driver 
$dc = DesiredCapabilities::firefox(); 
$dc->setCapability(FirefoxDriver::PROFILE, $profile); 

$driver = RemoteWebDriver::create($host, $dc); 
$driver->get('http://stackoverflow.com'); 

// Do stuff - https://github.com/facebook/php-webdriver/wiki/Example-command-reference 
//$driver->findElement(WebDriverBy::id("element-id")); 

// The HTML Source code 
$html = $driver->getPageSource(); 

// Firefox should be open and you can see no images or css was loaded 
관련 문제