2011-09-07 2 views
9

Selenium2는 기본적으로 새로운 프로파일로 firefox를 시작합니다. 기본 설정이 마음에 들지만, 내 기본 설정으로 시작하고 싶은 좋은 이유 (내 북마크에 액세스, 저장된 비밀번호, 부가 기능 사용 등)가 있습니다.Selenium2 firefox : 기본 프로파일 사용

속성을 제어하는 ​​속성이 supposed to be인데, 문서가 소스와 동기화되지 않았기 때문에 내가 말할 수있는 한 webdriver.firefox.bin 만 작동한다는 것입니다. 예 : 셀렌을 시작하는 경우 :

java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin=not-there 

(즉 불평). 그러나 이것은 효과가 없습니다 :

java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.profile=default 

("기본값은"profiles.ini에있는 이름이지만, 나는 또한 profiles.ini에서 섹션의 이름입니다 "Profile0"로 시도했습니다).

I는 액세스 (JsonWireProtocol를 사용하는) PHPWebdriver가 사용하고

$webdriver = new WebDriver("localhost", "4444"); 

$webdriver->connect("firefox"); 
I은 ​​PHP 측에서 일을 시도

:

$webdriver->connect("firefox","",array('profile'=>'default')); 

또는 :

$webdriver->connect("firefox","",array('profile'=>'Profile0')); 

와 성공하지 못했습니다 (파이어 폭스가 시작되지만 내 프로필을 사용하지 않음). 와 셀레늄을

#!/bin/bash 
/usr/bin/firefox -P default 

그리고 시작 :

가 나는 또한 배치 파일을 만드는 해커의 접근 시도 자바 -jar 셀레늄 서버 독립-2.5.0.jar -Dwebdriver.firefox.bin = "/ usr/local/src/selenium/myfirefox"

Firefox는 시작되지만 기본적으로 프로필을 사용하지 않으며, 모든 상황이 중단됩니다. 이렇게 시작하면 셀레늄이 firefox와 통신 할 수없는 것처럼 보입니다.

P. 나는 Selenium - Custom Firefox profile을 보았다 :

java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate "not-there" 

그리고 그것은 달리지 않는다! 흥분, 내가 뭔가있을 수 있다고 생각, 나는 시도 :

java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate /path/to/0abczyxw.default/ 

이것은 아무것도하지 않는다. 나는. 여전히 여기

답변

8

Simon Stewart answered this on the mailing list 나를 위해.

그의 대답을 요약하면 : 당신이 당신의 파이어 폭스 프로필을, (우편,하지 TGZ) 그것을 압축, base64로 인코딩 그것은 다음의 (a /session json request으로 모든 일을 보내는 기능의 firefox_profile 키에 base64로 문자열을 넣어 목적). 리눅스에서이 작업을 수행하는

예 방법 : 다음

cd /your/profile 
zip -r profile * 
base64 profile.zip > profile.zip.b64 

그리고 할 일 연결할 때 PHPWebDriver를 사용하는 경우 :

$webdriver->connect("firefox", "", array("firefox_profile" => file_get_contents("/your/profile/profile.zip.b64"))) 

참고 : 아직하지 않습니다 내 실제 프로필, 오히려 그것을 복사하십시오. 따라서 북마크는 기억되지 않으며 캐시가 채워지지 않습니다.

+0

정말 고맙습니다. 프로필을 압축 한 다음 base64로 인코딩하는 PHP 코드가 제공되어 PHP에서 모든 것을 수행 할 수 있다면 좋을 것입니다. – David

+0

이미 명시된 것을 재확인하십시오 ... 이것은 갈 길입니다. 우리가 프록시를 통해 모든 셀레늄 요청을 처리하기를 원할 때 완벽하게 작동했습니다. –

5

