From 7cf59cef630b81ed58e64ce30b6ca59afff46652 Mon Sep 17 00:00:00 2001 From: serv-inc Date: Mon, 27 May 2019 14:34:46 +0200 Subject: [PATCH 1/5] fix:minor typo fix pleaes -> please --- google-search-browserstack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-search-browserstack.py b/google-search-browserstack.py index 8dc6d5f..62116ab 100644 --- a/google-search-browserstack.py +++ b/google-search-browserstack.py @@ -9,7 +9,7 @@ USERNAME = os.environ.get('BROWSERSTACK_USERNAME') or sys.argv[1] BROWSERSTACK_ACCESS_KEY = os.environ.get('BROWSERSTACK_ACCESS_KEY') or sys.argv[2] except IndexError: - print("Pleaes provide the username and browserstack access key as command line arguments.") + print("Please provide the username and browserstack access key as command line arguments.") sys.exit(1) driver = webdriver.Remote( From ccbd72bdf167c819d0415664d1c3b4309e3c1609 Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Mon, 24 Jun 2019 19:25:45 +0530 Subject: [PATCH 2/5] Ported code snippets to Python3 --- README.md | 4 ++-- google-search-browserstack.py | 2 +- parallel_tests/README.md | 4 +++- parallel_tests/browsers.json | 6 +++--- parallel_tests/run_parallel_tests.py | 14 ++++++++++---- parallel_tests/test.py | 19 +++++++++++++------ screenshot-sample.py | 16 +++++++++------- 7 files changed, 41 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 546cd5e..04cb235 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ To test various sample repositories with ease, it is recommended to setup `BROWS ### For Windows: - - Download the latest python build for windows - http://sourceforge.net/projects/pywin32/files/pywin32/ + - Download the latest python build for windows - https://www.python.org/downloads/windows/ - Run the installer exe and follow the instructions to install python. ### For Mac and Linux: - - Run python --version to see what python version is installed and make sure it is 2.5.X and above. + - Run python --version to see what python version is installed and make sure it is 3.X and above. - Mac OS, Ubuntu and many flavors of linux come with pre-installed python. ## Install Selenium diff --git a/google-search-browserstack.py b/google-search-browserstack.py index 8dc6d5f..ecc0d08 100644 --- a/google-search-browserstack.py +++ b/google-search-browserstack.py @@ -27,5 +27,5 @@ elem.send_keys("selenium") elem.submit() -print driver.title +print(driver.title) driver.quit() diff --git a/parallel_tests/README.md b/parallel_tests/README.md index 04260ba..449656d 100644 --- a/parallel_tests/README.md +++ b/parallel_tests/README.md @@ -25,4 +25,6 @@ This project contains 3 files. Each of the files is described below. To run the tests in parallel execute the following command: - python run_parallel_tests.py test.py browsers.json +```sh +python3 run_parallel_tests.py test.py browsers.json +``` diff --git a/parallel_tests/browsers.json b/parallel_tests/browsers.json index d501620..8dd3d9a 100644 --- a/parallel_tests/browsers.json +++ b/parallel_tests/browsers.json @@ -1,8 +1,8 @@ [ { - "browserName": "iPhone", - "platform": "MAC", - "device": "iPhone 5" + "browserName": "safari", + "platform": "IOS", + "device": "iPhone 5S" }, { "browser": "firefox", diff --git a/parallel_tests/run_parallel_tests.py b/parallel_tests/run_parallel_tests.py index 8492d00..a617042 100644 --- a/parallel_tests/run_parallel_tests.py +++ b/parallel_tests/run_parallel_tests.py @@ -1,7 +1,13 @@ -import json, sys, subprocess +import json +import sys +import subprocess -file_name = sys.argv[1] -json_name = sys.argv[2] +try: + file_name = sys.argv[1] + json_name = sys.argv[2] +except IndexError: + print("Please provide test script and browserconfig as first and second argument, respectively, from command line.") + sys.exit(1) with open(json_name, "r") as f: obj = json.loads(f.read()) @@ -9,7 +15,7 @@ num_of_tests = len(obj) process = [] for counter in range(num_of_tests): - cmd = "python "+str(file_name)+ " " +str(json_name)+ " " +str(counter) + cmd = "python3 %s %s %s" % (file_name, json_name, counter) process.append(subprocess.Popen(cmd, shell=True)) for counter in range(num_of_tests): diff --git a/parallel_tests/test.py b/parallel_tests/test.py index 878b846..6023cf0 100644 --- a/parallel_tests/test.py +++ b/parallel_tests/test.py @@ -1,15 +1,21 @@ from selenium import webdriver import os, sys, json -json_name = sys.argv[1] +try: + json_name = sys.argv[1] + counter_val = sys.argv[2] +except IndexError: + print('Json name and counter val must be passed as first and second argument, respectively, from the comamnd line') + sys.exit(1) + USERNAME = os.environ.get('BROWSERSTACK_USERNAME') or sys.argv[2] BROWSERSTACK_ACCESS_KEY = os.environ.get('BROWSERSTACK_ACCESS_KEY') or sys.argv[3] with open(json_name, "r") as f: obj = json.loads(f.read()) -instance_caps= obj[int(sys.argv[2])] -print "Test "+sys.argv[2]+" started" +instance_caps = obj[int(counter_val)] +print("Test %s started" % (counter_val)) #------------------------------------------------------# # Mention any other capabilities required in the test @@ -19,7 +25,7 @@ #------------------------------------------------------# -caps = dict(caps.items() + instance_caps.items()) +caps = {**caps, **instance_caps} #------------------------------------------------------# # THE TEST TO BE RUN PARALLELY GOES HERE @@ -28,12 +34,13 @@ command_executor='https://%s:%s@hub.browserstack.com/wd/hub' % ( USERNAME, BROWSERSTACK_ACCESS_KEY ), - desired_capabilities=caps) + desired_capabilities=caps +) driver.get("http://www.google.com") inputElement = driver.find_element_by_name("q") inputElement.send_keys("browserstack") inputElement.submit() -print driver.title +print(driver.title) driver.quit() #------------------------------------------------------# diff --git a/screenshot-sample.py b/screenshot-sample.py index 2cbd1d1..2dbe04b 100644 --- a/screenshot-sample.py +++ b/screenshot-sample.py @@ -23,12 +23,13 @@ try: USERNAME = sys.argv[1] BROWSERSTACK_ACCESS_KEY = sys.argv[2] + FILENAME = sys.argv[3] except IndexError: print("Pleaes provide the username, browserstack access key and filename with which screenshot should be saved as command line arguments.") sys.exit(1) # Define take_screenshot -def take_screenshot(webdriver, file_name = "sample.png"): +def take_screenshot(webdriver, file_name="sample.png"): """ @param webdriver: WebDriver handler. @type webdriver: WebDriver @@ -37,21 +38,22 @@ def take_screenshot(webdriver, file_name = "sample.png"): """ if isinstance(webdriver, WebDriver): base64_data = webdriver.get_screenshot_as_base64() - screenshot_data = base64.decodestring(base64_data) - screenshot_file = open(file_name, "w") + screenshot_data = base64.b64decode(base64_data) + screenshot_file = open(file_name, "wb") screenshot_file.write(screenshot_data) screenshot_file.close() else: webdriver.save_screenshot(filename) driver = webdriver.Remote( - command_executor = 'http://akshaybhardwaj1:XQWDewaJsUzqYJRv8zhr@hub.browserstack.com/wd/hub', - desired_capabilities = caps) + command_executor = 'http://%s:%s@hub.browserstack.com/wd/hub' % (USERNAME, BROWSERSTACK_ACCESS_KEY), + desired_capabilities = caps +) driver.get("http://www.google.com") inputElement = driver.find_element_by_name("q") inputElement.send_keys("browserstack") inputElement.submit() -print driver.title -take_screenshot(driver, './sample.png') +print(driver.title) +take_screenshot(driver, FILENAME) driver.quit() From 602e1d2a0f6edf02b5d4856bd3baec2f3770f9f0 Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Mon, 1 Jul 2019 14:22:27 +0530 Subject: [PATCH 3/5] Changed capabilities for browser to comply with new changes --- parallel_tests/browsers.json | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/parallel_tests/browsers.json b/parallel_tests/browsers.json index 8dd3d9a..4e0e1b5 100644 --- a/parallel_tests/browsers.json +++ b/parallel_tests/browsers.json @@ -1,37 +1,37 @@ [ { - "browserName": "safari", - "platform": "IOS", - "device": "iPhone 5S" + "os_version": "11", + "device": "iPhone 8", + "real_mobile": "true" }, { - "browser": "firefox", - "browser_version": "17.0", "os": "Windows", - "os_version": "8" + "os_version": "8", + "browserName": "Firefox", + "browser_version": "65.0" }, { - "browser": "ie", - "browser_version": "8.0", "os": "Windows", - "os_version": "7" + "os_version": "7", + "browserName": "IE", + "browser_version": "8.0" }, { - "browser": "ie", - "browser_version": "9.0", "os": "Windows", - "os_version": "7" + "os_version": "7", + "browserName": "IE", + "browser_version": "9.0" }, { - "browser": "ie", - "browser_version": "10.0", "os": "Windows", - "os_version": "8" + "os_version": "8", + "browserName": "IE", + "browser_version": "10.0" }, { - "browser": "firefox", - "browser_version": "15.0", "os": "OS X", - "os_version": "Snow Leopard" + "os_version": "Snow Leopard", + "browserName": "Firefox", + "browser_version": "42.0" } ] From 6ff1d9a475f77296d6200873236a691f976f11a0 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:20:37 +0530 Subject: [PATCH 4/5] 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 22ef1ccb345ce6d4fe23c456caa9fab2772e47d8 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:24:41 +0530 Subject: [PATCH 5/5] Adding CODEOWNERS file --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..c9eea17 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @browserstack/automate-public-repos