I have a Django project that we are running Selenium UI tests for. I have the tests running locally in Docker, but the same tests are failing when run through BitBucket Pipelines.
The relevant portion of the Pipeline config looks like this:
image: python:2
pipelines:
default:
- step:
caches:
- pip
script: # Modify the commands below to build your repository.
- echo "Simple changes kick off pipelines!"
branches:
chrome-headless-bitbucket:
- step:
caches:
- pip
script:
- apt-get update
- apt-get install -y libxss1 libappindicator1 libindicator7 libxi6 libgconf-2-4
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- dpkg -i google-chrome*.deb || true
- apt-get install -f -y
- apt-get install -y xvfb unzip
- wget -N https://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip && chmod +x chromedriver
- mv -f chromedriver /usr/local/share/chromedriver
- ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
- ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
- pip install pyvirtualdisplay selenium
- cd tsmartweb && pip install -r requirements.txt && pip install -r requirements-dev.txt
- pytest
And the corresponding Dockerfile looks like this:
FROM python:2
RUN apt-get update
RUN apt-get install -y libxss1 libappindicator1 libindicator7 libxi6 libgconf-2-4 xvfb unzip
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome*.deb || true
RUN apt-get install -f -y
RUN wget -N https://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip
RUN chmod +x chromedriver
RUN mv -f chromedriver /usr/local/share/chromedriver
RUN ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
RUN ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
RUN pip install pyvirtualdisplay selenium
RUN mkdir -p /usr/local/src/
ADD . /usr/local/src/
RUN cd /usr/local/src/projectName/ && pip install -r requirements.txt
RUN cd /usr/local/src/projectName/ && pip install -r requirements-dev.txt
CMD ["pytest"]
To test I've been building the image, and running it with this command:
docker run -t -i --volume=/Users/username/.aws:/root/.aws --memory=4g --memory-swap=4g --memory-swappiness=0 --workdir="/usr/local/src/projectName" 4aec08b23718 pytest
Most of my tests pass locally, but none pass in Bitbucket. I'm getting this error in the console:
<span>response = {'sessionId': 'd30ab389776d7ad689bbaa055f460cbf', 'status': 7, 'value': {'message': 'no such element: Unable to locate...9.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.19.23-coreos-r1 x86_64)'}}</span>
...
<span>> raise exception_class(message, screen, stacktrace)</span><span>E NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"navbar-username"}</span><span>E (Session info: headless chrome=74.0.3729.131)</span><span>E (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.19.23-coreos-r1 x86_64)</span><span>self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f595777c410></span>
Why would tests pass in my local Docker environment, but not in Pipelines?
- macOS version 10.14.4 (18E226)
- Docker version 18.09.2, build 6247962