├── .gitpod.yml
├── .idea
├── .gitignore
├── compiler.xml
├── encodings.xml
├── jarRepositories.xml
├── misc.xml
└── vcs.xml
├── README.md
├── pom.xml
├── src
└── test
│ └── java
│ ├── vanilla_android.java
│ └── vanilla_ios.java
└── target
├── AppTesting-1.0-SNAPSHOT.jar
├── maven-archiver
└── pom.properties
├── maven-status
└── maven-compiler-plugin
│ └── testCompile
│ └── default-testCompile
│ ├── createdFiles.lst
│ └── inputFiles.lst
└── test-classes
└── vanilla_android.class
/.gitpod.yml:
--------------------------------------------------------------------------------
1 | # This configuration file was automatically generated by Gitpod.
2 | # Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
3 | # and commit this file to your remote git repository to share the goodness with others.
4 |
5 | tasks:
6 | - init: mvn install -DskipTests=false
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # How to close/open the app during a session in Real Devices on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-openApp) using the Appium Java Language
2 |
3 | While performing automation testing with Appium on LambdaTest Grid, you might face a scenario where you'd want to close the application or open the application during a test run.
4 | This can be essential sometimes to see how your application behaves in different scenarios. Let's see how we can leverage Appium's commands to achieve it on LambdaTest.
5 |
6 | **Tip:**
7 |
8 | - 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).
9 | - Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step.
10 | - Alternatively you can also use the `Custom ID` that you defined in your own words.
11 |
12 | ## Run Your First Test
13 |
14 | Once you are done with the above-mentioned steps, you can initiate your first Java test on LambdaTest.
15 |
16 | ### Configuring Your Test Capabilities
17 |
18 | 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:
19 |
20 |
21 |
22 |
23 |
24 | ```java
25 | public class vanilla_android {
26 | public static String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Add username here
27 | : System.getenv("LT_USERNAME");
28 | public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Add accessKey here
29 | : System.getenv("LT_ACCESS_KEY");
30 |
31 | private static AppiumDriver driver;
32 |
33 | public static void main(String args[]) throws MalformedURLException, InterruptedException {
34 |
35 | try {
36 | DesiredCapabilities capabilities = new DesiredCapabilities();
37 | capabilities.setCapability("deviceName", "Galaxy S20");
38 | capabilities.setCapability("platformVersion", "11");
39 | capabilities.setCapability("platformName", "Android");
40 | capabilities.setCapability("isRealMobile", true);
41 | capabilities.setCapability("app", "ENTER_CUSTOM_ID_HERE"); //Enter App_ID or Customer ID here
42 | capabilities.setCapability("deviceOrientation", "PORTRAIT");
43 | capabilities.setCapability("build", "Java Vanilla - iOS");
44 | capabilities.setCapability("name", "Sample Test Java");
45 | capabilities.setCapability("console", true);
46 | capabilities.setCapability("network", false);
47 | capabilities.setCapability("visual", true);
48 | capabilities.setCapability("devicelog", true);
49 |
50 | driver = new AppiumDriver(new URL("https://" +userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities);
51 |
52 | MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color"));
53 | color.click();
54 |
55 | MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text"));
56 | text.click();
57 |
58 | //Close the application
59 | driver.closeApp();
60 |
61 | //Open the application
62 | driver.launchApp();
63 |
64 | MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast"));
65 | toast.click();
66 |
67 | MobileElement notification = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification"));
68 | notification.click();
69 |
70 |
71 | } catch (AssertionError a) {
72 | ((JavascriptExecutor) driver).executeScript("lambda-status=failed");
73 | a.printStackTrace();
74 | }
75 | driver.quit();
76 | }
77 | }
78 | ```
79 |
80 | For more information on the Appium Commands used here, head over to:
81 | * [Launch App | Appium](https://appium.io/docs/en/commands/device/app/launch-app/)
82 | * [Close App | Appium](https://appium.io/docs/en/commands/device/app/close-app/)
83 |
84 | ## Executing The Test
85 |
86 | Execute the following commands to install the required dependencies:
87 |
88 | ```bash
89 | mvn clean install
90 | ```
91 |
92 | The tests can be executed in the terminal using the following command:
93 |
94 | Android:
95 |
96 |
97 | ```bash
98 | mvn test -P android
99 | ```
100 |
101 | iOS:
102 |
103 | ```bash
104 | mvn test -P ios
105 | ```
106 |
107 |
108 |
109 |
110 |
111 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build).
112 |
113 | ## Additional Links
114 |
115 | - [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/)
116 | - [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/)
117 | - [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/)
118 |
119 | ## Documentation & Resources :books:
120 |
121 | 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.
122 |
123 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python)
124 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python)
125 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python)
126 | * [LambdaTest Community](http://community.lambdatest.com/)
127 |
128 | ## LambdaTest Community :busts_in_silhouette:
129 |
130 | The [LambdaTest Community](https://community.lambdatest.com/) 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 🌎
131 |
132 | ## What's New At LambdaTest ❓
133 |
134 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
135 |
136 | ## About LambdaTest
137 |
138 | [LambdaTest](https://www.lambdatest.com) 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.
139 |
140 | ### Features
141 |
142 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
143 | * Real-time cross browser testing on 3000+ environments.
144 | * Test on Real device cloud
145 | * Blazing fast test automation with HyperExecute
146 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
147 | * Smart Visual Regression Testing on cloud
148 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
149 | * Automated Screenshot testing across multiple browsers in a single click.
150 | * Local testing of web and mobile apps.
151 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
152 | * Geolocation testing of web and mobile apps across 53+ countries.
153 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
154 |
155 | [
](https://accounts.lambdatest.com/register)
156 |
157 | ## We are here to help you :headphones:
158 |
159 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com)
160 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-java-openApp)
161 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | App
7 | AppTesting
8 | 1.0-SNAPSHOT
9 |
10 |
11 | UTF-8
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | org.seleniumhq.selenium
20 | selenium-java
21 | 3.141.59
22 |
23 |
24 |
25 |
26 | com.github.lambdatest
27 | lambdatest-tunnel-binary
28 | 1.0.5
29 |
30 |
31 |
32 |
33 | io.github.bonigarcia
34 | webdrivermanager
35 | 4.3.1
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.11.0
41 |
42 |
43 | org.seleniumhq.selenium
44 | selenium-support
45 | 2.52.0
46 |
47 |
48 | io.appium
49 | java-client
50 | 7.6.0
51 |
52 |
53 | org.testng
54 | testng
55 | 6.14.3
56 |
57 |
58 | commons-lang
59 | commons-lang
60 | 2.6
61 |
62 |
63 |
64 | org.apache.commons
65 | commons-lang3
66 | 3.0
67 |
68 |
69 |
70 | info.cukes
71 | cucumber-java
72 | 1.2.5
73 |
74 |
75 |
76 | junit
77 | junit
78 | 4.12
79 | test
80 |
81 |
82 | org.json
83 | json
84 | 20160810
85 |
86 |
87 | org.seleniumhq.selenium
88 | selenium-remote-driver
89 | 3.141.59
90 |
91 |
92 | io.rest-assured
93 | rest-assured
94 | 4.3.0
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | org.apache.maven.plugins
103 | maven-surefire-plugin
104 | 2.22.2
105 |
106 |
107 | org.apache.maven.plugins
108 | maven-compiler-plugin
109 | 3.8.1
110 |
111 | 1.8
112 | 1.8
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | android
121 |
122 |
123 |
124 | org.codehaus.mojo
125 | exec-maven-plugin
126 | 1.1.1
127 |
128 |
129 | test
130 |
131 | java
132 |
133 |
134 | vanilla_android
135 | test
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 | ios
146 |
147 |
148 |
149 | org.codehaus.mojo
150 | exec-maven-plugin
151 | 1.1.1
152 |
153 |
154 | test
155 |
156 | java
157 |
158 |
159 | vanilla_ios
160 | test
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/src/test/java/vanilla_android.java:
--------------------------------------------------------------------------------
1 | import io.appium.java_client.AppiumDriver;
2 | import io.appium.java_client.MobileBy;
3 | import io.appium.java_client.MobileElement;
4 | import org.openqa.selenium.JavascriptExecutor;
5 | import org.openqa.selenium.remote.DesiredCapabilities;
6 | import org.openqa.selenium.remote.RemoteWebDriver;
7 | import java.net.MalformedURLException;
8 | import java.net.URL;
9 |
10 | public class vanilla_android {
11 | public static String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Add username here
12 | : System.getenv("LT_USERNAME");
13 | public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Add accessKey here
14 | : System.getenv("LT_ACCESS_KEY");
15 |
16 | private static AppiumDriver driver;
17 |
18 | public static void main(String args[]) throws MalformedURLException, InterruptedException {
19 |
20 | try {
21 | DesiredCapabilities capabilities = new DesiredCapabilities();
22 | capabilities.setCapability("deviceName", "Galaxy S20");
23 | capabilities.setCapability("platformVersion", "11");
24 | capabilities.setCapability("platformName", "Android");
25 | capabilities.setCapability("isRealMobile", true);
26 | capabilities.setCapability("app", "ENTER_CUSTOM_ID_HERE"); //Enter App_ID or Custom ID here
27 | capabilities.setCapability("deviceOrientation", "PORTRAIT");
28 | capabilities.setCapability("build", "Java Vanilla - iOS");
29 | capabilities.setCapability("name", "Sample Test Java");
30 | capabilities.setCapability("console", true);
31 | capabilities.setCapability("network", false);
32 | capabilities.setCapability("visual", true);
33 | capabilities.setCapability("devicelog", true);
34 |
35 | driver = new AppiumDriver(new URL("https://" +userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities);
36 |
37 | MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color"));
38 | color.click();
39 |
40 | MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text"));
41 | text.click();
42 |
43 | //Close the application
44 | driver.closeApp();
45 |
46 | //Open the application
47 | driver.launchApp();
48 |
49 | MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast"));
50 | toast.click();
51 |
52 | MobileElement notification = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification"));
53 | notification.click();
54 |
55 |
56 | } catch (AssertionError a) {
57 | ((JavascriptExecutor) driver).executeScript("lambda-status=failed");
58 | a.printStackTrace();
59 | }
60 | driver.quit();
61 | }
62 | }
--------------------------------------------------------------------------------
/src/test/java/vanilla_ios.java:
--------------------------------------------------------------------------------
1 | import io.appium.java_client.AppiumDriver;
2 | import io.appium.java_client.MobileBy;
3 | import io.appium.java_client.MobileElement;
4 | import io.appium.java_client.ios.IOSDriver;
5 |
6 | import org.openqa.selenium.remote.DesiredCapabilities;
7 | import org.openqa.selenium.support.ui.ExpectedConditions;
8 | import org.openqa.selenium.support.ui.WebDriverWait;
9 |
10 | import java.net.URL;
11 |
12 | public class vanilla_ios {
13 |
14 | public static String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Add username here
15 | : System.getenv("LT_USERNAME");
16 | public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Add accessKey here
17 | : System.getenv("LT_ACCESS_KEY");
18 |
19 | public static IOSDriver driver = null;
20 |
21 | public static void main(String[] args) throws Exception {
22 |
23 | try {
24 | DesiredCapabilities caps = new DesiredCapabilities();
25 | caps.setCapability("platformVersion", "15");
26 | caps.setCapability("deviceName", "iPhone 12");
27 | caps.setCapability("isRealMobile", true);
28 | caps.setCapability("app", "ENTER_CUSTOM_ID_HERE"); //Enter App_ID or Custom ID here
29 | caps.setCapability("platformName", "iOS");
30 | caps.setCapability("build", "Java Vanilla - iOS");
31 | caps.setCapability("name", "Sample Test Java");
32 | caps.setCapability("devicelog", true);
33 | caps.setCapability("network", true);
34 |
35 | driver = new IOSDriver(new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), caps);
36 |
37 |
38 | Thread.sleep(2000);
39 |
40 | driver.findElement(MobileBy.id("color")).click();
41 | Thread.sleep(1000);
42 | driver.findElement(MobileBy.id("Text")).click();
43 | Thread.sleep(1000);
44 |
45 | //Close the application
46 | driver.closeApp();
47 |
48 | //Open the application
49 | driver.launchApp();
50 |
51 | driver.findElement(MobileBy.id("toast")).click();
52 | Thread.sleep(1000);
53 |
54 | driver.findElement(MobileBy.id("notification")).click();
55 | Thread.sleep(2000);
56 |
57 | ((JavascriptExecutor) driver).executeScript("lambda-status=passed");
58 | driver.quit();
59 |
60 | } catch (Exception t) {
61 | System.out.println(t);
62 | driver.quit();
63 |
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/target/AppTesting-1.0-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshuseth004/java-appium-open-app/88048ad21c8c024b5af4402f5c1d08e59581cd90/target/AppTesting-1.0-SNAPSHOT.jar
--------------------------------------------------------------------------------
/target/maven-archiver/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven
2 | #Wed Jun 22 23:23:12 IST 2022
3 | artifactId=AppTesting
4 | groupId=App
5 | version=1.0-SNAPSHOT
6 |
--------------------------------------------------------------------------------
/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst:
--------------------------------------------------------------------------------
1 | vanilla_android.class
2 |
--------------------------------------------------------------------------------
/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst:
--------------------------------------------------------------------------------
1 | /workspace/java-appium-open-preinstalled-app/src/test/java/vanilla_android.java
2 | /workspace/java-appium-open-preinstalled-app/src/test/java/vanilla_ios.java
3 |
--------------------------------------------------------------------------------
/target/test-classes/vanilla_android.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshuseth004/java-appium-open-app/88048ad21c8c024b5af4402f5c1d08e59581cd90/target/test-classes/vanilla_android.class
--------------------------------------------------------------------------------