:-(새 프로필로 시작되는 자바 해당. 나는

ProfilesIni profile = new ProfilesIni(); 
FirefoxProfile ffprofile = profile.getProfile("default"); 
WebDriver driver = new FirefoxDriver(ffprofile); 

. 가능 비슷한는 PHP에서이 확신이위한 추가적인 확장하려는 경우이 같은 작업을 수행 할 수 있습니다 뿐만 아니라.

ProfilesIni profile = new ProfilesIni(); 
FirefoxProfile ffprofile = profile.getProfile("default"); 
ffprofile.addExtension(new File("path/to/my/firebug.xpi")); 
WebDriver driver = new FirefoxDriver(ffprofile); 
+0

감사합니다. @nilesh. 이것이 WebDriver를 직접 사용하고 있다고 생각하는 것이 맞습니다. 당신은'selenium-server-standalone.jar'을 시작하지 않으므로 JsonWireProtocol을 사용하지 않을 것입니다. –

+0

이것은 webdriver를 직접 사용하고 있습니다. 독립 실행 형 항아리에서 시작하여 무슨 뜻인지 모르겠습니다. WebDriver 자체는 JsonWireProtocol을 사용하여 http://code.google.com/p/selenium/wiki/JsonWireProtocol – nilesh

+0

아, 흥미 롭습니다. 그래서 위의 자바 코드는 어떻게 든 JSON과 웹 서비스 호출로 변환 될까요? 그 호출이 무엇인지 추적 할 수 있다면 PHP 라이브러리에서 구현할 수 있습니다. 하지만 그것이하는 일은 당신이 준 URL에 문서화되어 있지 않으며, JsonWireProtocol에 대한 다른 문서를 보지 못했습니다. Selenium 개발자들과 연락을 취할 것입니다. –

1

나는 일이 매우 간단에 내가 가진 무엇도이에 대한 호기심이었다. 나는 내가 사용하는 사용하는 데 필요한 프로파일을 발견 한 나는. 프로필 관리자를 불러옵니다 명령 /Applications/Firefox.app/Contents/MacOS/firefox-bin -P을 사용 다음의 코드 t o browser = Selenium::WebDriver.for :firefox, :profile => "batman" 프로파일을 활성화하십시오.

이렇게하면 해당 프로필과 관련된 모든 북마크와 플러그인이 표시됩니다.

희망이 도움이됩니다.

+0

감사합니다. @ Curtis. 그 명령은 어떤 언어/도서관인가? –

+0

@Darren : 언어는 루비로되어 있습니다. 그러나 PHP에 상응하는 것이 있다고 확신합니다. –

1

-Dwebdriver.firefox.profile=<name> 명령 줄 매개 변수를 사용할 수 없다는 점은 유스 케이스에서는 고려되지 않았기 때문에 현재 코드 디자인의 동일한 문제가 발생하여 새 세션이 생성 될 때마다 프로필 디렉토리를 업로드하고 싶지 않았기 때문에 this patch을 구현했습니다. 새로운 firefox_profile_name 매개 변수가 도입되어 JSON 기능에서 특정 Firefox 프로필을 대상으로 지정할 수 있습니다. 원격 서버. 희망이 도움이됩니다.

+0

Great @ Stéphane - 내가 패치를 이해했다면, 그게 바로 내가 한 것입니다.아직 테스트하지는 않았지만 안전합니까? (즉, 깔끔한 단계에서 셀레늄은 생성 된 임시 프로필 디렉토리를 삭제합니다. 그런 일을 막기 위해 명시적인 코드가 필요하지 않습니까?) –

+0

예, 안전합니다. Selenium은 실제로이 프로파일의 임시 사본을 만들어 템플릿과 같이 사용합니다. –

1

나는이 같은 젠드에서 그것을했다 :

public function indexAction(){ 
    $appdata = 'C:\Users\randomname\AppData\Roaming\Mozilla\Firefox' . "\\"; 
    $temp = 'C:\Temp\\'; 
    $hash = md5(rand(0, 999999999999999999)); 
    if(!isset($this->params['p'])){ 
     shell_exec("\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -CreateProfile " . $hash); 
    }else{ 
     $hash = $this->params['p']; 
    } 
    $ini = new Zend_Config_Ini('C:\Users\randomname\AppData\Roaming\Mozilla\Firefox\profiles.ini'); 
    $path = false; 
    foreach ($ini as $key => $value){ 
     if(isset($value->Name) && $value->Name == $hash){ 
      $path = $value->Path; 
      break; 
     } 
    } 
    if($path === false){ 
     die('<pre>No profile found with name: ' . $hash); 
    } 
    echo "<pre>Profile : $hash \nProfile Path : " . $appdata . "$path \n"; 
    echo "Files: \n"; 
    $filesAndDirs = $this->getAllFiles($appdata . $path); 
    $files = $filesAndDirs[0]; 
    foreach ($files as $file){ 
     echo " $file\n"; 
    } 
    echo "Dirs : \n"; 
    $dirs = array_reverse($filesAndDirs[1]); 
    foreach ($dirs as $dir){ 
     echo " $dir\n"; 
    } 
    echo 'Zipping : '; 
    $zip = new ZipArchive(); 
    $zipPath = md5($path) . ".temp.zip"; 
    $zipRet = $zip->open($temp .$zipPath, ZipArchive::CREATE); 
    echo ($zipRet === true)?"Succes\n":"Error $zipRet\n"; 
    echo "Zip name : $zipPath\n"; 
    foreach ($dirs as $dir){ 
     $zipRet = $zip->addEmptyDir($dir); 
     if(!($zipRet === true)){ 
      echo "Error creating folder: $dir\n"; 
     } 
    } 
    foreach ($files as $file){ 
     $zipRet = $zip->addFile($appdata . $path ."\\". $file,$file); 
     if(!($zipRet === true && file_exists($appdata . $path . "\\". $file) && is_readable($appdata . $path . "\\". $file))){ 
      echo "Error zipping file: $appdata$path/$file\n"; 
     } 
    } 
    $zipRet = $zip->addFile($appdata . $path ."\\prefs.js",'user.js'); 
    if(!($zipRet === true && file_exists($appdata . $path . "\\". $file) && is_readable($appdata . $path . "\\". $file))){ 
     echo "Error zipping file: $appdata$path/$file\n"; 
    } 
    $zipRet = $zip->close(); 
    echo "Closing zip : " . (($zipRet === true)?("Succes\n"):("Error:\n")); 
    if($zipRet !== true){ 
     var_dump($zipRet); 
    } 
    echo "Reading zip in string\n"; 
    $zipString = file_get_contents($temp .$zipPath); 
    echo "Encoding zip\n"; 
    $zipString = base64_encode($zipString); 
    echo $zipString . "\n"; 
    require 'webdriver.php'; 
    echo "Connecting Selenium\n"; 
    $webDriver = new WebDriver("localhost",'4444'); 
    if(!$webDriver->connect("firefox","",array('firefox_profile'=>$zipString)) 
{ 
     die('Selenium is not running'); 
    } 
} 
    private function getAllFiles($path,$WithPath = false){ 
    $return = array(); 
    $dirs = array(); 
    if (is_dir($path)) { 
     if ($dh = opendir($path)) { 
      while (($file = readdir($dh)) !== false) { 
       if(!in_array($file, array('.','..'))){ 
        if(is_dir($path . "\\" . $file)){ 
         $returned = $this->getAllFiles($path . "\\" . $file,(($WithPath==false)?'':$WithPath) . $file . "\\"); 
         $return = array_merge($return,$returned[0]); 
         $dirs = array_merge($dirs,$returned[1]); 
         $dirs[] = (($WithPath==false)?'':$WithPath) . $file; 
        }else{ 
         $return[] = (($WithPath==false)?'':$WithPath) . $file; 
        } 
       } 
      } 
      closedir($dh); 
     } 
    } 
    return array($return,$dirs); 
} 

아이디어는 당신이 GET/게시물에 제공한다는 것입니다/젠드이 아닌 임의 줘야 생성 할 경우 프로파일의 이름으로 P 매개 변수, 그는 모든 파일을 압축하여 임시 폴더에 넣고 넣으십시오.

5
java -jar selenium-server-standalone-2.21.0.jar -Dwebdriver.firefox.profile=default 

이 작동해야합니다. 버그는 fixed입니다.

셀렌 서버를 업데이트하십시오.

+0

위대한, 감사합니다 무하마드. 방금 작동했음을 확인했습니다. (BTW, 여전히 프로필의 _copy_이며 캐시/기록이 채워지지 않습니다.) –

+1

아, SSL 인증 및 dom.max_script_run_time과 같은 일부 속성을 저장하기 위해 사용합니다. –

관련 문제