From c9b833dad4266cc8f8ec2f1fc32e2c12a49c9f15 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Mon, 10 Oct 2022 15:44:41 +0530 Subject: [PATCH 01/11] chore: fix import --- scripts/local.py | 1 + scripts/parallel.py | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/local.py b/scripts/local.py index 77bfc77..1f41434 100644 --- a/scripts/local.py +++ b/scripts/local.py @@ -1,5 +1,6 @@ from dotenv import load_dotenv import os +import json from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.chrome.options import Options as ChromeOptions diff --git a/scripts/parallel.py b/scripts/parallel.py index 31c2757..9c0f16e 100644 --- a/scripts/parallel.py +++ b/scripts/parallel.py @@ -1,5 +1,6 @@ from dotenv import load_dotenv import os +import json from selenium import webdriver from selenium.webdriver.chrome.options import Options as ChromeOptions from selenium.webdriver.firefox.options import Options as FirefoxOptions From a3c23b4c0ac4afb3d70f0b23f8936f0029c6e7db Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Mon, 28 Nov 2022 11:05:09 +0530 Subject: [PATCH 02/11] fix: handle mobile caps --- scripts/parallel.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/parallel.py b/scripts/parallel.py index 9c0f16e..df2712f 100644 --- a/scripts/parallel.py +++ b/scripts/parallel.py @@ -62,12 +62,17 @@ def run_session(cap): } if "os" in cap: bstack_options["os"] = cap["os"] - bstack_options["source"] = "python:sample-main:v1.0" + if "deviceName" in cap: + bstack_options['deviceName'] = cap["deviceName"] + bstack_options["source"] = "python:sample-main:v1.1" + if cap['browserName'] in ['ios']: + cap['browserName'] = 'safari' options = get_browser_option(cap["browserName"].lower()) if "browserVersion" in cap: options.browser_version = cap["browserVersion"] options.set_capability('bstack:options', bstack_options) - + if cap['browserName'].lower() == 'samsung': + options.set_capability('browserName', 'samsung') driver = webdriver.Remote( command_executor=URL, options=options) From 92054de85f69a03583c0ce8f1abb09d9163d026f Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Mon, 28 Nov 2022 11:05:29 +0530 Subject: [PATCH 03/11] chore: update gitignore to include env --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ca91b7a..0f2dc0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /local.log +env From 739c59980719e5a7b07b630fd19e9ad896854493 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Mon, 28 Nov 2022 11:06:01 +0530 Subject: [PATCH 04/11] chore: fix formatting --- scripts/parallel.py | 75 ++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/scripts/parallel.py b/scripts/parallel.py index df2712f..5fb1b86 100644 --- a/scripts/parallel.py +++ b/scripts/parallel.py @@ -13,36 +13,39 @@ from threading import Thread load_dotenv() -BROWSERSTACK_USERNAME = os.environ.get("BROWSERSTACK_USERNAME") or "BROWSERSTACK_USERNAME" -BROWSERSTACK_ACCESS_KEY = os.environ.get("BROWSERSTACK_ACCESS_KEY") or "BROWSERSTACK_ACCESS_KEY" +BROWSERSTACK_USERNAME = os.environ.get( + "BROWSERSTACK_USERNAME") or "BROWSERSTACK_USERNAME" +BROWSERSTACK_ACCESS_KEY = os.environ.get( + "BROWSERSTACK_ACCESS_KEY") or "BROWSERSTACK_ACCESS_KEY" URL = os.environ.get("URL") or "https://hub.browserstack.com/wd/hub" capabilities = [ - { - "os": "OS X", - "osVersion": "Monterey", - "buildName" : "browserstack-build-1", - "sessionName" : "BStack parallel python", - "browserName": "chrome", - "browserVersion": "latest" - }, - { - "os": "Windows", - "osVersion": "11", - "buildName" : "browserstack-build-1", - "sessionName" : "BStack parallel python", - "browserName": "firefox", - "browserVersion": "latest" - }, - { - "osVersion": "10", - "deviceName" : "Samsung Galaxy S20", - "buildName" : "browserstack-build-1", - "sessionName" : "BStack parallel python", - "browserName": "chrome", - }, + { + "os": "OS X", + "osVersion": "Monterey", + "buildName": "browserstack-build-1", + "sessionName": "BStack parallel python", + "browserName": "chrome", + "browserVersion": "latest" + }, + { + "os": "Windows", + "osVersion": "11", + "buildName": "browserstack-build-1", + "sessionName": "BStack parallel python", + "browserName": "firefox", + "browserVersion": "latest" + }, + { + "osVersion": "10", + "deviceName": "Samsung Galaxy S20", + "buildName": "browserstack-build-1", + "sessionName": "BStack parallel python", + "browserName": "chrome", + }, ] + def get_browser_option(browser): switcher = { "chrome": ChromeOptions(), @@ -52,27 +55,28 @@ def get_browser_option(browser): } return switcher.get(browser, ChromeOptions()) + def run_session(cap): bstack_options = { - "osVersion" : cap["osVersion"], - "buildName" : cap["buildName"], - "sessionName" : cap["sessionName"], + "osVersion": cap["osVersion"], + "buildName": cap["buildName"], + "sessionName": cap["sessionName"], "userName": BROWSERSTACK_USERNAME, "accessKey": BROWSERSTACK_ACCESS_KEY } if "os" in cap: - bstack_options["os"] = cap["os"] + bstack_options["os"] = cap["os"] if "deviceName" in cap: - bstack_options['deviceName'] = cap["deviceName"] + bstack_options['deviceName'] = cap["deviceName"] bstack_options["source"] = "python:sample-main:v1.1" if cap['browserName'] in ['ios']: - cap['browserName'] = 'safari' + cap['browserName'] = 'safari' options = get_browser_option(cap["browserName"].lower()) if "browserVersion" in cap: - options.browser_version = cap["browserVersion"] + options.browser_version = cap["browserVersion"] options.set_capability('bstack:options', bstack_options) if cap['browserName'].lower() == 'samsung': - options.set_capability('browserName', 'samsung') + options.set_capability('browserName', 'samsung') driver = webdriver.Remote( command_executor=URL, options=options) @@ -88,7 +92,7 @@ def run_session(cap): # Check if the Cart pane is visible WebDriverWait(driver, 10).until(EC.visibility_of_element_located( (By.CLASS_NAME, "float-cart__content"))) - ## Get text of product in cart + # Get text of product in cart item_in_cart = WebDriverWait(driver, 10).until(EC.visibility_of_element_located( (By.XPATH, '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]'))).text # Verify whether the product (iPhone 12) is added to cart @@ -107,5 +111,6 @@ def run_session(cap): # Stop the driver driver.quit() + for cap in capabilities: - Thread(target=run_session, args=(cap,)).start() + Thread(target=run_session, args=(cap,)).start() From 76a4a32fcb53c563a94ef4b4b2e02f89acab2b7a Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Thu, 23 Mar 2023 16:42:00 +0530 Subject: [PATCH 05/11] Made parallel test as default --- README.md | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 66a8624..2074fe1 100644 --- a/README.md +++ b/README.md @@ -17,32 +17,14 @@ BROWSERSTACK_USERNAME="BROWSERSTACK_USERNAME" BROWSERSTACK_ACCESS_KEY="BROWSERSTACK_ACCESS_KEY" URL="https://hub.browserstack.com/wd/hub" ``` -- Change the capabilities if you wish: -(For single test session, Navigate to ./scripts/single.py) -```python -desired_cap = { - ... - 'browserName': 'iPhone', - 'device': 'iPhone 11', - 'realMobile': 'true', - 'os_version': '14.0', - 'name': 'BStack-[Python] Sample Test', # test name - 'build': 'BStack Build Number 1' # CI/CD job or build name - ... -} -``` - Run tests - a. For single + a. For parallel ``` - python3 ./scripts/single.py + python3 ./scripts/parallel.py ``` b. For local ``` python3 ./scripts/local.py ``` - c. For parallel - ``` - python3 ./scripts/parallel.py - ``` From e410651524518f75be6a7f1677e96106748e0822 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Wed, 12 Apr 2023 13:40:29 +0530 Subject: [PATCH 06/11] Added workflow file in main --- .github/CODEOWNERS | 1 + .github/workflows/reviewing_changes.yml | 88 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/reviewing_changes.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..7e1f1b4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +.github/* @browserstack/asi-devs diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml new file mode 100644 index 0000000..bec57fb --- /dev/null +++ b/.github/workflows/reviewing_changes.yml @@ -0,0 +1,88 @@ +# This job is to test different profiles in sdk branch against Pull Requests raised +# This workflow targets python-selenium + +name: Python SDK Test workflow on workflow_dispatch(from main branch) + +on: + workflow_dispatch: + inputs: + pull_request_number: + description: 'The pull request number to build' + required: true + +jobs: + comment-run: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + max-parallel: 3 + matrix: + python: ['3.7', '3.10', '3.11'] + os: [ macos-latest, windows-latest, ubuntu-latest ] + name: Python-selenium Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + env: + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + + steps: + - uses: actions/checkout@v3 + with: + ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head + - name: Fetch Commit SHA + run: | + git log -1 --format='%H' + echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV + echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV + - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 + id: status-check-in-progress + env: + job_name: Python-selenium Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + with: + github-token: ${{ github.token }} + script: | + const result = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.job_name, + head_sha: process.env.commit_sha, + status: 'in_progress' + }).catch((err) => ({status: err.status, response: err.response})); + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) + if (result.status !== 201) { + console.log('Failed to create check run') + } + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install dependencies + run: python -m pip install -r requirements.txt + + - name: run tests in parallel + run: browserstack-sdk ./tests/test.py + + - name: run local tests in parallel + run: browserstack-sdk ./tests/local-test.py + + - if: always() + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 + id: status-check-completed + env: + conclusion: ${{ job.status }} + job_name: Python-selenium Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + with: + github-token: ${{ github.token }} + script: | + const result = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.job_name, + head_sha: process.env.commit_sha, + status: 'completed', + conclusion: process.env.conclusion + }).catch((err) => ({status: err.status, response: err.response})); + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) + if (result.status !== 201) { + console.log('Failed to create check run') + } From d160b7584216af9a499a5c1865b171bf29dae2ec Mon Sep 17 00:00:00 2001 From: bstack-security-github <116066275+bstack-security-github@users.noreply.github.com> Date: Wed, 21 Jun 2023 17:26:38 +0530 Subject: [PATCH 07/11] Adding Code Scanner Semgrep.yml workflow file --- .github/workflows/Semgrep.yml | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/Semgrep.yml diff --git a/.github/workflows/Semgrep.yml b/.github/workflows/Semgrep.yml new file mode 100644 index 0000000..0347afd --- /dev/null +++ b/.github/workflows/Semgrep.yml @@ -0,0 +1,48 @@ +# Name of this GitHub Actions workflow. +name: Semgrep + +on: + # Scan changed files in PRs (diff-aware scanning): + # The branches below must be a subset of the branches above + pull_request: + branches: ["master", "main"] + push: + branches: ["master", "main"] + schedule: + - cron: '0 6 * * *' + + +permissions: + contents: read + +jobs: + semgrep: + # User definable name of this GitHub Actions job. + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + name: semgrep/ci + # If you are self-hosting, change the following `runs-on` value: + runs-on: ubuntu-latest + + container: + # A Docker image with Semgrep installed. Do not change this. + image: returntocorp/semgrep + + # Skip any PR created by dependabot to avoid permission issues: + if: (github.actor != 'dependabot[bot]') + + steps: + # Fetch project source with GitHub Actions Checkout. + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + # Run the "semgrep ci" command on the command line of the docker image. + - run: semgrep ci --sarif --output=semgrep.sarif + env: + # Add the rules that Semgrep uses by setting the SEMGREP_RULES environment variable. + SEMGREP_RULES: p/default # more at semgrep.dev/explore + + - name: Upload SARIF file for GitHub Advanced Security Dashboard + uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2.20.0 + with: + sarif_file: semgrep.sarif + if: always() \ No newline at end of file From c400c91993265f98b2c02397ecaef7f96c97a2c8 Mon Sep 17 00:00:00 2001 From: bstack-security-github <116066275+bstack-security-github@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:46:55 +0530 Subject: [PATCH 08/11] Adding CODEOWNERS file --- .github/CODEOWNERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7e1f1b4..09a587d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,3 @@ .github/* @browserstack/asi-devs + +* @browserstack/automate-public-repos From 1de162ab7a792af5319d20f6bd58c3b839c89331 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Jul 2023 11:50:59 +0530 Subject: [PATCH 09/11] Fix workflow file --- .github/workflows/reviewing_changes.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml index bec57fb..ad8815d 100644 --- a/.github/workflows/reviewing_changes.yml +++ b/.github/workflows/reviewing_changes.yml @@ -6,8 +6,8 @@ name: Python SDK Test workflow on workflow_dispatch(from main branch) on: workflow_dispatch: inputs: - pull_request_number: - description: 'The pull request number to build' + commit_sha: + description: 'The commit id to build' required: true jobs: @@ -27,16 +27,12 @@ jobs: steps: - uses: actions/checkout@v3 with: - ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head - - name: Fetch Commit SHA - run: | - git log -1 --format='%H' - echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV - echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV + ref: ${{ github.event.inputs.commit_sha }} - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-in-progress env: job_name: Python-selenium Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + commit_sha: ${{ github.event.inputs.commit_sha }} with: github-token: ${{ github.token }} script: | @@ -71,6 +67,7 @@ jobs: env: conclusion: ${{ job.status }} job_name: Python-selenium Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + commit_sha: ${{ github.event.inputs.commit_sha }} with: github-token: ${{ github.token }} script: | From 7d5ad3a6d941e390485ca8b21068b8a0b500bd59 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Jul 2023 12:11:00 +0530 Subject: [PATCH 10/11] Fix workflow file --- .github/workflows/reviewing_changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml index ad8815d..bd48a5d 100644 --- a/.github/workflows/reviewing_changes.yml +++ b/.github/workflows/reviewing_changes.yml @@ -1,7 +1,7 @@ # This job is to test different profiles in sdk branch against Pull Requests raised # This workflow targets python-selenium -name: Python SDK Test workflow on workflow_dispatch(from main branch) +name: Python SDK Test workflow on workflow_dispatch on: workflow_dispatch: From 4f5a7519f1bb6bdc6f0e3edcad24f598f5330b7e Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Jul 2023 13:05:49 +0530 Subject: [PATCH 11/11] Fix workflow file --- .github/workflows/reviewing_changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml index bd48a5d..4a72a7b 100644 --- a/.github/workflows/reviewing_changes.yml +++ b/.github/workflows/reviewing_changes.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: inputs: commit_sha: - description: 'The commit id to build' + description: 'The full commit id to build' required: true jobs: