/
AppiumUiAutomator2Server.java
40 lines (33 loc) · 1.29 KB
/
AppiumUiAutomator2Server.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package io.appium.uiautomator2.server.test;
import android.os.SystemClock;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.appium.uiautomator2.common.exceptions.SessionRemovedException;
import io.appium.uiautomator2.server.ServerInstrumentation;
import io.appium.uiautomator2.utils.Logger;
@RunWith(AndroidJUnit4.class)
public class AppiumUiAutomator2Server {
private static ServerInstrumentation serverInstrumentation;
/**
* Starts the server on the device.
* !!! This class is the main entry point for UIA2 driver package.
* !!! Do not rename or move it unless you know what you are doing.
*/
@Test
public void startServer() {
if (serverInstrumentation == null) {
serverInstrumentation = ServerInstrumentation.getInstance();
Logger.info("[AppiumUiAutomator2Server]", " Starting Server");
try {
while (!serverInstrumentation.isServerStopped()) {
SystemClock.sleep(1000);
serverInstrumentation.startMjpegServer();
serverInstrumentation.startServer();
}
} catch (SessionRemovedException e) {
//Ignoring SessionRemovedException
}
}
}
}