2017-07-03 30 views
0

我正在努力從Docker鏡像運行我的黃瓜測試。如何在Docker中運行cucumber/selenium測試?

這裏是我的設置:

  1. 我使用OSX與XQuartz運行的X11會議
  2. 我用發展的Ubuntu的14放浪形象在我轉發我的X11會議
  3. 我想運行與Firefox碼頭工人形象,將用我XQuartz會話顯示

到目前爲止,我設法用下面的設置啓動Firefox:

# Dockerfile 
FROM ubuntu:14.04 

RUN apt-get update && apt-get install -y firefox 

# Replace 1000 with something appropriate ;) 
RUN export uid=1000 gid=1000 && \ 
    mkdir -p /home/developer && \ 
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/dev:/bin/bash" >> /etc/passwd && \ 
    echo "developer:x:${uid}:" >> /etc/group && \ 
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \ 
    chmod 0440 /etc/sudoers.d/developer && \ 
    chown ${uid}:${gid} -R /home/developer 

USER developer 
ENV HOME /home/developer 
CMD /usr/bin/firefox 

我可以--net=host從我的流浪機啓動Firefox:

docker build -t firefox . 
docker run --net=host -ti --rm -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:rw firefox:latest 

但因爲我不能在泊塢窗,compose.yml文件等容器鏈接到我的機器,這是不理想的。理想情況下,我想沒有--net=host運行我的泊塢窗機是這樣的:

docker build -t firefox . 
docker run -ti --rm -e DISPLAY=$DISPLAY -v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:rw firefox:latest 

,但我得到了以下錯誤:

error: XDG_RUNTIME_DIR not set in the environment. 
Error: cannot open display: localhost:10.0 

請幫助:)

+0

你特別努力,因爲你想看到的測試或者使用X11你打開一些像Xvfb這樣的容器,你不需要X11服務器就可以運行虛擬幀緩衝區?我問,因爲我使用官方Selenium鏡像https://hub.docker.com/r/selenium/在Selenium Hub上使用Selenium Hub在Firefox和Chrome中運行Selenium測試,它運行良好。 –

+0

是的,我不使用xvfb的主要原因是因爲我想查看和調試我的測試。 Xvfb非常適合CI。 –

回答

0

你可以簡單地使用elgalu/docker-selenium來避免處理已經解決的問題,並保留:

docker run --rm -ti --net=host --pid=host --name=grid \ 
    -e SELENIUM_HUB_PORT=4444 -e TZ="US/Pacific" \ 
    -v /dev/shm:/dev/shm --privileged elgalu/selenium 

如果你需要一個像具有視頻錄製,例如,或實時預覽儀表板的高級功能,您可以使用Zalenium,並啓動它:

curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | bash -s start -i 
+0

我如何使用它來運行我的黃瓜測試? –

+0

當然,這些是安裝了Firefox和Chrome的硒服務器。 –