diff --git a/docs/gitlab-ci-integration.md b/docs/gitlab-ci-integration.md index e4bea922d..26bb92379 100644 --- a/docs/gitlab-ci-integration.md +++ b/docs/gitlab-ci-integration.md @@ -110,7 +110,7 @@ import VerifiedTag from '@site/src/component/verifiedTag'; "name": "Code sample 5", "codeSampleType": "code snippet", "programmingLanguage": "text", - "text": "$ set LT_ACCESS_KEY=\n$ set LT_ACCESS_KEY=" + "text": "$ set LT_USERNAME=\n$ set LT_ACCESS_KEY=" }, { "@type": "SoftwareSourceCode", @@ -211,7 +211,7 @@ $ export LT_ACCESS_KEY= ``` -$ set LT_ACCESS_KEY= +$ set LT_USERNAME= $ set LT_ACCESS_KEY= ``` diff --git a/docs/gitlab-integration-with-hyperexecute.md b/docs/gitlab-integration-with-hyperexecute.md index f0eae47fe..23e6a7379 100644 --- a/docs/gitlab-integration-with-hyperexecute.md +++ b/docs/gitlab-integration-with-hyperexecute.md @@ -78,13 +78,13 @@ import VerifiedTag from '@site/src/component/verifiedTag'; "hasPart": [ { "@type": "SoftwareSourceCode", - "name": "Below is a sample of GitLab YAML created for your reference", + "name": "Sample .gitlab-ci.yml for HyperExecute", "codeSampleType": "code snippet", - "programmingLanguage": "Shell", - "text": "## Define the image to use (adjust for macOS if needed)\nimage: ubuntu:latest\n\n## Define pipelines (can have multiple pipelines)\npipelines:\n ## Default pipeline (can be named differently)\n default:\n ## Branches to trigger this pipeline on (adjust as needed)\n branches:\n - master\n\n ## Define steps in the pipeline\n steps:\n ## Download Hyperexecute CLI (descriptive name)\n - name: Download Hyperexecute CLI\n script: |\n wget https://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute\n chmod u+x hyperexecute\n\n ## Run Hyperexecute tests (descriptive name)\n - name: Run Hyperexecute Tests\n script: |\n ./hyperexecute --user --key --config " + "programmingLanguage": "YAML", + "text": "stages:\n - test\n\nhyperexecute:\n stage: test\n image: ubuntu:latest\n rules:\n # Run on the default branch (adjust as needed)\n - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n before_script:\n # ubuntu:latest does not ship curl, so install it first\n - apt-get update && apt-get install -y curl ca-certificates\n # Download the Linux HyperExecute CLI and make it executable\n - curl -fsSL https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute -o hyperexecute\n - chmod +x hyperexecute\n script:\n # LT_USERNAME and LT_ACCESS_KEY come from the masked CI/CD variables added in step 4\n # Replace with the path of your HyperExecute YAML file\n - ./hyperexecute --user \"$LT_USERNAME\" --key \"$LT_ACCESS_KEY\" --config " } ], - "dateModified": "2026-09-09T19:10:37+05:30" + "dateModified": "2026-12-04T12:00:00+05:30" }) }} /> @@ -127,7 +127,19 @@ To connect your external repository by URL, fill in the required information in Create New Project -### 4. Configure the Pipeline +### 4. Add Your Credentials as CI/CD Variables + +Keep your username and access key out of the pipeline file. Store them as project variables, and the pipeline reads them at run time. + +- In your GitLab project, go to **Settings** > **CI/CD**, expand **Variables**, and click **Add variable**. You need the Maintainer role. +- Add a variable with the key `LT_USERNAME` and your username as the value. +- Add a variable with the key `LT_ACCESS_KEY` and your access key as the value. +- Keep the visibility of both variables at **Masked**, the default, so GitLab shows `[MASKED]` in job logs instead of the value. GitLab can mask a value only when it is a single line with no spaces and at least 8 characters long. If your username is shorter than 8 characters, set `LT_USERNAME` to **Visible** and keep `LT_ACCESS_KEY` masked. +- If you also select **Protect variable**, the variables are passed only to pipelines that run on protected branches or tags, such as your default branch. + +To find your username and access key, see [how to get your username and access key](/support/docs/hyperexecute-how-to-get-my-username-and-access-key/). + +### 5. Configure the Pipeline - To configure the new pipeline that you just created, click the **Configure Pipeline** button in the center of the page. Create New Project @@ -143,33 +155,35 @@ Below is a sample of GitLab YAML created for your reference: -```bash -## Define the image to use (adjust for macOS if needed) -image: ubuntu:latest - -## Define pipelines (can have multiple pipelines) -pipelines: - ## Default pipeline (can be named differently) - default: - ## Branches to trigger this pipeline on (adjust as needed) - branches: - - master - - ## Define steps in the pipeline - steps: - ## Download Hyperexecute CLI (descriptive name) - - name: Download Hyperexecute CLI - script: | - wget https://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute - chmod u+x hyperexecute - - ## Run Hyperexecute tests (descriptive name) - - name: Run Hyperexecute Tests - script: | - ./hyperexecute --user --key --config +```yaml title=".gitlab-ci.yml" +stages: + - test + +hyperexecute: + stage: test + image: ubuntu:latest + rules: + # Run on the default branch (adjust as needed) + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + before_script: + # ubuntu:latest does not ship curl, so install it first + - apt-get update && apt-get install -y curl ca-certificates + # Download the Linux HyperExecute CLI and make it executable + - curl -fsSL https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute -o hyperexecute + - chmod +x hyperexecute + script: + # LT_USERNAME and LT_ACCESS_KEY come from the masked CI/CD variables added in step 4 + # Replace with the path of your HyperExecute YAML file + - ./hyperexecute --user "$LT_USERNAME" --key "$LT_ACCESS_KEY" --config ``` -### 5. Run Your Job +- **stages:** Lists the stages of the pipeline. This example has one stage, `test`. +- **hyperexecute:** The job that runs your tests. It runs in the `test` stage on the `ubuntu:latest` image. +- **rules:** Runs the job on pushes to the default branch. Change the condition to run it on other branches or on merge requests. +- **before_script:** Installs curl, downloads the Linux build of the HyperExecute CLI and makes it executable. +- **script:** Runs the HyperExecute CLI with your username and access key, read from the masked variables, and the path of the YAML file created for HyperExecute. For every flag the CLI accepts, see the [HyperExecute CLI guide](/support/docs/hyperexecute-cli-run-tests-on-hyperexecute-grid/). + +### 6. Run Your Job - To commit your changes and run your job, click the **Commit Changes** button.

