diff --git a/.gitignore b/.gitignore index 8fbdb55..c4a8251 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,28 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -.DS_Store -.DS_Store -/.idea/ -/target/ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.DS_Store +.DS_Store +/.idea/ +/target/ diff --git a/.idea/.gitignore b/.idea/.gitignore index 26d3352..eaf91e2 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,3 +1,3 @@ -# Default ignored files -/shelf/ -/workspace.xml +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c72376c..77ce06c 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,13 +1,13 @@ - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index 712ab9d..a468a99 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -1,20 +1,20 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index e24323e..9e0563e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,5 +8,5 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..c8397c9 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/README.md b/README.md index efbd527..fe2a5e2 100644 --- a/README.md +++ b/README.md @@ -1,248 +1,248 @@ -# JUnit With Appium ![pw](https://img.shields.io/badge/Junit5-25A162?style=for-the-badge&logo=junit5&logoColor=white) - -

- -

- -

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

-  -  -  - -_JUnit is a popular unit testing framework for Java, and was an important part of test-driven development. It belongs to a family of unit testing frameworks known as xUnit. Perform [JUnit test on LambdaTest's online cloud](https://www.lambdatest.com/appium-mobile-testing?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit)._ - -_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-junit)._ - -[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) - -## 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: - -- Make sure you have Appium’s [Java client library](https://github.com/appium/java-client) installed. - -### Clone The Sample Project - -Clone the LambdaTest’s :link: [LT-appium-java-junit](https://github.com/LambdaTest/LT-appium-java-junit) repository and navigate to the code directory as shown below: - -```bash -git clone https://github.com/LambdaTest/LT-appium-java-junit -cd LT-appium-java-junit -``` - -### 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-junit) or access the [Automation Dashboard](https://appautomation.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit). - -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:** - -**For 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"' -``` - -**For 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:** - -**For 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"' -``` - -**For 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 - -Once you are done with the above-mentioned steps, you can initiate your first JUnit test on LambdaTest. - -**Test Scenario**: Check out [android.java](https://github.com/LambdaTest/LT-appium-java-junit/blob/master/src/test/java/com/lambdatest/android.java) file to view the sample test script for android and [ios.java](https://github.com/LambdaTest/LT-appium-java-junit/blob/master/src/test/java/com/lambdatest/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("build", "JUNIT Native App automation"); - capabilities.setCapability("name", "Java JUnit Android Pixel 6"); - capabilities.setCapability("platformName", "android"); - capabilities.setCapability("deviceName", "Pixel 6"); //Enter the name of the device here - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("platformVersion","12"); - capabilities.setCapability("app","YOUR_APP_URL"); //Enter the App ID here - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("console",true); - capabilities.setCapability("network",true); - capabilities.setCapability("visual",true); -``` - - - - - -```java -DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("build", "JUNIT Native App automation"); - capabilities.setCapability("name", "Java JUnit iOS iPhone 12"); - capabilities.setCapability("platformName", "ios"); - capabilities.setCapability("deviceName", "iPhone 12"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("platformVersion","15"); - capabilities.setCapability("app","YOUR_APP_URL"); //Enter the APP_ID here - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("console",true); - capabilities.setCapability("network",true); - capabilities.setCapability("visual",true); -``` - - - - - -**Info 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-junit)**. 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-junit). - -## Executing The Test - -Execute the following commands to install the required dependencies: - -```bash -mvn clean -``` - -The tests can be executed in the terminal using the following command: - - - - -```bash -mvn test -P android -``` - - - - - -```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-junit). - -## 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-junit) -- [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-junit) -- [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-junit) - -## 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-junit) -- [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) -- [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) - -## LambdaTest Community :busts_in_silhouette: - -The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) 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-junit) 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-junit) - -## 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-junit) +# JUnit With Appium ![pw](https://img.shields.io/badge/Junit5-25A162?style=for-the-badge&logo=junit5&logoColor=white) + +

+ +

+ +

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

+  +  +  + +_JUnit is a popular unit testing framework for Java, and was an important part of test-driven development. It belongs to a family of unit testing frameworks known as xUnit. Perform [JUnit test on LambdaTest's online cloud](https://www.lambdatest.com/appium-mobile-testing?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit)._ + +_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-junit)._ + +[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) + +## 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: + +- Make sure you have Appium’s [Java client library](https://github.com/appium/java-client) installed. + +### Clone The Sample Project + +Clone the LambdaTest’s :link: [LT-appium-java-junit](https://github.com/LambdaTest/LT-appium-java-junit) repository and navigate to the code directory as shown below: + +```bash +git clone https://github.com/LambdaTest/LT-appium-java-junit +cd LT-appium-java-junit +``` + +### 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-junit) or access the [Automation Dashboard](https://appautomation.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit). + +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:** + +**For 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"' +``` + +**For 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:** + +**For 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"' +``` + +**For 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 + +Once you are done with the above-mentioned steps, you can initiate your first JUnit test on LambdaTest. + +**Test Scenario**: Check out [android.java](https://github.com/LambdaTest/LT-appium-java-junit/blob/master/src/test/java/com/lambdatest/android.java) file to view the sample test script for android and [ios.java](https://github.com/LambdaTest/LT-appium-java-junit/blob/master/src/test/java/com/lambdatest/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("build", "JUNIT Native App automation"); + capabilities.setCapability("name", "Java JUnit Android Pixel 6"); + capabilities.setCapability("platformName", "android"); + capabilities.setCapability("deviceName", "Pixel 6"); //Enter the name of the device here + capabilities.setCapability("isRealMobile", true); + capabilities.setCapability("platformVersion","12"); + capabilities.setCapability("app","YOUR_APP_URL"); //Enter the App ID here + capabilities.setCapability("deviceOrientation", "PORTRAIT"); + capabilities.setCapability("console",true); + capabilities.setCapability("network",true); + capabilities.setCapability("visual",true); +``` + + + + + +```java +DesiredCapabilities capabilities = new DesiredCapabilities(); + + capabilities.setCapability("build", "JUNIT Native App automation"); + capabilities.setCapability("name", "Java JUnit iOS iPhone 12"); + capabilities.setCapability("platformName", "ios"); + capabilities.setCapability("deviceName", "iPhone 12"); + capabilities.setCapability("isRealMobile", true); + capabilities.setCapability("platformVersion","15"); + capabilities.setCapability("app","YOUR_APP_URL"); //Enter the APP_ID here + capabilities.setCapability("deviceOrientation", "PORTRAIT"); + capabilities.setCapability("console",true); + capabilities.setCapability("network",true); + capabilities.setCapability("visual",true); +``` + + + + + +**Info 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-junit)**. 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-junit). + +## Executing The Test + +Execute the following commands to install the required dependencies: + +```bash +mvn clean +``` + +The tests can be executed in the terminal using the following command: + + + + +```bash +mvn test -P android +``` + + + + + +```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-junit). + +## 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-junit) +- [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-junit) +- [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-junit) + +## 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-junit) +- [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) +- [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) + +## LambdaTest Community :busts_in_silhouette: + +The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-junit) 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-junit) 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-junit) + +## 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-junit) diff --git a/pom.xml b/pom.xml index 95ddfb1..529badb 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.seleniumhq.selenium selenium-java - 3.141.59 + 4.27.0 test @@ -43,7 +43,7 @@ io.appium java-client - 7.6.0 + 9.3.0 test diff --git a/src/test/java/com/lambdatest/android.java b/src/test/java/com/lambdatest/android.java index 10f6065..6d6076a 100644 --- a/src/test/java/com/lambdatest/android.java +++ b/src/test/java/com/lambdatest/android.java @@ -1,68 +1,88 @@ package com.lambdatest; -import io.appium.java_client.MobileBy; +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.By; - +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 android { - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-android" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + String username = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" : System.getenv("LT_USERNAME"); + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); public String status = "passed"; - public static RemoteWebDriver driver = null; + // Fix 1: Use AndroidDriver instead of RemoteWebDriver + public static AndroidDriver driver = null; @Before public void setUp() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability("build", "JUNIT Native App automation"); - capabilities.setCapability("name", "Java JUnit Android"); - capabilities.setCapability("platformName", "android"); - capabilities.setCapability("deviceName", "Pixel.*"); //Enter the name of the device here - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("platformVersion", "12"); - capabilities.setCapability("app", app_id); //Enter the App ID here - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - capabilities.setCapability("autoGrantPermissions", true); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), + // Fix 2: Use lt:options for W3C compliance + HashMap ltOptions = new HashMap(); + ltOptions.put("w3c", true); + ltOptions.put("platformName", "android"); + ltOptions.put("deviceName", "Pixel.*"); + ltOptions.put("platformVersion", "14"); + ltOptions.put("isRealMobile", true); + ltOptions.put("app", "lt://APP1016055391769006462699400"); + ltOptions.put("build", "JUNIT Native App automation"); + ltOptions.put("name", "Java JUnit Android"); + ltOptions.put("visual", true); + ltOptions.put("console", true); + ltOptions.put("autoGrantPermissions", true); + + capabilities.setCapability("lt:options", ltOptions); + + driver = new AndroidDriver( + new URL("https://" + username + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities); } @Test public void testSimple() throws Exception { try { - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click(); - Thread.sleep(5000); + // Fix 3: Use Duration for WebDriverWait in Selenium 4 + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + // Fix 4: Use AppiumBy instead of MobileBy + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("color"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("geoLocation"))).click(); + + Thread.sleep(2000); + + // Fix 5: Proper Mobile Back Navigation driver.navigate().back(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("webview"))).click(); - Thread.sleep(10000); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/"); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click(); - Thread.sleep(5000); + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("Text"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("notification"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("toast"))).click(); + + // Interaction with WebView + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("webview"))).click(); + + WebElement urlField = wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("url"))); + urlField.sendKeys("https://www.lambdatest.com/"); + + driver.findElement(AppiumBy.id("find")).click(); + + Thread.sleep(2000); driver.navigate().back(); + status = "passed"; } catch (Exception e) { - System.out.println(e.getMessage()); + System.out.println("Test Error: " + e.getMessage()); status = "failed"; + throw e; } } @@ -73,5 +93,4 @@ public void tearDown() throws Exception { driver.quit(); } } -} - +} \ No newline at end of file diff --git a/src/test/java/com/lambdatest/androidWeb.java b/src/test/java/com/lambdatest/androidWeb.java index 76e8fc0..5f650f1 100644 --- a/src/test/java/com/lambdatest/androidWeb.java +++ b/src/test/java/com/lambdatest/androidWeb.java @@ -1,70 +1,78 @@ -package com.lambdatest; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; -import java.util.concurrent.TimeUnit; - -public class androidWeb { - - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - public String status = "passed"; - - public static RemoteWebDriver driver = null; - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("build", "JUNIT Native Web automation"); - capabilities.setCapability("name", "Java JUnit Android"); - capabilities.setCapability("platformName", "android"); - capabilities.setCapability("deviceName", "Pixel .*"); //Enter the name of the device here - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("platformVersion", "12"); - capabilities.setCapability("deviceOrientation", "PORTRAIT"); - capabilities.setCapability("console", true); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), - capabilities); - } - - @Test - public void testSimple() throws Exception { - try { - driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); - driver.get("https://mfml.in/api/getInfo"); - driver.getWindowHandles().forEach(handle -> System.out.println(handle)); - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click(); - - status = "passed"; - } catch (Exception e) { - System.out.println(e.getMessage()); - status = "failed"; - } - } - - @After - public void tearDown() throws Exception { - if (driver != null) { - driver.executeScript("lambda-status=" + status); - driver.quit(); - } - } - -} +package com.lambdatest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +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; +import java.util.concurrent.TimeUnit; + +public class androidWeb { + + String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here + public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + public String status = "passed"; + + public static RemoteWebDriver driver = null; + + @Before + public void setUp() throws Exception { + DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap(); + ltOptions.put("build", "JUNIT Native Web automation"); + ltOptions.put("name", "Java JUnit Android"); + ltOptions.put("platformName", "android"); + ltOptions.put("deviceName", "Pixel .*"); //Enter the name of the device here + ltOptions.put("isRealMobile", true); + ltOptions.put("platformVersion", "14"); + ltOptions.put("deviceOrientation", "PORTRAIT"); + ltOptions.put("console", true); + ltOptions.put("network", false); + ltOptions.put("visual", true); + ltOptions.put("browserName", "chrome"); + ltOptions.put("autoGrantPermissions", true); + capabilities.setCapability("lt:options", ltOptions); + + + + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), + capabilities); + } + + @Test + public void testSimple() throws Exception { + try { + driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); + driver.get("https://mfml.in/api/getInfo"); + driver.getWindowHandles().forEach(handle -> System.out.println(handle)); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click(); + + status = "passed"; + } catch (Exception e) { + System.out.println(e.getMessage()); + status = "failed"; + } + } + + @After + public void tearDown() throws Exception { + if (driver != null) { + driver.executeScript("lambda-status=" + status); + driver.quit(); + } + } + +} diff --git a/src/test/java/com/lambdatest/ios.java b/src/test/java/com/lambdatest/ios.java index c96d810..d211fe1 100644 --- a/src/test/java/com/lambdatest/ios.java +++ b/src/test/java/com/lambdatest/ios.java @@ -1,67 +1,88 @@ package com.lambdatest; -import io.appium.java_client.MobileBy; +// Use Appium-specific imports +import io.appium.java_client.AppiumBy; +import io.appium.java_client.ios.IOSDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.By; - 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 ios { - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-ios" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + String username = System.getenv("LT_USERNAME") == null ? "YOUR_USERNAME" : System.getenv("LT_USERNAME"); + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "YOUR_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); + public String grid_url = "mobile-hub.lambdatest.com"; public String status = "passed"; - public static RemoteWebDriver driver = null; - + // FIX 1: Use IOSDriver instead of RemoteWebDriver + public static IOSDriver driver = null; @Before public void setUp() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap(); + + ltOptions.put("build", "JUNIT Native App automation"); + ltOptions.put("name", "Java JUnit iOS"); + ltOptions.put("platformName", "ios"); + ltOptions.put("deviceName", "iPhone.*"); + ltOptions.put("isRealMobile", true); + ltOptions.put("platformVersion", "18"); + ltOptions.put("app", "lt://APP1016018631760361477812757"); + ltOptions.put("network", false); + ltOptions.put("visual", true); + ltOptions.put("w3c", true); // Ensure W3C is enabled + + capabilities.setCapability("lt:options", ltOptions); - capabilities.setCapability("build", "JUNIT Native App automation"); - capabilities.setCapability("name", "Java JUnit iOS"); - capabilities.setCapability("platformName", "ios"); - capabilities.setCapability("deviceName", "iPhone.*"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("platformVersion", "15"); - capabilities.setCapability("app", app_id); //Enter the APP_ID here - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), + // FIX 2: Initialize as IOSDriver + driver = new IOSDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), capabilities); } @Test public void testSimple() throws Exception { try { - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + // FIX 3: Use AppiumBy instead of MobileBy + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("color"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("geoLocation"))).click(); + + Thread.sleep(2000); + + // FIX 4: iOS navigate().back() is often not supported. + // If this fails, you must click the 'Back' button element in your UI instead. + try { + driver.navigate().back(); + } catch (Exception e) { + System.out.println("Standard back not supported, skipping or use element click."); + } + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("Text"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("notification"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("toast"))).click(); + + // Navigate to Browser/WebView + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.accessibilityId("Browser"))).click(); Thread.sleep(5000); - driver.navigate().back(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("Browser"))).click(); - Thread.sleep(10000); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/"); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click(); + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("url"))).sendKeys("https://www.lambdatest.com/"); + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("find"))).click(); + Thread.sleep(5000); + // navigate back to app driver.navigate().back(); status = "passed"; } catch (Exception e) { - System.out.println(e.getMessage()); + System.out.println("Test failed: " + e.getMessage()); status = "failed"; } } @@ -69,9 +90,9 @@ public void testSimple() throws Exception { @After public void tearDown() throws Exception { if (driver != null) { + // FIX 5: Use the correct LambdaTest status hook for Appium 2.x driver.executeScript("lambda-status=" + status); driver.quit(); } } -} - +} \ No newline at end of file diff --git a/src/test/java/com/lambdatest/iosWeb.java b/src/test/java/com/lambdatest/iosWeb.java index c442b2a..1ef37f2 100644 --- a/src/test/java/com/lambdatest/iosWeb.java +++ b/src/test/java/com/lambdatest/iosWeb.java @@ -1,69 +1,73 @@ -package com.lambdatest; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; -import java.util.concurrent.TimeUnit; - -public class iosWeb { - - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - public String status = "passed"; - - public static RemoteWebDriver driver = null; - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - capabilities.setCapability("build", "JUNIT Native Web automation"); - capabilities.setCapability("name", "Java JUnit iOS"); - capabilities.setCapability("platformName", "ios"); - capabilities.setCapability("deviceName", "iPhone .*"); - capabilities.setCapability("isRealMobile", true); - capabilities.setCapability("platformVersion", "15"); - capabilities.setCapability("console", true); - capabilities.setCapability("network", false); - capabilities.setCapability("visual", true); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), - capabilities); - } - - @Test - public void testSimple() throws Exception { - try { - driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); - driver.get("https://mfml.in/api/getInfo"); - driver.getWindowHandles().forEach(handle -> System.out.println(handle)); - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click(); - - status = "passed"; - } catch (Exception e) { - System.out.println(e.getMessage()); - status = "failed"; - } - } - - @After - public void tearDown() throws Exception { - if (driver != null) { - driver.executeScript("lambda-status=" + status); - driver.quit(); - } - } - -} +package com.lambdatest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +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; +import java.util.concurrent.TimeUnit; + +public class iosWeb { + + String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here + String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here + public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); + public String status = "passed"; + + public static RemoteWebDriver driver = null; + + @Before + public void setUp() throws Exception { + DesiredCapabilities capabilities = new DesiredCapabilities(); + HashMap ltOptions = new HashMap(); + + ltOptions.put("build", "JUNIT Native Web automation"); + ltOptions.put("name", "Java JUnit iOS"); + ltOptions.put("platformName", "ios"); + ltOptions.put("deviceName", "iPhone .*"); + ltOptions.put("isRealMobile", true); + ltOptions.put("platformVersion", "18"); + ltOptions.put("console", true); + ltOptions.put("network", false); + ltOptions.put("visual", true); + capabilities.setCapability("lt:options", ltOptions); + + driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), + capabilities); + } + + @Test + public void testSimple() throws Exception { + try { + driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); + driver.get("https://mfml.in/api/getInfo"); + driver.getWindowHandles().forEach(handle -> System.out.println(handle)); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click(); + wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click(); + + status = "passed"; + } catch (Exception e) { + System.out.println(e.getMessage()); + status = "failed"; + } + } + + @After + public void tearDown() throws Exception { + if (driver != null) { + driver.executeScript("lambda-status=" + status); + driver.quit(); + } + } + +} diff --git a/src/test/java/com/lambdatest/ltOptions_w3c/androidWeb_ltOptions_w3c.java b/src/test/java/com/lambdatest/ltOptions_w3c/androidWeb_ltOptions_w3c.java deleted file mode 100644 index f13758a..0000000 --- a/src/test/java/com/lambdatest/ltOptions_w3c/androidWeb_ltOptions_w3c.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.lambdatest.ltOptions_w3c; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -public class androidWeb_ltOptions_w3c { - - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - public String status = "passed"; - - public static RemoteWebDriver driver = null; - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - HashMap ltOptions = new HashMap(); - ltOptions.put("w3c", true); - ltOptions.put("console", true); - ltOptions.put("network", true); - ltOptions.put("visual", true); - ltOptions.put("enableCustomTranslation", true); - ltOptions.put("platformName", "android"); - ltOptions.put("deviceName", ".*"); - ltOptions.put("platformVersion", "13"); - ltOptions.put("deviceOrientation", "PORTRAIT"); - ltOptions.put("build", "JUNIT_lt:options_w3c"); - ltOptions.put("name", "android_lt:options_w3c"); - ltOptions.put("isRealMobile", true); - capabilities.setCapability("lt:options", ltOptions); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), capabilities); - } - - @Test - public void testSimple() throws Exception { - try { - driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); - driver.get("https://mfml.in/api/getInfo"); - driver.getWindowHandles().forEach(handle -> System.out.println(handle)); - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click(); - - status = "passed"; - } catch (Exception e) { - System.out.println(e.getMessage()); - status = "failed"; - } - } - - @After - public void tearDown() throws Exception { - if (driver != null) { - driver.executeScript("lambda-status=" + status); - driver.quit(); - } - } - -} diff --git a/src/test/java/com/lambdatest/ltOptions_w3c/android_ltOptions_w3c.java b/src/test/java/com/lambdatest/ltOptions_w3c/android_ltOptions_w3c.java deleted file mode 100644 index a6b7501..0000000 --- a/src/test/java/com/lambdatest/ltOptions_w3c/android_ltOptions_w3c.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.lambdatest.ltOptions_w3c; - -import io.appium.java_client.MobileBy; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; -import java.util.HashMap; - -public class android_ltOptions_w3c { - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-android" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - public String status = "passed"; - - public static RemoteWebDriver driver = null; - - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - HashMap ltOptions = new HashMap(); - ltOptions.put("w3c", true); - ltOptions.put("console", true); - ltOptions.put("network", false); - ltOptions.put("visual", true); - ltOptions.put("autoGrantPermissions", true); - ltOptions.put("enableCustomTranslation", true); - ltOptions.put("platformName", "android"); - ltOptions.put("deviceName", ".*"); - ltOptions.put("platformVersion", "12"); - ltOptions.put("app", app_id); - ltOptions.put("deviceOrientation", "PORTRAIT"); - ltOptions.put("build", "JUNIT_lt:options_w3c"); - ltOptions.put("name", "android_lt:options_w3c"); - ltOptions.put("isRealMobile", true); - capabilities.setCapability("lt:options", ltOptions); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), capabilities); - } - - @Test - public void testSimple() throws Exception { - try { - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click(); - Thread.sleep(5000); - driver.navigate().back(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("webview"))).click(); - Thread.sleep(10000); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/"); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click(); - Thread.sleep(5000); - driver.navigate().back(); - status = "passed"; - } catch (Exception e) { - System.out.println(e.getMessage()); - status = "failed"; - } - } - - @After - public void tearDown() throws Exception { - if (driver != null) { - driver.executeScript("lambda-status=" + status); - driver.quit(); - } - } -} - diff --git a/src/test/java/com/lambdatest/ltOptions_w3c/iosWeb_ltOptions_w3c.java b/src/test/java/com/lambdatest/ltOptions_w3c/iosWeb_ltOptions_w3c.java deleted file mode 100644 index 5d66b0a..0000000 --- a/src/test/java/com/lambdatest/ltOptions_w3c/iosWeb_ltOptions_w3c.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.lambdatest.ltOptions_w3c; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -public class iosWeb_ltOptions_w3c { - - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - public String status = "passed"; - - public static RemoteWebDriver driver = null; - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - HashMap ltOptions = new HashMap(); - ltOptions.put("w3c", true); - ltOptions.put("console", true); - ltOptions.put("network", true); - ltOptions.put("visual", true); - ltOptions.put("enableCustomTranslation", true); - ltOptions.put("platformName", "ios"); - ltOptions.put("deviceName", ".*"); - ltOptions.put("platformVersion", "16"); - ltOptions.put("deviceOrientation", "PORTRAIT"); - ltOptions.put("build", "JUNIT_lt:options_w3c"); - ltOptions.put("name", "ios_lt:options_w3c"); - ltOptions.put("isRealMobile", true); - capabilities.setCapability("lt:options", ltOptions); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), capabilities); - } - - @Test - public void testSimple() throws Exception { - try { - driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS); - driver.get("https://mfml.in/api/getInfo"); - driver.getWindowHandles().forEach(handle -> System.out.println(handle)); - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(By.id("resolution"))).click(); - - wait.until(ExpectedConditions.elementToBeClickable(By.id("location"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("details"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("timezone"))).click(); - - status = "passed"; - } catch (Exception e) { - System.out.println(e.getMessage()); - status = "failed"; - } - } - - @After - public void tearDown() throws Exception { - if (driver != null) { - driver.executeScript("lambda-status=" + status); - driver.quit(); - } - } - -} diff --git a/src/test/java/com/lambdatest/ltOptions_w3c/ios_ltOptions_w3c.java b/src/test/java/com/lambdatest/ltOptions_w3c/ios_ltOptions_w3c.java deleted file mode 100644 index 7ee1500..0000000 --- a/src/test/java/com/lambdatest/ltOptions_w3c/ios_ltOptions_w3c.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.lambdatest.ltOptions_w3c; - -import io.appium.java_client.MobileBy; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.URL; -import java.util.HashMap; - -public class ios_ltOptions_w3c { - String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME"); //Enter the Username here - String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY"); //Enter the Access key here - public String app_id = System.getenv("LT_APP_ID") == null ? "lt://proverbial-ios" : System.getenv("LT_APP_ID"); //Enter your LambdaTest App ID at the place of lt://proverbial-android - public String grid_url = System.getenv("LT_GRID_URL") == null ? "mobile-hub.lambdatest.com" : System.getenv("LT_GRID_URL"); - public String status = "passed"; - - public static RemoteWebDriver driver = null; - - @Before - public void setUp() throws Exception { - DesiredCapabilities capabilities = new DesiredCapabilities(); - - HashMap ltOptions = new HashMap(); - ltOptions.put("w3c", true); - ltOptions.put("console", true); - ltOptions.put("network", true); - ltOptions.put("visual", true); - ltOptions.put("enableCustomTranslation", true); - ltOptions.put("platformName", "ios"); - ltOptions.put("deviceName", ".*"); - ltOptions.put("platformVersion", "15"); - ltOptions.put("app", app_id); - ltOptions.put("deviceOrientation", "PORTRAIT"); - ltOptions.put("build", "JUNIT_lt:options_w3c"); - ltOptions.put("name", "ios_lt:options_w3c"); - ltOptions.put("isRealMobile", true); - capabilities.setCapability("lt:options", ltOptions); - - driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@" + grid_url + "/wd/hub"), capabilities); - } - - @Test - public void testSimple() throws Exception { - try { - WebDriverWait wait = new WebDriverWait(driver, 30); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("color"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("geoLocation"))).click(); - Thread.sleep(5000); - driver.navigate().back(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("Text"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("notification"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("toast"))).click(); - wait.until(ExpectedConditions.elementToBeClickable(By.id("Browser"))).click(); - Thread.sleep(10000); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))).sendKeys("https://www.lambdatest.com/"); - wait.until(ExpectedConditions.elementToBeClickable(MobileBy.id("find"))).click(); - Thread.sleep(5000); - driver.navigate().back(); - - status = "passed"; - } catch (Exception e) { - System.out.println(e.getMessage()); - status = "failed"; - } - } - - @After - public void tearDown() throws Exception { - if (driver != null) { - driver.executeScript("lambda-status=" + status); - driver.quit(); - } - } -} -