Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break up selenium tests #281

Merged
merged 15 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/python_development/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"ms-python.black-formatter"
]
}
}
},
"remoteUser": "admin.ackbar"
}
30 changes: 24 additions & 6 deletions .github/workflows/cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,43 @@ jobs:
docker-compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c " cd testing/tests \
&& echo export elastic=${{ env.elastic }} > .env \
&& echo export ES_HOST=${{ env.LS1_IP }} >> .env \
&& cat .env \
&& python3 -m venv /home/admin.ackbar/venv_test \
&& . /home/admin.ackbar/venv_test/bin/activate \
&& pip install -r requirements.txt \
&& sudo chmod ugo+w /home/admin.ackbar/LME/ -R \
&& pytest -v api_tests/"

- name: Run selenium tests in container
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c " cd testing/tests \
&& echo export ELASTIC_PASSWORD=${{ env.elastic }} > .env \
&& . .env \
docker-compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c " cd testing/tests \
&& echo export elastic=${{ env.elastic }} > .env \
&& echo export ES_HOST=${{ env.LS1_IP }} >> .env \
&& echo export KIBANA_HOST= ${{ env.LS1_IP }} >> .env \
&& echo export KIBANA_PORT=443 >> .env \
&& echo export KIBANA_USER=elastic >> .env \
&& echo export SELENIUM_TIMEOUT=60 >> .env \
&& echo export SELENIUM_MODE=headless >> .env \
&& cat .env \
&& python3 -m venv /home/admin.ackbar/venv_test \
&& . /home/admin.ackbar/venv_test/bin/activate \
&& pip install -r requirements.txt \
&& sudo chmod ugo+w /home/admin.ackbar/LME/ -R \
&& python selenium_tests.py --domain ${{ env.LS1_IP }} -v"
&& pytest -v selenium_tests/"

# - name: Run selenium tests in container
# run: |
# set +e
# cd testing/development
# docker compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c " cd testing/tests \
# && echo export ELASTIC_PASSWORD=${{ env.elastic }} > .env \
# && . .env \
# && python3 -m venv /home/admin.ackbar/venv_test \
# && . /home/admin.ackbar/venv_test/bin/activate \
# && pip install -r requirements.txt \
# && sudo chmod ugo+w /home/admin.ackbar/LME/ -R \
# && python selenium_tests.py --domain ${{ env.LS1_IP }} -v"

- name: Cleanup environment
if: always()
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/linux_only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ jobs:
&& . /home/admin.ackbar/venv_test/bin/activate \
&& sudo chmod ugo+w /home/admin.ackbar/LME/ \
&& pytest testing/tests/api_tests/linux_only/ "

- name: Run selenium tests in container
run: |
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c "
. testing/configure/lib/functions.sh \
&& echo export ELASTIC_PASSWORD=${{ env.elastic }} > testing/tests/.env \
&& echo export KIBANA_HOST=localhost >> testing/tests/.env \
&& echo export KIBANA_PORT=443 >> testing/tests/.env \
&& echo export KIBANA_USER=elastic >> testing/tests/.env \
&& echo export SELENIUM_TIMEOUT=60 >> testing/tests/.env \
&& echo export SELENIUM_MODE=headless >> testing/tests/.env \
&& . testing/tests/.env \
&& sudo cp /opt/lme/Chapter\\ 3\\ Files/output.log . \
&& extract_credentials output.log \
&& sudo rm output.log \
&& sudo docker ps \
&& . /home/admin.ackbar/venv_test/bin/activate \
&& sudo chmod ugo+w /home/admin.ackbar/LME/ \
&& pytest testing/tests/selenium_tests/linux_only/ \
"

