diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..d5aff27 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..64cfb96 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..a156f52 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a468a99 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..60add33 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 747aeeb..fd4f888 100644 --- a/README.md +++ b/README.md @@ -1,238 +1,238 @@ -# Java With Appium ![pw](https://img.shields.io/badge/Java-ED8B00?style=for-the-badge&logo=java&logoColor=white) - -

- -

- -

- Blog -   ⋅   - Docs -   ⋅   - Learning Hub -   ⋅   - Newsletter -   ⋅   - Certifications -   ⋅   - YouTube -

-  -  -  - -_Appium is a tool for automating native, mobile web, and hybrid applications on iOS, Android, and Windows platforms. It supports iOS native apps written in Objective-C or Swift and Android native apps written in Java or Kotlin. It also supports mobile web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in 'Browser' app on Android). Perform Appium automation tests on [LambdaTest's online cloud](https://www.lambdatest.com/appium-mobile-testing)._ - -_Learn the basics of [Appium testing on the LambdaTest platform](https://www.lambdatest.com/support/docs/getting-started-with-appium-testing/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java)._ - -[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) - -## Table of Contents - -- [Pre-requisites](#pre-requisites) -- [Run Your First Test](#run-your-first-test) -- [Executing The Test](#executing-the-test) - -## Pre-requisites - -Before you can start performing App automation testing with Appium, you would need to follow these steps: - -- Ensure you have the [Java client library](https://github.com/appium/java-client) installed for Selenium and Appium. -- Download and install **Maven** following the steps from [the official website](https://maven.apache.org/). Maven can also be installed easily on **Linux/MacOS** using [**Homebrew**](https://brew.sh/) package manager. - -### Clone The Sample Project - -Clone the LambdaTest’s :link: [LT-appium-java](https://github.com/LambdaTest/LT-appium-java) repository and navigate to the code directory as shown below: - -```bash -git clone https://github.com/LambdaTest/LT-appium-java -cd LT-appium-java -``` - -### Setting Up Your Authentication - -Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest. To obtain your access credentials, [purchase a plan](https://billing.lambdatest.com/billing/plans?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) or access the [Automation Dashboard](https://appautomation.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). - -Set LambdaTest `Username` and `Access Key` in environment variables. - -**For Linux/macOS:** - -```bash -export LT_USERNAME="YOUR_LAMBDATEST_USERNAME" \ -export LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY" -``` - -**For Windows:** - -```bash -set LT_USERNAME="YOUR_LAMBDATEST_USERNAME" \ -set LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY" -``` - -### Upload Your Application - -Upload your **_iOS_** application (.ipa file) or **_android_** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API: - -**Using App File:** - -**Linux/macOS:** - -```bash -curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ ---location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ ---form 'name="Android_App"' \ ---form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' -``` - -**Windows:** - -```bash -curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"/Users/macuser/Downloads/proverbial_android.apk"" -``` - -**Using App URL:** - -**Linux/macOS:** - -```bash -curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ ---location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ ---form 'name="Android_App"' \ ---form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"' -``` - -**Windows:** - -```bash -curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -d "{"url":"https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk","name":"sample.apk"}" -``` - -**Tip:** - -- If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). -- Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step. - -## Run Your First Test - -**Test Scenario:** Check out [vanila_android.java](https://github.com/LambdaTest/LT-appium-java/blob/master/src/test/java/vanilla_android.java) file to view the sample test script for android and [vanilla_ios.java](https://github.com/LambdaTest/LT-appium-java/blob/master/src/test/java/vanilla_ios.java) for iOS. - -### Configuring Your Test Capabilities - -You can update your custom capabilities in test scripts. In this sample project, we are passing platform name, platform version, device name and app url (generated earlier) along with other capabilities like build name and test name via capabilities object. The capabilities object in the sample code are defined as: - - - - -```java -DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("deviceName", "Galaxy S20"); - capabilities.setCapability("platformVersion", "11"); - capabilities.setCapability("platformName", "Android"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("app", "YOUR_APP_URL"); //Enter your app url - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("build", "Java Vanilla - iOS"); - capabilities.setCapability("name", "Sample Test Java"); - capabilities.setCapability("console", true); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("devicelog", true); -``` - - - - - -```java -DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platformVersion", "15"); - caps.setCapability("deviceName", "iPhone 12"); - caps.setCapability("isRealMobile", true); - caps.setCapability("app", "YOUR_APP_URL"); //Enter your app url - caps.setCapability("platformName", "iOS"); - caps.setCapability("build", "Java Vanilla - iOS"); - caps.setCapability("name", "Sample Test Java"); - caps.setCapability("devicelog", true); - caps.setCapability("network", true); -``` - - - - - -**Note:** - -- You must add the generated **APP_URL** to the `"app"` capability in the config file. -- You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/beta/index.html?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java)**. A more Detailed Capability Guide is available [here](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). - -## Executing The Test - -Execute the following commands to install the required dependencies: - -```bash -mvn clean install -``` - -The tests can be executed in the terminal using the following command: - -**Android:** - -```bash -mvn test -P android -``` - -**iOS:** - -```bash -mvn test -P ios -``` - -**Info:** Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the :link: [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). - -## Additional Links - -- [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) -- [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) -- [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) - -## Documentation & Resources :books: - -Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. - -- [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) -- [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) -- [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) - -## LambdaTest Community :busts_in_silhouette: - -The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 - -## What's New At LambdaTest ❓ - -To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) - -## About LambdaTest - -[LambdaTest](https://www.lambdatest.com?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. - -### Features - -- Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. -- Real-time cross browser testing on 3000+ environments. -- Test on Real device cloud -- Blazing fast test automation with HyperExecute -- Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. -- Smart Visual Regression Testing on cloud -- 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. -- Automated Screenshot testing across multiple browsers in a single click. -- Local testing of web and mobile apps. -- Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. -- Geolocation testing of web and mobile apps across 53+ countries. -- LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports - -[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) - -## We are here to help you :headphones: - -- Got a query? we are available 24x7 to help. [Contact Us](mailto:support@lambdatest.com) -- For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) +# Java With Appium ![pw](https://img.shields.io/badge/Java-ED8B00?style=for-the-badge&logo=java&logoColor=white) + +

