├── .gitignore ├── results └── .gitignore ├── robot ├── requirements.txt ├── Dockerfile └── tests │ ├── valid_login.robot │ ├── invalid_login.robot │ └── resource.robot ├── docker-compose.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | -------------------------------------------------------------------------------- /results/.gitignore: -------------------------------------------------------------------------------- 1 | ff/ 2 | gc/ 3 | -------------------------------------------------------------------------------- /robot/requirements.txt: -------------------------------------------------------------------------------- 1 | robotframework 2 | selenium 3 | robotframework-seleniumlibrary 4 | -------------------------------------------------------------------------------- /robot/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:alpine 2 | 3 | COPY requirements.txt /tmp/requirements.txt 4 | RUN pip install --upgrade pip 5 | RUN pip install -r /tmp/requirements.txt 6 | 7 | COPY tests /tests 8 | 9 | ENTRYPOINT [ "robot" ] 10 | -------------------------------------------------------------------------------- /robot/tests/valid_login.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Documentation A test suite with a single test for valid login. 3 | ... 4 | ... This test has a workflow that is created using keywords in 5 | ... the imported resource file. 6 | Resource resource.robot 7 | 8 | *** Test Cases *** 9 | Valid Login 10 | Open Browser To Login Page 11 | Input Username demo 12 | Input Password mode 13 | Submit Credentials 14 | Welcome Page Should Be Open 15 | [Teardown] Close Browser -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | demoapp: 5 | image: suonto/demoapp 6 | expose: 7 | - 7272 8 | networks: 9 | - selenium-grid 10 | 11 | hub: 12 | image: selenium/hub:latest 13 | expose: 14 | - 4444 15 | networks: 16 | - selenium-grid 17 | 18 | chrome: 19 | image: selenium/node-chrome-debug:latest 20 | environment: 21 | - HUB_PORT_4444_TCP_ADDR=hub 22 | - HUB_PORT_4444_TCP_PORT=4444 23 | ports: 24 | - 5900:5900 25 | depends_on: 26 | - hub 27 | networks: 28 | - selenium-grid 29 | 30 | firefox: 31 | image: selenium/node-firefox-debug:latest 32 | environment: 33 | - HUB_PORT_4444_TCP_ADDR=hub 34 | - HUB_PORT_4444_TCP_PORT=4444 35 | ports: 36 | - 5901:5900 37 | depends_on: 38 | - hub 39 | networks: 40 | - selenium-grid 41 | 42 | test-gc: 43 | build: robot 44 | command: -v BROWSER:gc --outputdir /out /tests 45 | volumes: 46 | - ./robot/tests:/tests:ro 47 | - ./results/gc:/out:rw 48 | depends_on: 49 | - demoapp 50 | - chrome 51 | networks: 52 | - selenium-grid 53 | 54 | test-ff: 55 | build: robot 56 | command: -v BROWSER:ff --outputdir /out /tests 57 | volumes: 58 | - ./robot/tests:/tests:ro 59 | - ./results/ff:/out:rw 60 | depends_on: 61 | - demoapp 62 | - firefox 63 | networks: 64 | - selenium-grid 65 | 66 | networks: 67 | selenium-grid: -------------------------------------------------------------------------------- /robot/tests/invalid_login.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Documentation A test suite containing tests related to invalid login. 3 | ... 4 | ... These tests are data-driven by their nature. They use a single 5 | ... keyword, specified with Test Template setting, that is called 6 | ... with different arguments to cover different scenarios. 7 | ... 8 | ... This suite also demonstrates using setups and teardowns in 9 | ... different levels. 10 | Suite Setup Open Browser To Login Page 11 | Suite Teardown Close Browser 12 | Test Setup Go To Login Page 13 | Test Template Login With Invalid Credentials Should Fail 14 | Resource resource.robot 15 | 16 | *** Test Cases *** USER NAME PASSWORD 17 | Invalid Username invalid ${VALID PASSWORD} 18 | Invalid Password ${VALID USER} invalid 19 | Invalid Username And Password invalid whatever 20 | Empty Username ${EMPTY} ${VALID PASSWORD} 21 | Empty Password ${VALID USER} ${EMPTY} 22 | Empty Username And Password ${EMPTY} ${EMPTY} 23 | 24 | *** Keywords *** 25 | Login With Invalid Credentials Should Fail 26 | [Arguments] ${username} ${password} 27 | Input Username ${username} 28 | Input Password ${password} 29 | Submit Credentials 30 | Login Should Have Failed 31 | 32 | Login Should Have Failed 33 | Location Should Be ${ERROR URL} 34 | Title Should Be Error Page -------------------------------------------------------------------------------- /robot/tests/resource.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Documentation A resource file with reusable keywords and variables. 3 | ... 4 | ... The system specific keywords created here form our own 5 | ... domain specific language. They utilize keywords provided 6 | ... by the imported SeleniumLibrary. 7 | Library SeleniumLibrary 8 | 9 | *** Variables *** 10 | ${SELENIUM} http://hub:4444/wd/hub 11 | ${APPLICATION} http://demoapp:7272 12 | ${BROWSER} Firefox 13 | ${DELAY} 0 14 | ${VALID USER} demo 15 | ${VALID PASSWORD} mode 16 | ${LOGIN URL} ${APPLICATION}/ 17 | ${WELCOME URL} ${APPLICATION}/welcome.html 18 | ${ERROR URL} ${APPLICATION}/error.html 19 | 20 | 21 | *** Keywords *** 22 | Open Browser To Login Page 23 | Open Browser ${LOGIN URL} browser=${BROWSER} remote_url=${SELENIUM} 24 | Maximize Browser Window 25 | Set Selenium Speed ${DELAY} 26 | Login Page Should Be Open 27 | 28 | Login Page Should Be Open 29 | Title Should Be Login Page 30 | 31 | Go To Login Page 32 | Go To ${LOGIN URL} 33 | Login Page Should Be Open 34 | 35 | Input Username 36 | [Arguments] ${username} 37 | Input Text username_field ${username} 38 | 39 | Input Password 40 | [Arguments] ${password} 41 | Input Text password_field ${password} 42 | 43 | Submit Credentials 44 | Click Button login_button 45 | 46 | Welcome Page Should Be Open 47 | Location Should Be ${WELCOME URL} 48 | Title Should Be Welcome Page 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Selenium Example 2 | 3 | It's great to use [docker-compose](https://docs.docker.com/compose/) to build web testing infra and launch tests in a blink. 4 | 5 | ## Setup 6 | 7 | **Versions:** 8 | ``` 9 | (docker-selenium-rf) docker-selenium-rf % docker-machine version 10 | docker-machine version 0.16.1, build cce350d 11 | 12 | (docker-selenium-rf) docker-selenium-rf % docker-compose version 13 | docker-compose version 1.23.2, build unknown 14 | docker-py version: 3.6.0 15 | CPython version: 3.7.2 16 | OpenSSL version: OpenSSL 1.0.2q 20 Nov 2018 17 | 18 | (docker-selenium-rf) docker-selenium-rf % docker version 19 | Client: Docker Engine - Community 20 | Version: 18.09.1 21 | API version: 1.39 22 | Go version: go1.11.4 23 | Git commit: 4c52b90 24 | Built: Thu Jan 10 03:21:29 2019 25 | OS/Arch: darwin/amd64 26 | Experimental: false 27 | 28 | Server: Docker Engine - Community 29 | Engine: 30 | Version: 18.09.1 31 | API version: 1.39 (minimum version 1.12) 32 | Go version: go1.10.6 33 | Git commit: 4c52b90 34 | Built: Wed Jan 9 19:41:49 2019 35 | OS/Arch: linux/amd64 36 | Experimental: true 37 | ``` 38 | 39 | ## Create Fresh Docker Engine (recommended) 40 | [Docker For Mac](https://docs.docker.com/docker-for-mac/) version 1.13 has [knows issues](https://github.com/docker/docker/issues/25305). 41 | It's recommended to use docker-machine to create a clean engine for this example. 42 | ``` 43 | docker-machine create -d virtualbox test-machine 44 | eval $(docker-machine env test-machine) 45 | ``` 46 | 47 | ## Launch 48 | 49 | **Test application:** 50 | ``` 51 | docker-compose up -d demoapp 52 | ``` 53 | 54 | **Test Infra:** 55 | ``` 56 | docker-compose up -d hub firefox chrome 57 | ``` 58 | 59 | **Robot Framework Tests with browsers:** 60 | ``` 61 | docker-compose run test-ff 62 | docker-compose run test-gc 63 | ``` 64 | 65 | **Reports:** 66 | After test run,test output files will appear in [results](results) directory. 67 | 68 | **View & Debug Execution:** 69 | Connect with vnc to the browsers (in 5900 and 5901). When prompted for password the default is `secret`. 70 | 71 | ## Cleanup 72 | ``` 73 | docker-compose down 74 | docker-machine rm -f test-machine 75 | ``` 76 | --------------------------------------------------------------------------------