|
1 | | -# ai-authoring-automate-demo-browserstack |
2 | | -AI Authoring Automate Demo Repository for Browserstack |
| 1 | +# AI Authoring Agent-Automate Demo for Web (BrowserStack) |
| 2 | + |
| 3 | +[TestNG](http://testng.org) Integration with BrowserStack. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## What Does This Repo Do? |
| 8 | + |
| 9 | +This repository showcases the use of **BrowserStack's AI Authoring Agent** for web automation using TestNG. The key feature is the ability to write test steps in **Natural Language (Plain English)**, moving away from explicit Selenium locators and actions. |
| 10 | + |
| 11 | +It contains a demo script: |
| 12 | +* **`BstackAIAuthoring.java`**: Runs complex test objectives (like selecting a product in a specific price range or navigating to a quote page) using simple English commands. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## How It Works |
| 17 | + |
| 18 | +1. **Enablement:** The feature is enabled by declaring the capability `aiAuthoring: true` in your `browserstack.yml` configuration file. |
| 19 | +2. **The Command:** Inside the test script (`BstackAIAuthoring.java`), the test uses a standard Selenium `JavascriptExecutor` to pass the Natural Language instruction to the BrowserStack environment: |
| 20 | + ```java |
| 21 | + // Example Objective: Find Google Pixel 3 phone on the website and add 5 of them to the cart |
| 22 | + jse.executeScript("browserstack_executor: {\"action\": \"ai\", \"arguments\": [\" Click on the Google button and Add 5 Pixel 3 phones to cart\"]}"); |
| 23 | + ``` |
| 24 | +3. **Execution:** The BrowserStack AI Agent intercepts this command, interprets the natural language, and executes the equivalent low-level Selenium actions on the target web page. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Running the Tests |
| 29 | + |
| 30 | +### Using Maven |
| 31 | + |
| 32 | +#### Run sample build |
| 33 | + |
| 34 | +- Clone the repository |
| 35 | +- Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` with your BrowserStack access credentials in `browserstack.yml`. |
| 36 | +- Declare capability **`aiAuthoring: true`** in `browserstack.yml` file (if not already present). |
| 37 | +- Install dependencies `mvn compile` |
| 38 | +- To run the test suite having cross-platform with parallelization, run **`mvn test -P sample-test`**. |
| 39 | +- To run local tests, run **`mvn test -P sample-local-test`**. |
| 40 | + |
| 41 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github). |
| 42 | + |
| 43 | +#### Integrate your test suite |
| 44 | + |
| 45 | +* Add maven dependency of `browserstack-java-sdk` in your `pom.xml` file: |
| 46 | + ```xml |
| 47 | + <dependency> |
| 48 | + <groupId>com.browserstack</groupId> |
| 49 | + <artifactId>browserstack-java-sdk</artifactId> |
| 50 | + <version>LATEST</version> |
| 51 | + <scope>compile</scope> |
| 52 | + </dependency> |
| 53 | + ``` |
| 54 | +* Modify your build plugin to run tests by adding `argLine -javaagent:${com.browserstack:browserstack-java-sdk:jar}` in the Surefire plugin configuration. |
| 55 | +* Install dependencies `mvn compile`. |
| 56 | + |
| 57 | +### Using Gradle |
| 58 | + |
| 59 | +#### Prerequisites |
| 60 | + |
| 61 | +- If using Gradle, Java v9+ is required. |
| 62 | + |
| 63 | +#### Run sample build |
| 64 | + |
| 65 | +- Clone the repository |
| 66 | +- Install dependencies `gradle build` |
| 67 | +- To run the test suite having cross-platform with parallelization, run **`gradle sampleTest`**. |
| 68 | +- To run local tests, run **`gradle sampleLocalTest`**. |
| 69 | + |
| 70 | +#### Integrate your test suite |
| 71 | + |
| 72 | +* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies in your `gradle.build`. |
| 73 | +* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest*. |
| 74 | +* Install dependencies `gradle build`. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Notes |
| 79 | + |
| 80 | +* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate). |
| 81 | +* For detailed documentation on general Selenium and Java setup with BrowserStack Automate, please refer to the [official documentation](https://www.browserstack.com/docs/automate/selenium?fw-lang=java). |
0 commit comments