From 146f07c4f2cb53f2bca7815eb23d88b6708137a5 Mon Sep 17 00:00:00 2001 From: tauqirsarwar1 Date: Wed, 27 Mar 2024 17:23:53 +0500 Subject: [PATCH 1/2] parallel execution --- .github/workflows/ui_workflow.yml | 39 ------------------------------- 1 file changed, 39 deletions(-) diff --git a/.github/workflows/ui_workflow.yml b/.github/workflows/ui_workflow.yml index 2367d1d9..457ea144 100644 --- a/.github/workflows/ui_workflow.yml +++ b/.github/workflows/ui_workflow.yml @@ -176,22 +176,6 @@ jobs: ref: gh-pages path: gh-pages -# - name: Allure Report -# uses: simple-elf/allure-report-action@v1.7 -# 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: @@ -317,29 +301,6 @@ jobs: 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/allure-report-action@v1.7 -# 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 From 2f256a7fb8dc7264fbbd19970c7860c662cad0b9 Mon Sep 17 00:00:00 2001 From: tauqirsarwar1 Date: Thu, 28 Mar 2024 10:49:23 +0500 Subject: [PATCH 2/2] parallel execution --- .github/workflows/ui_workflow.yml | 4 ++-- ci_run_web.sh | 6 ++---- local_run_android.sh | 2 +- local_run_web.sh | 2 +- main/notifications/slack_plugin.py | 15 +++++++++++++-- main/notifications/teams_plugin.py | 16 ++++++++++++++-- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ui_workflow.yml b/.github/workflows/ui_workflow.yml index 457ea144..520eabe4 100644 --- a/.github/workflows/ui_workflow.yml +++ b/.github/workflows/ui_workflow.yml @@ -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 }}" \ @@ -293,7 +293,7 @@ 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 diff --git a/ci_run_web.sh b/ci_run_web.sh index 860dd4c4..2c3e45b1 100755 --- a/ci_run_web.sh +++ b/ci_run_web.sh @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/local_run_android.sh b/local_run_android.sh index 9613bcfa..3446360a 100755 --- a/local_run_android.sh +++ b/local_run_android.sh @@ -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" \ No newline at end of file diff --git a/local_run_web.sh b/local_run_web.sh index fe6ebd97..b85ebf26 100755 --- a/local_run_web.sh +++ b/local_run_web.sh @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/main/notifications/slack_plugin.py b/main/notifications/slack_plugin.py index f45bfa0c..ee9c091a 100644 --- a/main/notifications/slack_plugin.py +++ b/main/notifications/slack_plugin.py @@ -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 @@ -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") @@ -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): @@ -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) diff --git a/main/notifications/teams_plugin.py b/main/notifications/teams_plugin.py index dd615fdd..0edf76ff 100644 --- a/main/notifications/teams_plugin.py +++ b/main/notifications/teams_plugin.py @@ -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 @@ -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") @@ -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): @@ -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)