Skip to content

Commit

Permalink
Develop (#71)
Browse files Browse the repository at this point in the history
### To be filled by the PR creator:

* A brief description of the changes made - 

* Do we have clean latest run report (Docker or Browserstack) attached
with this PR?
  * [ ] Yes
  * [ ] No (Please explain why)

* Does the PR contain changes to any core file?
  * [ ] Yes (Needs approval from at least 1 people)
  * [ ] No

* Is it
  * [ ] New Testcase
  * [ ] Fix


### To be filled by the PR reviewer:

* [ ] Verify the attached run report passed in GitHub Actions (Docker or
Browserstack run)

* General
    * [ ] Use the best strategy to locate the elements
    * [ ] Comments wherever the code is not readable by itself
    * [ ] Use of the right data structure for the use case
    * [ ] Reuse logic/functionality as much as possible
    * [ ] Cleanup of any test data that is generated by the tests
    * [ ] No static waits
  • Loading branch information
Tauqir Sarwar authored Mar 28, 2024
2 parents cccbd1f + 2f256a7 commit 20b0214
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 51 deletions.
43 changes: 2 additions & 41 deletions .github/workflows/ui_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
run: |
env
source $HOME/.bp-venv/bin/activate
sh ci_run_web.sh ${{secrets.BROWSERSTACK_API_USERNAME}} ${{secrets.BROWSERSTACK_ACCESS_KEY}} "${{ matrix.config_file }}" "$TAGS" "${{secrets.SLACK_WEBHOOK_URL}}" "${{secrets.TEAMS_WEBHOOK_URL}}" "$BASE_URL"
sh ci_run_web.sh ${{secrets.BROWSERSTACK_API_USERNAME}} ${{secrets.BROWSERSTACK_ACCESS_KEY}} "${{ matrix.config_file }}" "$TAGS" "$BASE_URL"
# --pytest-testrail-export-test-results \
# --testrail-project-id "${{ env.TESTRAIL_PROJECT_ID }}" \
# --pytest-testrail-test-plan-id "${{ env.TEST_PLAN_ID }}" \
Expand All @@ -176,22 +176,6 @@ jobs:
ref: gh-pages
path: gh-pages

# - name: Allure Report
# uses: simple-elf/[email protected]
# if: always()
# with:
# gh_pages: gh-pages
# allure_results: allure-results
# allure_history: allure-history
#
# - name: Deploy report to Github Pages
# if: always()
# uses: peaceiris/actions-gh-pages@v3
# with:
# PERSONAL_TOKEN: ${{ secrets.PYTEST_TOKEN }}
# PUBLISH_BRANCH: gh-pages
# PUBLISH_DIR: allure-history

- name: Upload HTML run report in the Artifacts Folder
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -309,37 +293,14 @@ jobs:
env
source $HOME/.bp-venv/bin/activate
sh ci_run_web.sh ${{secrets.BROWSERSTACK_API_USERNAME}} ${{secrets.BROWSERSTACK_ACCESS_KEY}} "$BROWSER" "$TAGS" "${{secrets.SLACK_WEBHOOK_URL}}" "${{secrets.TEAMS_WEBHOOK_URL}}" "$BASE_URL"
sh ci_run_web.sh ${{secrets.BROWSERSTACK_API_USERNAME}} ${{secrets.BROWSERSTACK_ACCESS_KEY}} "$BROWSER" "$TAGS" "$BASE_URL"
- name: BrowserStackLocal Stop
uses: browserstack/github-actions/setup-local@master
with:
local-testing: stop
if: ${{ always() }}

# - name: Get Allure history
# uses: actions/checkout@v4
# if: always()
# continue-on-error: true
# with:
# ref: gh-pages
# path: gh-pages
#
# - name: Allure Report
# uses: simple-elf/[email protected]
# if: always()
# with:
# gh_pages: gh-pages
# allure_results: allure-results
# allure_history: allure-history
#
# - name: Deploy report to Github Pages
# if: always()
# uses: peaceiris/actions-gh-pages@v3
# with:
# PERSONAL_TOKEN: ${{ secrets.PYTEST_TOKEN }}
# PUBLISH_BRANCH: gh-pages
# PUBLISH_DIR: allure-history

- name: Upload HTML run report in the Artifacts Folder
uses: actions/upload-artifact@v4
Expand Down
6 changes: 2 additions & 4 deletions ci_run_web.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

# Run Web tests
python -m pytest -v -s --gherkin-terminal-reporter --driver=Remote --selenium-host "$1":"$2""@hub-cloud.browserstack.com" --variables=$3 --html="./output/reports/" \
--tags=$4 --reruns 1 --reruns-delay 2 --self-contained-html --capability headless False --slack-webhook-url=$5 --slack-channel=pytest-test-automation \
--slack-results-url=https://tweag.github.io/pytest-automation-boilerplate --teams-webhook-url=$6 \
--teams-results-url=https://tweag.github.io/pytest-automation-boilerplate --base-url=$7
python -m pytest -vv -s --gherkin-terminal-reporter --driver=Remote --selenium-host "$1":"$2""@hub-cloud.browserstack.com" --variables=$3 --html="./output/reports/" \
--tags=$4 --reruns 1 --reruns-delay 2 --self-contained-html --capability headless False --base-url=$5
2 changes: 1 addition & 1 deletion local_run_android.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

# Run API tests
python -m pytest -v -s --disable-warnings --gherkin-terminal-reporter --driver=Appium --html="./output/reports/" --self-contained-html \
python -m pytest -vv -s --disable-warnings --gherkin-terminal-reporter --driver=Appium --html="./output/reports/" --self-contained-html \
--variables="env_configs/android_mobile_docker.json" --reruns 1 --reruns-delay 2 --tags="android_mobile_tests"
2 changes: 1 addition & 1 deletion local_run_web.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

# Run API tests
python -m pytest -v -s --gherkin-terminal-reporter --driver=Chrome --html="./output/reports/" --self-contained-html --capability headless True --reruns 1 --reruns-delay 2 --tags="web_tests" -n 2
python -m pytest -vv -s --gherkin-terminal-reporter --driver=Chrome --html="./output/reports/" --self-contained-html --capability headless True --reruns 1 --reruns-delay 2 --tags="web_tests" -n 2
15 changes: 13 additions & 2 deletions main/notifications/slack_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def __init__(
webhook_url: str,
channel: str,
results_url: Optional[str] = None,
failure_only: Optional[bool] = False,
):
self.webhook_url = webhook_url
self.channel = channel
self.results_url = results_url
self.failure_only = failure_only

self.reports: Dict[Outcome, List] = defaultdict(list)
self.session_start = 0
Expand Down Expand Up @@ -164,9 +166,12 @@ def pytest_sessionstart(self, session) -> None:

def pytest_sessionfinish(self, session, exitstatus) -> None:
self.session_end = time.time()
if exitstatus == 0 or exitstatus == 1 or exitstatus == 6:
if self.failure_only.lower() == 'true' and self.failed_tests_count > 0 and exitstatus == 1:
self.send_message()
print('Test results sent to Slack')
print('Test results with failures sent to Slack')
elif self.failure_only.lower() == 'false' or self.failure_only is None:
self.send_message()
print('All Test results sent to Slack')
else:
print(f"No Slack alert sent")

Expand All @@ -188,6 +193,11 @@ def pytest_addoption(parser: Parser):
help='URL to results page for link in Slack message',
default=os.getenv('SLACK_RESULTS_URL'),
)
group.addoption(
'--slack-failure-only',
help='Alert only on test failures',
default=os.getenv('SLACK_FAILURE_ONLY'),
)