- name: Cleanup Docker Compose
if: always()
Expand Down
15 changes: 14 additions & 1 deletion testing/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,26 @@ You can create these files in the .vscode directory in the root of your repo and
"cwd": "${workspaceFolder}/testing/tests",
"envFile": "${workspaceFolder}/testing/tests/.env"
},
{
"name": "Python Debugger: Run Selenium linux only Tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"${workspaceFolder}/testing/tests/selenium_tests/linux_only"
],
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${workspaceFolder}/testing/tests",
"envFile": "${workspaceFolder}/testing/tests/.env"
},
{
"name": "Python Debugger: Run Selenium Tests",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/testing/tests/selenium_tests.py",
"args": [
"--domain", "172.212.163.74"
"--domain", "lme"
],
"console": "integratedTerminal",
"justMyCode": false,
Expand Down
21 changes: 19 additions & 2 deletions testing/tests/.env_example
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
export elastic="yourelasticsearchpassword"
export ES_HOST="elasticsearchhostip"
# Comes from an install using InstallTestbed.ps1 many tests use it
export elastic='yourelasticpassword'

# For api tests that connect directly to elasticsearch
export ES_HOST="lme" # When running in docker and connecting from dev container
# export ES_HOST=xx.xx.xx.xxx # When you have a cluser installed in azure

# Selenium tests folder. Connects to kibana
export KIBANA_HOST=lme # When running in docker and connecting from dev container
# export KIBANA_HOST=localhost # When running the tests inside of the lme container
# export KIBANA_HOST=xx.xx.xx.xxx # When you have a cluser installed in azure
export KIBANA_PORT=443
export KIBANA_USER=elastic
export SELENIUM_TIMEOUT=60
# debug, detached, headless
export SELENIUM_MODE=headless

# selenium_tests.py
export ELASTIC_PASSWORD='yourelasticpassword'
98 changes: 85 additions & 13 deletions testing/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,47 @@ After that, the Run and Debug interface will change and have a green arrow in it
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Run Tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"${workspaceFolder}/testing/tests/api_tests" // Path to your tests
],
"console": "integratedTerminal",
"justMyCode": false, // Set this to false to allow debugging into external libraries
"cwd": "${workspaceFolder}/testing/tests/" // Set the working directory
}
{
"name": "Python Debugger: Run API Tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"${workspaceFolder}/testing/tests/api_tests"
],
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${workspaceFolder}/testing/tests",
"envFile": "${workspaceFolder}/testing/tests/.env"
},
{
"name": "Python Debugger: Run Selenium linux only Tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"${workspaceFolder}/testing/tests/selenium_tests/linux_only"
],
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${workspaceFolder}/testing/tests",
"envFile": "${workspaceFolder}/testing/tests/.env"
},
{
"name": "Python Debugger: Run Selenium Tests",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/testing/tests/selenium_tests.py",
"args": [
"--domain", "172.19.0.3"
],
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${workspaceFolder}/testing/tests",
"envFile": "${workspaceFolder}/testing/tests/.env",
}
]
}
}
```
If you want to get the test explorer (beaker icon) to be able to find your tests, you can add
this to your `.vscode/settings.json`, so it knows to look in the `/testing/tests` folder.
Expand Down Expand Up @@ -191,3 +218,48 @@ When a test fails, the test result details on the report provide appropriate inf

## Development and Docker

Using Visual Studio Code you can open this project in a container so you can develop in an environment that is just like the pipeline runs.
In order to do so, you will need to create a directory at the root of the repo and put some folders inside of it.
```bash
mkdir -p .devcontainer/python_development
touch .devcontainer/python_development/devcontainer.json
```

Once you have set up this configuration you can add this to `devcontainer.json`:
```json
{
"name": "Python Development",
"dockerComposeFile": [
"../../testing/development/docker-compose.yml"
],
"service": "ubuntu",
"shutdownAction": "none",
"workspaceFolder": "/lme",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"littlefoxteam.vscode-python-test-adapter",
"ms-python.black-formatter"
]
}
},
"remoteUser": "admin.ackbar"
}
```

Now you can press the blue button at the far bottom left of the VSCode editor and select "Reopen in container", choosing the "Python Development" option.

In this container, you can reach an lme install (on the host's docker) by connecting to `lme` lme resolves to the other container where
you can run an lme install on.
You can see how to do an lme install on that container by looking at the `linux_only.yml` pipeline in the `.github/workflows` directory.

At the time of this writing, you can run this on your host's system (not in the dev container):
```bash
cd LME/testing/development/
docker compose exec -T lme bash -c "./testing/development/build_docker_lme_install.sh -b your-branch-name-with-no-quotes"
# Make sure your branch is pushed up to github before running this.
```

Once you do that, you can now reach that install from within your dev containers by using the hostname `lme`.

Loading
Loading