{"id":15021981,"url":"https://github.com/testdotai/java-selenium-sdk-demo","last_synced_at":"2025-04-10T23:50:58.528Z","repository":{"id":102291459,"uuid":"459880495","full_name":"testdotai/java-selenium-sdk-demo","owner":"testdotai","description":"🎊 A demo/tutorial for java-selenium-sdk","archived":false,"fork":false,"pushed_at":"2022-03-11T07:04:09.000Z","size":67,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-24T20:38:17.212Z","etag":null,"topics":["ai","geckodriver","google-chrome","java","safaridriver","selenium","selenium-java","selenium-webdriver","test-ai"],"latest_commit_sha":null,"homepage":"https://sdk.test.ai/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testdotai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-16T06:29:43.000Z","updated_at":"2023-10-10T11:13:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"666723d4-65c8-490e-af6d-41d35528cf49","html_url":"https://github.com/testdotai/java-selenium-sdk-demo","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"529dc3f59b52125837a2c7e7dc55e9c523c3cf84"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fjava-selenium-sdk-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fjava-selenium-sdk-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fjava-selenium-sdk-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fjava-selenium-sdk-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testdotai","download_url":"https://codeload.github.com/testdotai/java-selenium-sdk-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317707,"owners_count":21083528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","geckodriver","google-chrome","java","safaridriver","selenium","selenium-java","selenium-webdriver","test-ai"],"created_at":"2024-09-24T19:57:17.601Z","updated_at":"2025-04-10T23:50:58.510Z","avatar_url":"https://github.com/testdotai.png","language":"Java","readme":"# test-ai-selenium-demo\n[![JDK-11+](https://img.shields.io/badge/JDK-11%2B-blue)](https://adoptium.net)\n[![Apache 2.0](https://img.shields.io/badge/Apache-2.0-blue)](https://www.apache.org/licenses/LICENSE-2.0)\n[![Discord](https://img.shields.io/discord/853669216880295946?\u0026logo=discord)](https://sdk.test.ai/discord)\n\nWelcome to the test.ai Selenium Java demo!\n\nThis repository contains a pre-configured project and basic tutorial, so you can hit the ground running with [test.ai enhanced Selenium](https://github.com/testdotai/java-selenium-sdk)!\n\n👉 This tutorial uses Google Chrome, but you will be able to use `test-ai-selenium` with any other browser that supports Selenium.\n\n## Pre-requisites\nBefore we get started, please ensure that you have installed the following software on your computer:\n\n* [Java](https://adoptium.net) - version `11` or newer\n* [Google Chrome](https://www.google.com/chrome/)\n\nYou will also need a test.ai account, please visit https://sdk.test.ai (it's free!) to register.\n\n## An Introduction to the test.ai SDK\nIn the following tutorial, you will learn how to set up and run AI-enhanced Selenium with test.ai.\n\nNow that you have the pre-requisites installed, let's get started.\n\nPlease begin by cloning this repository to your computer.\n```bash\ngit clone https://github.com/testdotai/java-selenium-sdk-demo.git\n```\n\n### Run the demo\nPlease visit https://sdk.test.ai, and log into your account.  Please copy your `API key` (in the upper right corner of your screen), you will need this for the next step.\n\n![Example API Key](https://testdotai.github.io/static-assets/appium-demo/api_key.png)\n\nNext, `cd` into the root directory of this repository and run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n```bash\n./gradlew run --args=YOUR_API_KEY\n```\n\nIf using Windows, please run\n```powershell\ngradlew.bat run --args=YOUR_API_KEY\n```\n\nIf everything worked, an instance of the Chrome browser will be started and open to the [test.ai Store](https://testaistore.com) (no, it's not a real store!).  Then, the sample code in this demo will click the `Store` navbar link, search for `Shoes`, and add a pair of green shoes to the cart.\n\n🎥 Click [here](https://testdotai.github.io/static-assets/selenium-demo/no_ai_example_flow.mov) to see a video of the expected behavior.\n\nThus far, the demo is using the standard Selenium selectors without any AI, which is how apps today are commonly tested.  However, selectors such as these are fragile and break easily, as even minor changes to a website may cause them to *immediately* stop working.  Fortunately, the test.ai SDK is equipped to help you avoid this unecessary hassle.\n\n### Using test.ai with Selenium\n\nPlease visit https://sdk.test.ai (and log in to your test.ai account if you've been logged out).\n\nYou should see the following new entries on this page:\n\n\u003cimg src=\"https://testdotai.github.io/static-assets/selenium-demo/element_list.png\" width=400\u003e\n\nnamely,\n* `store_nav_link`\n* `search_products_input`\n* `search_button`\n* `green_shoes`\n* `add_to_cart`\n\nStart by clicking on the link in the `Element` column for `store_nav_link`.\n\nOn this new page, find the navbar link `Store`.  Using your mouse, click and drag a box around the link.  A green box will appear as you drag your mouse.  Release your mouse button to save the selection.\n\n![store nav link demo](https://testdotai.github.io/static-assets/selenium-demo/store_nav_link.gif)\n\nBelieve it or not, you just used AI!  test.ai is visual-based, so there's no need to mess around with Selenium selectors.  The test.ai classifier will train itself using the element inside the box you just drew with your mouse, and now, when it encounters this element in the future, it will be able to recognize it!  \n\nLet's do the same thing for the other elements.\n\n#### `search_products_input`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![search products input demo](https://testdotai.github.io/static-assets/selenium-demo/search_products_input.gif)\n\u003c/details\u003e\n\n#### `search_button`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![search button demo](https://testdotai.github.io/static-assets/selenium-demo/search_button.gif)\n\u003c/details\u003e\n\n#### `green_shoes`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![green shoes demo](https://testdotai.github.io/static-assets/selenium-demo/green_shoes.gif)\n\u003c/details\u003e\n\n#### `add_to_cart`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![add to cart demo](https://testdotai.github.io/static-assets/selenium-demo/add_to_cart.gif)\n\u003c/details\u003e\n\n👉 Training takes a few minutes, you can check training status by visiting https://sdk.test.ai/training_status\n\n![training status](https://testdotai.github.io/static-assets/selenium-demo/training_status.png)\n\nNext, let's simulate what happens when a developer changes a web application's code.\n\nIn the IDE of your choice, please open [src/main/java/ai/test/sdk/demo/Example.java](src/main/java/ai/test/sdk/demo/Example.java).  This Java file contains an abridged form of what you might find in typical Selenium-based test suite.\n\nA few noteworthy items:\n* The `ChromeDriver` gets passed as a parameter to a `TestAiDriver`, along with your API key.\n* Each call to a \"`findElementsBy`\" method contains a second parameter, which is used to give the element an optional, human-readable label for use at https://sdk.test.ai\n\nAs you can see, it is very easy to integrate test.ai into your existing Selenium-based test cases.\n\nNow, let's change a couple of the XPath selectors:\n\n```java\n// Change this line:\nWebElement storeNavLink = driver.findElementById(\"menu-item-45\", \"store_nav_link\");\n\n//to:\nWebElement storeNavLink = driver.findElementById(\"my-developers-changed-this\", \"store_nav_link\");\n```\n\n```java\n// Change this line:\nWebElement searchProductsInput = driver.findElementByCssSelector(\"#woocommerce-product-search-field-0\", \"search_products_input\");\n\n// to:\nWebElement searchProductsInput = driver.findElementByCssSelector(\"#my-developers-also-changed-this\", \"search_products_input\");\n```\n\n```java\n// Change this line:\nWebElement addToCart = driver.findElementByXPath(\"//*[@id=\\\"product-2719\\\"]/div[2]/form/button\", \"add_to_cart\");\n\n// to:\nWebElement addToCart = driver.findElementByXPath(\"//*[wow/these/developers/have/been/busy]\", \"add_to_cart\");\n```\n\nAs you may have already guessed, a standard Selenium test would certainly fail, but test.ai won't!\n\n### Re-run using AI selectors\nUsing your terminal, `cd` into the root directory of this project, and run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n\n```bash\n./gradlew run --args=YOUR_API_KEY\n```\n\nIf using Windows, please run\n```powershell\ngradlew.bat run --args=YOUR_API_KEY\n```\n\nThe demo will repeat the same steps that it performed previously, only this time, it's using test.ai!  The \"developer's breaking changes\" we introduced in the code have no effect on the test's ability to run, all thanks to test.ai AI.\n\nAnd that's all folks, you've made it to the end of the tutorial!  🎉\n\nAs far as next steps go, please feel free to experiment more with this code and try out some of the other selectors.  Good luck and have fun!\n\n## Additional Resources\n* [API docs](https://www.javadoc.io/doc/ai.test.sdk/test-ai-selenium)\n* [Another Basic Tutorial](https://sdk.test.ai/tutorial)\n\n## Contact\nQuestions?  Comments?  We'd love to hear from you!\n\n* ✉️ Email us: `sdk {at} test.ai`\n* 💬 Chat with us on Discord: https://sdk.test.ai/discord","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdotai%2Fjava-selenium-sdk-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestdotai%2Fjava-selenium-sdk-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdotai%2Fjava-selenium-sdk-demo/lists"}