def pytest_configure(config: Config):
Expand All @@ -197,6 +207,7 @@ def pytest_configure(config: Config):
webhook_url=slack_webhook_url,
channel=config.option.slack_channel,
results_url=config.option.slack_results_url,
failure_only=config.option.slack_failure_only,
)
config._slack = plugin
config.pluginmanager.register(plugin)
Expand Down
16 changes: 14 additions & 2 deletions main/notifications/teams_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def __init__(
self,
webhook_url: str,
results_url: Optional[str] = None,
failure_only: Optional[bool] = False,
):
self.webhook_url = webhook_url
self.results_url = results_url
self.failure_only = failure_only

self.reports: Dict[Outcome, List] = defaultdict(list)
self.session_start = 0
Expand Down Expand Up @@ -164,9 +166,12 @@ def pytest_sessionstart(self, session) -> None:

def pytest_sessionfinish(self, session, exitstatus) -> None:
self.session_end = time.time()
if exitstatus == 0 or exitstatus == 1 or exitstatus == 6:
if self.failure_only.lower() == 'true' and self.failed_tests_count > 0 and exitstatus == 1:
self.send_teams_message()
print('Test results sent to Teams')
print('Test results with failures sent to Teams')
elif self.failure_only.lower() == 'false' or self.failure_only is None:
self.send_teams_message()
print('All Test results sent to Teams')
else:
print(f"No Teams alert sent")

Expand All @@ -183,6 +188,11 @@ def pytest_addoption(parser: Parser):
help='URL to results page for link in Teams message',
default=os.getenv('TEAMS-RESULTS-URL'),
)
group.addoption(
'--teams-failure-only',
help='Alert only on test failures',
default=os.getenv('TEAMS_FAILURE_ONLY'),
)


def pytest_configure(config: Config):
Expand All @@ -191,6 +201,8 @@ def pytest_configure(config: Config):
plugin = TeamsPlugin(
webhook_url=teams_webhook_url,
results_url=config.option.teams_results_url,
failure_only=config.option.teams_failure_only,

)
config._teams = plugin
config.pluginmanager.register(plugin)
Expand Down

0 comments on commit 20b0214

Please sign in to comment.