This repository demonstrates how to use BrowserStack's Cross Browser AI Authoring (CBAA) with Python and Selenium. It executes Gherkin-based feature scenarios on BrowserStack's infrastructure, leveraging AI to interpret and execute natural language steps.
- Python 3.x: Ensure Python 3 is installed on your system.
- BrowserStack Account: You need a BrowserStack username and access key. Sign up for a free trial if you don't have one, and connect with your Account Manager to enable Cross Browser AI Authoring.
-
Clone the repository:
git clone <repository-url> cd cbaa-demo
-
Create and activate a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install dependencies:
This project requires
selenium,gherkin-official, andpython-dotenv.pip install -r requirements.txt pip install python-dotenv
-
Configure Environment Variables:
Create a
.envfile in the root directory of the project and add your BrowserStack credentials:BROWSERSTACK_USERNAME=your_username BROWSERSTACK_ACCESS_KEY=your_access_key
cbaa.py: The main entry point script. It initializes the Selenium driver with BrowserStack options, parses feature files, and executes scenarios using a thread pool.features/: Contains Gherkin.featurefiles defining the test scenarios.purchase.feature: A sample e-commerce purchase scenario.
utils/: Helper utilities.parse_feature.py: Parses Gherkin feature files and "hydrates" them with examples (replaces placeholders with actual data).
browserstack.yml: Configuration file for BrowserStack SDK (reference).requirements.txt: List of Python dependencies.
To run the AI-authored tests, execute the cbaa.py script:
python cbaa.py- The script reads
features/purchase.feature. - It parses the scenarios and replaces placeholders (e.g.,
<Category>,<Email>) with the values from theExamplestable. - For each scenario iteration, it spawns a thread.
- Each thread starts a Selenium session on BrowserStack.
- Steps are executed using
browserstack_executorwith theaiaction, allowing the AI to interpret natural language commands like "Click on the 'Men' category". - Results are reported back to BrowserStack.
- Ensure your BrowserStack plan supports the number of parallel threads you intend to run.
- The
aiAuthoring: "true"capability is critical for enabling the AI features.