Create New Project diff --git a/docs/run-tests-with-chrome-devtools-protocol.md b/docs/run-tests-with-chrome-devtools-protocol.md index a75f17f63..de59a212f 100644 --- a/docs/run-tests-with-chrome-devtools-protocol.md +++ b/docs/run-tests-with-chrome-devtools-protocol.md @@ -133,6 +133,27 @@ import VerifiedTag from '@site/src/component/verifiedTag'; "programmingLanguage": "text", "text": "Page 1: 15 products\nPage 2: 15 products\nPage 3: 15 products\nPage 4: 15 products\nPage 5: 15 products\nCollected 75 products total\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 (index) \u2502 name \u2502 price \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 0 \u2502 'HTC Touch HD' \u2502 '$146.00' \u2502\n\u2502 1 \u2502 'Palm Treo Pro' \u2502 '$337.99' \u2502\n\u2502 2 \u2502 'Canon EOS 5D' \u2502 '$134.00' \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518" }, + { + "@type": "SoftwareSourceCode", + "name": "Run the Same CDP Test in Python With Playwright", + "codeSampleType": "code snippet", + "programmingLanguage": "Shell", + "text": "pip install playwright" + }, + { + "@type": "SoftwareSourceCode", + "name": "cdp_test.py", + "codeSampleType": "code snippet", + "programmingLanguage": "Python", + "text": "# cdp_test.py\nimport json\nimport os\nfrom urllib.parse import quote\n\nfrom playwright.sync_api import sync_playwright\n\nusername = os.environ[\"LT_USERNAME\"]\naccess_key = os.environ[\"LT_ACCESS_KEY\"]\n\ncapabilities = {\n \"browserName\": \"Chrome\",\n \"browserVersion\": \"latest\",\n \"LT:Options\": {\n \"platformName\": \"Windows 10\",\n \"build\": \"CDP Web Automation\",\n \"name\": \"Product Listing (Python)\",\n \"username\": username,\n \"accessKey\": access_key,\n },\n}\n\nendpoint = (\n f\"wss://{quote(username, safe='')}:{quote(access_key, safe='')}\"\n f\"@cdp.lambdatest.com/puppeteer?capabilities={quote(json.dumps(capabilities), safe='')}\"\n)\n\nBASE = \"https://ecommerce-playground.lambdatest.io/index.php?route=product/category&path=25\"\n\n\ndef set_status(page, status, remark):\n action = {\"action\": \"setTestStatus\", \"arguments\": {\"status\": status, \"remark\": remark}}\n page.evaluate(\"_ => {}\", \"lambdatest_action: \" + json.dumps(action))\n\n\nwith sync_playwright() as p:\n browser = p.chromium.connect_over_cdp(endpoint)\n context = browser.contexts[0]\n page = context.pages[0] if context.pages else context.new_page()\n try:\n page.goto(BASE, wait_until=\"domcontentloaded\")\n page.wait_for_selector(\".product-thumb\")\n names = page.locator(\".product-thumb .caption .title a\").all_inner_texts()\n print(f\"Found {len(names)} products\")\n for name in names[:3]:\n print(name.strip())\n # Mark the test as passed on the TestMu AI dashboard\n set_status(page, \"passed\", f\"Found {len(names)} products\")\n except Exception as e:\n # Mark the test as failed so the dashboard reflects the real outcome\n set_status(page, \"failed\", str(e))\n raise\n finally:\n browser.close()" + }, + { + "@type": "SoftwareSourceCode", + "name": "Run the Same CDP Test in Python With Playwright", + "codeSampleType": "code snippet", + "programmingLanguage": "Shell", + "text": "python cdp_test.py" + }, { "@type": "SoftwareSourceCode", "name": "Running Web Automation With CDP From an AI Agent", @@ -176,7 +197,7 @@ import VerifiedTag from '@site/src/component/verifiedTag'; "text": "Found 15 product images\nSaved product-1.jpg (HTC Touch HD)\nSaved product-2.jpg (Palm Treo Pro)\nSaved product-3.jpg (Canon EOS 5D)\nSaved product-4.jpg (Nikon D300)\nSaved product-5.jpg (iPod Touch)" } ], - "dateModified": "2026-08-17T11:11:51+05:30" + "dateModified": "2026-12-04T19:05:00+05:30" }) }} /> @@ -210,6 +231,8 @@ Puppeteer is a CDP client. It connects to a TestMu AI cloud browser over a CDP W These examples are written in TypeScript. You're free to use plain JavaScript instead (remove the type annotations and save the file as `.js`), or connect over CDP from any other language your stack supports. The connection flow is the same. ::: +Other CDP tools connect to the same `wss://cdp.lambdatest.com/puppeteer` endpoint: Playwright through `connect_over_cdp` ([Python example below](#run-the-same-cdp-test-in-python-with-playwright)), [Playwright CLI and Playwright MCP](/support/docs/browser-cloud-playwright-cli-mcp/), [Browser Use](/support/docs/browser-cloud-browser-use/), and the open-source agent-browser CLI from Vercel Labs, so you can also [run agent-browser over CDP](https://www.testmuai.com/agent-browser/#agent-browser-skill). + **1. Install the Puppeteer client.** `puppeteer-core` connects to a remote browser without downloading a local one. @@ -377,6 +400,87 @@ To view your test results, navigate to the TestMu AI Web Automation dashboard. CDP test execution on TestMu AI +### Run the Same CDP Test in Python With Playwright + +Playwright for Python connects to the same endpoint with `connect_over_cdp`. This script builds the endpoint the same way as `cdp-test.ts`, reads your credentials from the `LT_USERNAME` and `LT_ACCESS_KEY` environment variables you set in step 2, reads the first page of the product listing, and marks the test **passed** or **failed** on the dashboard. + +**1. Install Playwright for Python.** It needs Python 3.10 or later. + +```bash +pip install playwright +``` + +**2. Create `cdp_test.py`.** + +```python title="cdp_test.py" +# cdp_test.py +import json +import os +from urllib.parse import quote + +from playwright.sync_api import sync_playwright + +username = os.environ["LT_USERNAME"] +access_key = os.environ["LT_ACCESS_KEY"] + +capabilities = { + "browserName": "Chrome", + "browserVersion": "latest", + "LT:Options": { + "platformName": "Windows 10", + "build": "CDP Web Automation", + "name": "Product Listing (Python)", + "username": username, + "accessKey": access_key, + }, +} + +endpoint = ( + f"wss://{quote(username, safe='')}:{quote(access_key, safe='')}" + f"@cdp.lambdatest.com/puppeteer?capabilities={quote(json.dumps(capabilities), safe='')}" +) + +BASE = "https://ecommerce-playground.lambdatest.io/index.php?route=product/category&path=25" + + +def set_status(page, status, remark): + action = {"action": "setTestStatus", "arguments": {"status": status, "remark": remark}} + page.evaluate("_ => {}", "lambdatest_action: " + json.dumps(action)) + + +with sync_playwright() as p: + browser = p.chromium.connect_over_cdp(endpoint) + context = browser.contexts[0] + page = context.pages[0] if context.pages else context.new_page() + try: + page.goto(BASE, wait_until="domcontentloaded") + page.wait_for_selector(".product-thumb") + names = page.locator(".product-thumb .caption .title a").all_inner_texts() + print(f"Found {len(names)} products") + for name in names[:3]: + print(name.strip()) + # Mark the test as passed on the TestMu AI dashboard + set_status(page, "passed", f"Found {len(names)} products") + except Exception as e: + # Mark the test as failed so the dashboard reflects the real outcome + set_status(page, "failed", str(e)) + raise + finally: + browser.close() +``` + +:::warning +The endpoint contains your access key. Build it from environment variables when the script runs, and keep it out of logs and version control. +::: + +**3. Run it:** + +```bash +python cdp_test.py +``` + +The session appears on the TestMu AI Web Automation dashboard under the build **CDP Web Automation**. + ## Running Web Automation With CDP From an AI Agent ***