+ +

+ +

+ Blog +   ⋅   + Docs +   ⋅   + Learning Hub +   ⋅   + Newsletter +   ⋅   + Certifications +   ⋅   + YouTube +

+  +  +  + +_Appium is a tool for automating native, mobile web, and hybrid applications on iOS, Android, and Windows platforms. It supports iOS native apps written in Objective-C or Swift and Android native apps written in Java or Kotlin. It also supports mobile web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in 'Browser' app on Android). Perform Appium automation tests on [LambdaTest's online cloud](https://www.lambdatest.com/appium-mobile-testing)._ + +_Learn the basics of [Appium testing on the LambdaTest platform](https://www.lambdatest.com/support/docs/getting-started-with-appium-testing/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java)._ + +[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) + +## Table of Contents + +- [Pre-requisites](#pre-requisites) +- [Run Your First Test](#run-your-first-test) +- [Executing The Test](#executing-the-test) + +## Pre-requisites + +Before you can start performing App automation testing with Appium, you would need to follow these steps: + +- Ensure you have the [Java client library](https://github.com/appium/java-client) installed for Selenium and Appium. +- Download and install **Maven** following the steps from [the official website](https://maven.apache.org/). Maven can also be installed easily on **Linux/MacOS** using [**Homebrew**](https://brew.sh/) package manager. + +### Clone The Sample Project + +Clone the LambdaTest’s :link: [LT-appium-java](https://github.com/LambdaTest/LT-appium-java) repository and navigate to the code directory as shown below: + +```bash +git clone https://github.com/LambdaTest/LT-appium-java +cd LT-appium-java +``` + +### Setting Up Your Authentication + +Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest. To obtain your access credentials, [purchase a plan](https://billing.lambdatest.com/billing/plans?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) or access the [Automation Dashboard](https://appautomation.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). + +Set LambdaTest `Username` and `Access Key` in environment variables. + +**For Linux/macOS:** + +```bash +export LT_USERNAME="YOUR_LAMBDATEST_USERNAME" \ +export LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY" +``` + +**For Windows:** + +```bash +set LT_USERNAME="YOUR_LAMBDATEST_USERNAME" \ +set LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY" +``` + +### Upload Your Application + +Upload your **_iOS_** application (.ipa file) or **_android_** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API: + +**Using App File:** + +**Linux/macOS:** + +```bash +curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ +--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ +--form 'name="Android_App"' \ +--form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' +``` + +**Windows:** + +```bash +curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"/Users/macuser/Downloads/proverbial_android.apk"" +``` + +**Using App URL:** + +**Linux/macOS:** + +```bash +curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ +--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ +--form 'name="Android_App"' \ +--form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"' +``` + +**Windows:** + +```bash +curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -d "{"url":"https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk","name":"sample.apk"}" +``` + +**Tip:** + +- If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). +- Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step. + +## Run Your First Test + +**Test Scenario:** Check out [vanila_android.java](https://github.com/LambdaTest/LT-appium-java/blob/master/src/test/java/vanilla_android.java) file to view the sample test script for android and [vanilla_ios.java](https://github.com/LambdaTest/LT-appium-java/blob/master/src/test/java/vanilla_ios.java) for iOS. + +### Configuring Your Test Capabilities + +You can update your custom capabilities in test scripts. In this sample project, we are passing platform name, platform version, device name and app url (generated earlier) along with other capabilities like build name and test name via capabilities object. The capabilities object in the sample code are defined as: + + + + +```java +DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability("deviceName", "Galaxy S20"); + capabilities.setCapability("platformVersion", "11"); + capabilities.setCapability("platformName", "Android"); + capabilities.setCapability("isRealMobile", true); + capabilities.setCapability("app", "YOUR_APP_URL"); //Enter your app url + capabilities.setCapability("deviceOrientation", "PORTRAIT"); + capabilities.setCapability("build", "Java Vanilla - iOS"); + capabilities.setCapability("name", "Sample Test Java"); + capabilities.setCapability("console", true); + capabilities.setCapability("network", false); + capabilities.setCapability("visual", true); + capabilities.setCapability("devicelog", true); +``` + + + + + +```java +DesiredCapabilities caps = new DesiredCapabilities(); + caps.setCapability("platformVersion", "15"); + caps.setCapability("deviceName", "iPhone 12"); + caps.setCapability("isRealMobile", true); + caps.setCapability("app", "YOUR_APP_URL"); //Enter your app url + caps.setCapability("platformName", "iOS"); + caps.setCapability("build", "Java Vanilla - iOS"); + caps.setCapability("name", "Sample Test Java"); + caps.setCapability("devicelog", true); + caps.setCapability("network", true); +``` + + + + + +**Note:** + +- You must add the generated **APP_URL** to the `"app"` capability in the config file. +- You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/beta/index.html?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java)**. A more Detailed Capability Guide is available [here](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). + +## Executing The Test + +Execute the following commands to install the required dependencies: + +```bash +mvn clean install +``` + +The tests can be executed in the terminal using the following command: + +**Android:** + +```bash +mvn test -P android +``` + +**iOS:** + +```bash +mvn test -P ios +``` + +**Info:** Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the :link: [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java). + +## Additional Links + +- [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) +- [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) +- [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) + +## Documentation & Resources :books: + +Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. + +- [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) +- [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) +- [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) + +## LambdaTest Community :busts_in_silhouette: + +The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 + +## What's New At LambdaTest ❓ + +To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) + +## About LambdaTest + +[LambdaTest](https://www.lambdatest.com?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. + +### Features + +- Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. +- Real-time cross browser testing on 3000+ environments. +- Test on Real device cloud +- Blazing fast test automation with HyperExecute +- Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. +- Smart Visual Regression Testing on cloud +- 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. +- Automated Screenshot testing across multiple browsers in a single click. +- Local testing of web and mobile apps. +- Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. +- Geolocation testing of web and mobile apps across 53+ countries. +- LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports + +[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) + +## We are here to help you :headphones: + +- Got a query? we are available 24x7 to help. [Contact Us](mailto:support@lambdatest.com) +- For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java) diff --git a/pom.xml b/pom.xml index 8e2731f..d415dde 100644 --- a/pom.xml +++ b/pom.xml @@ -1,170 +1,176 @@ - - - 4.0.0 - - - App - AppTesting - 1.0-SNAPSHOT - - - UTF-8 - - - - - - - - org.seleniumhq.selenium - selenium-java - 3.141.59 - - - - - com.github.lambdatest - lambdatest-tunnel-binary - 1.0.10 - - - - - io.github.bonigarcia - webdrivermanager - 4.3.1 - - - commons-io - commons-io - 2.11.0 - - - org.seleniumhq.selenium - selenium-support - 2.52.0 - - - io.appium - java-client - 7.6.0 - - - org.testng - testng - 7.6.1 - - - commons-lang - commons-lang - 2.6 - - - - org.apache.commons - commons-lang3 - 3.0 - - - - info.cukes - cucumber-java - 1.2.5 - - - - junit - junit - 4.12 - test - - - org.json - json - 20160810 - - - org.seleniumhq.selenium - selenium-remote-driver - 3.141.59 - - - io.rest-assured - rest-assured - 4.3.0 - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - - - - - - android - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - vanilla_android - test - - - - - - - - - - ios - - - - org.codehaus.mojo - exec-maven-plugin - 1.1.1 - - - test - - java - - - vanilla_ios - test - - - - - - - - - - + + + + 4.0.0 + + org.example + AppTest + 1.0-SNAPSHOT + + + UTF-8 + 22 + ${java.version} + ${java.version} + + + + + org.seleniumhq.selenium + selenium-java + 4.27.0 + + + + io.appium + java-client + 9.3.0 + + + + org.testng + testng + 7.10.2 + compile + + + + com.konghq + unirest-java + 3.14.5 + + + + org.json + json + 20240303 + + + + org.webjars.npm + xmlhttprequest-ssl + 2.1.2 + + + + org.slf4j + slf4j-simple + 2.0.13 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + ${java.version} + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.2 + + + true + + + + + + + + + android-single + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/android-single.xml + + + + + + + + + android-app-profiling + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/android-app-profiling.xml + + + + + + + + + android-parallel + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/android-parallel.xml + + + + + + + + + ios-single + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/ios-single.xml + + + + + + + + + ios-parallel + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/java/ios-parallel.xml + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/vanilla_android.java b/src/test/java/vanilla_android.java index 6009380..c3ed6a9 100644 --- a/src/test/java/vanilla_android.java +++ b/src/test/java/vanilla_android.java @@ -1,91 +1,97 @@ -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + import java.net.MalformedURLException; import java.net.URL; +import java.util.HashMap; public class vanilla_android { - public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" // Add username here - : System.getenv("LT_USERNAME"); - public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" // Add accessKey here - : System.getenv("LT_ACCESS_KEY"); - - private static AppiumDriver driver; - public static void main(String args[]) throws MalformedURLException, InterruptedException { + public static String userName = System.getenv("LT_USERNAME") == null ? "utkarshblambdatest" : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACTUAL_KEY" : System.getenv("LT_ACCESS_KEY"); + + public AndroidDriver driver; + + @BeforeTest + public void setup() throws MalformedURLException { + DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap(); + + ltOptions.put("deviceName", "Galaxy.*"); + ltOptions.put("platformVersion", "14"); + ltOptions.put("platformName", "Android"); + ltOptions.put("isRealMobile", true); + ltOptions.put("app", "lt://APP1016055391769006462699400"); + ltOptions.put("deviceOrientation", "PORTRAIT"); + ltOptions.put("build", "Java Vanilla - Android"); + ltOptions.put("name", "Sample Test Java"); + ltOptions.put("console", true); + ltOptions.put("autoGrantPermissions", true); + ltOptions.put("visual", true); + ltOptions.put("devicelog", true); + + capabilities.setCapability("lt:options", ltOptions); + + String hub = "https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"; + driver = new AndroidDriver(new URL(hub), capabilities); + } + @Test + public void basicTest() throws InterruptedException { try { - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("deviceName", "Galaxy S20"); - capabilities.setCapability("platformVersion", "11"); - capabilities.setCapability("platformName", "Android"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("app", "APP_URL"); // Enter your app url - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("build", "Java Vanilla - Android"); - capabilities.setCapability("name", "Sample Test Java"); - capabilities.setCapability("console", true); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("devicelog", true); - - driver = new AppiumDriver( - new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), - capabilities); - - MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color")); + // Updated to AppiumBy.id + WebElement color = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/color")); color.click(); - MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text")); - // Changes the text to proverbial + WebElement text = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/Text")); text.click(); - // toast is visible - MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast")); + WebElement toast = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/toast")); toast.click(); - // notification is visible - MobileElement notification = (MobileElement) driver - .findElement(MobileBy.id("com.lambdatest.proverbial:id/notification")); + WebElement notification = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/notification")); notification.click(); - // Open the geolocation page - MobileElement geo = (MobileElement) driver - .findElement(MobileBy.id("com.lambdatest.proverbial:id/geoLocation")); + WebElement geo = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/geoLocation")); geo.click(); Thread.sleep(5000); - // takes back to home page - MobileElement el3 = (MobileElement) driver.findElementByAccessibilityId("Home"); - driver.navigate().back(); Thread.sleep(2000); - // Takes to speed test page - MobileElement speedtest = (MobileElement) driver - .findElement(MobileBy.id("com.lambdatest.proverbial:id/speedTest")); + WebElement speedtest = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/speedTest")); speedtest.click(); Thread.sleep(5000); driver.navigate().back(); - // Opens the browser - MobileElement browser = (MobileElement) driver.findElement(MobileBy.AccessibilityId("Browser")); + // Updated to AppiumBy.accessibilityId (note the lowercase 'a') + WebElement browser = driver.findElement(AppiumBy.accessibilityId("Browser")); browser.click(); - MobileElement url = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/url")); + WebElement url = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/url")); url.sendKeys("https://www.lambdatest.com"); - MobileElement find = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/find")); + + WebElement find = driver.findElement(AppiumBy.id("com.lambdatest.proverbial:id/find")); find.click(); - } catch (AssertionError a) { + ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); + } catch (Exception e) { ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); - a.printStackTrace(); + e.printStackTrace(); + } + } + + @AfterTest + public void tearDown() { + if (driver != null) { + driver.quit(); } - // The driver.quit statement is required, otherwise the test continues to - // execute, leading to a timeout. - driver.quit(); } -} +} \ No newline at end of file diff --git a/src/test/java/vanilla_ios.java b/src/test/java/vanilla_ios.java index cb51dd4..bbf8556 100644 --- a/src/test/java/vanilla_ios.java +++ b/src/test/java/vanilla_ios.java @@ -1,100 +1,77 @@ -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; +import io.appium.java_client.AppiumBy; import io.appium.java_client.ios.IOSDriver; - +import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; - import java.net.URL; +import java.time.Duration; +import java.util.HashMap; public class vanilla_ios { - public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" // Add username here - : System.getenv("LT_USERNAME"); - public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" // Add accessKey here - : System.getenv("LT_ACCESS_KEY"); + public static String userName = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" : System.getenv("LT_USERNAME"); + public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); - public static final String URL = "https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"; public static IOSDriver driver = null; public static void main(String[] args) throws Exception { try { DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability("platformVersion", "15"); - caps.setCapability("deviceName", "iPhone 12"); - caps.setCapability("isRealMobile", true); - caps.setCapability("app", "APP_URL"); // Enter your app url - caps.setCapability("platformName", "iOS"); - caps.setCapability("build", "Java Vanilla - iOS"); - caps.setCapability("name", "Sample Test Java"); - caps.setCapability("devicelog", true); - caps.setCapability("network", false); + HashMap ltOptions = new HashMap(); + + ltOptions.put("w3c", true); + ltOptions.put("platformName", "iOS"); + ltOptions.put("deviceName", "iPhone.*"); // Updated to a newer model for better stability + ltOptions.put("platformVersion", "17"); + ltOptions.put("isRealMobile", true); + ltOptions.put("app", "lt://APP1016018631760361477812757"); // Use your iOS App URL + ltOptions.put("build", "Java Vanilla - iOS"); + ltOptions.put("name", "Sample Test Java iOS"); + ltOptions.put("devicelog", true); + ltOptions.put("autoAcceptAlerts", true); + ltOptions.put("network", false); + ltOptions.put("visual", true); + + caps.setCapability("lt:options", ltOptions); driver = new IOSDriver( new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), caps); - Thread.sleep(2000); - - // Changes color + // Wait utility + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); - driver.findElement(MobileBy.id("color")).click(); - Thread.sleep(1000); - - // Back to black color - driver.navigate().back(); + // 1. Changes color + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("color"))).click(); - Thread.sleep(1000); + // 2. Changes the text + driver.findElement(AppiumBy.id("Text")).click(); - // Changes the text to proverbial - driver.findElement(MobileBy.id("Text")).click(); - Thread.sleep(1000); + // 3. Toast + driver.findElement(AppiumBy.id("toast")).click(); - // toast is visible - driver.findElement(MobileBy.id("toast")).click(); - Thread.sleep(1000); + // 4. Notification + driver.findElement(AppiumBy.id("notification")).click(); +// Thread.sleep(2000); - // notification is visible - driver.findElement(MobileBy.id("notification")).click(); - Thread.sleep(2000); - - // Open the geolocation page - driver.findElement(MobileBy.id("geoLocation")).click(); - Thread.sleep(4000); - driver.navigate().back(); - Thread.sleep(1000); - - // Takes to speed test page - driver.findElement(MobileBy.id("speedTest")).click(); + // 5. Geolocation + driver.findElement(AppiumBy.id("geoLocation")).click(); Thread.sleep(5000); driver.navigate().back(); - Thread.sleep(1000); - // Opens the browser - MobileElement browser = (MobileElement) driver.findElementByAccessibilityId("Browser"); - browser.click(); - Thread.sleep(3000); - WebDriverWait el7 = new WebDriverWait(driver, 30); - el7.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))); - driver.findElementById("url").sendKeys("https://www.lambdatest.com/"); - // Clicks on the text box - WebDriverWait el = new WebDriverWait(driver, 90); - MobileElement el4 = (MobileElement) driver.findElementByAccessibilityId("find"); - el.until(ExpectedConditions.elementToBeClickable(el4)); - el4.click(); - el4.sendKeys("Lambdatest"); - // ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); - driver.quit(); } catch (Exception t) { - System.out.println(t); - driver.quit(); - + System.out.println("Test Failed: " + t.getMessage()); + t.printStackTrace(); + } finally { + if (driver != null) { + driver.quit(); + } } } -} +} \ No newline at end of file diff --git a/target/AppTest-1.0-SNAPSHOT.jar b/target/AppTest-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..d588108 Binary files /dev/null and b/target/AppTest-1.0-SNAPSHOT.jar differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..cb7c04a --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=AppTest +groupId=org.example +version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..9d6976f --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1,2 @@ +vanilla_ios.class +vanilla_android.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..5b2224a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1,2 @@ +/Users/utkarshb/Downloads/Repos/LT-appium-java-ADO/src/test/java/vanilla_android.java +/Users/utkarshb/Downloads/Repos/LT-appium-java-ADO/src/test/java/vanilla_ios.java diff --git a/target/test-classes/vanilla_android.class b/target/test-classes/vanilla_android.class new file mode 100644 index 0000000..3d0c5b3 Binary files /dev/null and b/target/test-classes/vanilla_android.class differ diff --git a/target/test-classes/vanilla_ios.class b/target/test-classes/vanilla_ios.class new file mode 100644 index 0000000..c16dc70 Binary files /dev/null and b/target/test-classes/vanilla_ios.class differ