2013-05-19 2 views
3

* nux 상자에서 Fabric에서 배포 한 후 몇 가지 브라우저 자동화 작업을 실행하기 위해 Win2k8 EC2 인스턴스를 실행하고 있습니다. Mac 및 Linux에서 작동cygwin에서 Selenium Webdriver가 Firefox 경로를 찾도록 허용하고 표준 설치를

내 스크립트 Cygwin에서 파이썬 Cygwin에서 아래에 다음과 같은 오류를 제공합니다 :

File "/home/Myuser/.virtualenvs/myproject/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 141, in _get_firefox_start_cmd 
    " Please specify the firefox binary location or install firefox") 
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox 

Cygwin에서 (selenium)에서 Webdriver 지원에 대한 관심이 알려진 버그/부족이있다.

동료

는 SO 사용자가 더 도움이 여기 해결책이 있습니다 https://stackoverflow.com/a/11104952/1668057

을가 맥/* nix에서 스크립트에서 내 코드를 깰 것 같은 방법이 보인다.

어떻게 구현하고 코드를 이식성있게 유지할 수 있습니까?

(내 셀레늄은 PIP에서 설치되기 때문에 모든 모듈 파일을 편집보다 메소드를 오버라이드 (override)하는 것을 선호)

편집 : 더 파이썬 방법은 제프의 대답에 제안보고

를, 내가 와서 다음 (해제 이미지에 대한주의 내 스크립트가 이미 서브 클래스/오버라이드 FirefoxProfile 클래스)로 : 일에 내 맥에

from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile 
from subprocess import Popen, PIPE 

class CygwinFirefoxProfile(FirefoxProfile): 

    @property 
    def path(self): 

     path = self.profile_dir 

     try: 
      proc = Popen(['cygpath','-d',path], stdout=PIPE, stderr=PIPE) 
      stdout, stderr = proc.communicate() 
      path = stdout.split('\n', 1)[0] 
      print("cygwin path found") 

     except OSError: 
      print("No cygwin path found") 

     return path 

class CarServiceOnlineBookingsTest(unittest.TestCase):  

    def setUp(self): 

     firefoxProfile = CygwinFirefoxProfile() 

     ## Disable CSS 
     firefoxProfile.set_preference('permissions.default.stylesheet', 2) 
     ## Disable images 
     firefoxProfile.set_preference('permissions.default.image', 2) 
     ## Disable Flash 
     firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false') 

     self.driver = webdriver.Firefox(firefoxProfile) 

이 이제 예외를 catch 정상적으로 계속되지만 Cygwin에서 경로가 감지 전자 Win2k8 상자, 여전히 다음과 같은 오류와 함께 실패합니다

Traceback (most recent call last): 
    File "myscript.py", line 45, in setUp 
    self.driver = webdriver.Firefox(firefoxProfile) 
    File "/home/Myuser/.virtualenvs/myenv/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 50, in __init__ 
    self.binary = FirefoxBinary() 
    File "/home/Myuser/.virtualenvs/myenv/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 33, in __init__ 
    self._start_cmd = self._get_firefox_start_cmd() 
    File "/home/Myuser/.virtualenvs/myenv/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 141, in _get_firefox_start_cmd 
    " Please specify the firefox binary location or install firefox") 
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox 

나는 모두는 popen에 익숙하지 않은거야 아니면 내가 긍정적 인 결과를 반환 기대하고있어. 예 : C:\Program Files (x86)\Firefox\Firefox.exe과 같은 것을 사용해야합니까?

다음 디버그 단계는 어디에 있습니까?

편집 # 2 :

Cygwin에서 bash 쉘에서이 명령을 실행 오픈 파이어 폭스를 수행합니다

/cygdrive/c/Program\ Files\ \(x86\)/Mozilla\ Firefox/firefox.exe

나는 나의 다음 단계는 스크립트에이 하드 코딩하고 있는지 생각 Selenium이 cygwin bash를 통해 로컬로 또는 Firefox를 통해 원격으로 SSH를 통해 Firefox를 시작할 수있게 해줍니다. ...

답변

4

OK, e PATH 변수를 Win2k8 cygwin에서 사용하면 Jeff의 답변 코드가 작동하고 원격 Linux 컴퓨터를 통해 Win2k8 컴퓨터에서 Firefox를 행복하게 실행할 수 있습니다.

내가 수동으로이 바람을 피우고 생각 경로를 설정하지 않은,하지만 난 완전 자동화를 원하는 경우 심지어는 패브릭 스크립트의 일부로 수행 할 수 있습니다

... 여기

지금 노력하고 코드입니다 Mac 및 Windows에서 모두 정상적으로 작동합니다.

from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile 
from subprocess import Popen, PIPE 

class CygwinFirefoxProfile(FirefoxProfile): 

    @property 
    def path(self): 

     path = self.profile_dir 

     # cygwin requires to manually specify Firefox path a below: 
     # PATH=/cygdrive/c/Program\ Files\ \(x86\)/Mozilla\ Firefox/:$PATH 
     try: 
      proc = Popen(['cygpath','-d',path], stdout=PIPE, stderr=PIPE) 
      stdout, stderr = proc.communicate() 
      path = stdout.split('\n', 1)[0] 

     except OSError: 
      print("No cygwin path found") 

     return path 

class CarServiceOnlineBookingsTest(unittest.TestCase):  

    def setUp(self): 

     firefoxProfile = CygwinFirefoxProfile() 

     ## Disable CSS 
     firefoxProfile.set_preference('permissions.default.stylesheet', 2) 
     ## Disable images 
     firefoxProfile.set_preference('permissions.default.image', 2) 
     ## Disable Flash 
     firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false') 

     self.driver = webdriver.Firefox(firefoxProfile) 

그런 여행이 도움이되기를 바랍니다.

관련 문제