
나는 클라이언트에서 서버의 브라우저를 자동화하기 위해 Selenium을 사용하고 있지만 서버가 시작 시 자동으로 Selenium을 실행하기를 원합니다.
/etc/init에 3개의 파일이 있습니다:
프록시서버.conf:
respawn
start on runlevel [23]
script
exec java -jar selenium-server-standalone-2.20.0.jar -role hub -port 1111
end script
프록시서버2.conf그리고프록시서버3.conf이는 동일하며 "스크립트"의 내용만 변경합니다.
exec java -Dwebdriver.chrome.driver=/home/marco/selenium-client/chromedriver -jar selenium-server-standalone-2.20.0.jar -role node -port 2222 -hub http://192.168.1.12:1111 -browserName=chrome,maxInstances=5
이 방법으로 시작할 때 이 명령을 실행하면 클라이언트에서 Selenium을 실행할 때 다음 오류가 발생합니다.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
하지만 /etc/init에서 사용하는 것과 동일한 명령을 터미널에서 실행하면 모든 것이 완벽하게 작동합니다. 왜죠?!
마지막으로 실행하면 다음과 같습니다.
ps aux | grep selenium
서버가 시작 시 스크립트를 실행하면 다음이 제공됩니다.
root 746 0.0 12.1 677080 124468 ? Ssl Apr23 8:10 java -Dwebdriver...
root 749 0.0 12.7 685552 130280 ? Ssl Apr23 8.09 java -Dwebdriver...
root 755 0.0 1.9 680168 20240 ? Ssl Apr23 8.08 java -jar selenium...
터미널에서 실행하면 다음이 표시됩니다.
1000 9764 6.6 3.0 679236 30992 pts/0 Sl+ 10.33 0:01 java -jar...
1000 9783 14.0 3.0 677112 31752 pts/1 Sl+ 10.33 0:01 java -Dwebdriver...
1000 9792 12.6 3.0 675472 30944 pts/2 Sl+ 10.34 0:01 java -Dwebdriver...
왜 작동하지 않습니까?
감사해요!!
답변1
어쩌면 init에서 생성된 프로세스에는 터미널에서 실행할 때 가지고 있는 일부 환경 변수가 누락되었을 수 있습니다( DISPLAY
Selenium이 브라우저 창을 여는 디스플레이에서 알아야 하는 변수입니다).
이것을 초기화 스크립트에 넣어보세요:
env DISPLAY=:0.0
자세한 내용은 다음을 참조하세요.신생 요리책.