移动的测试:java + appium容器+远程adb服务器+真实的的移动的设备

pod7payv  于 2022-10-30  发布在  Java
关注(0)|答案(1)|浏览(156)

我目前正在为一个移动的应用程序开发一个测试系统。
我在我的本地计算机上运行Appium容器。我在本地网络中的一台单独的计算机上启动ADB服务器。智能手机通过USB连接到第二台计算机。
我使用以下命令在本地计算机上运行容器:

docker run -d -p 4723:4723 -e REMOTE_ADB=true -e "ADB_SERVER_SOCKET=tcp:10.38.223.243:5037" --name container-appium-tests ross/appium-tests:v1.0.1

docker exec -it container-appium-tests sh

然后,在容器中运行命令

adb devices

一切都工作得很好,在容器中,我可以看到连接到远程计算机的电话列表:

当我运行测试mvn clean test -Dxml=parallel时,问题就开始了。我得到的错误是:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device in 20026ms. 
Host info: host: '8e41f735a077', ip: '172.17.0.2'
Build info: version: '4.5.0', revision: 'fe167b119a'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.104-linuxkit', java.version: '17.0.4'
Driver info: io.appium.java_client.AppiumDriver
Command: [null, newSession {capabilities=[{appium:newCommandTimeout=60, appium:appWaitForLaunch=true, appium:resetKeyboard=true, appium:appWaitDuration=60000, appium:appWaitActivity=pl.com.rossmann.centauros.dashboard.presentation.main.DashboardActivity, appium:automationName=UIAutomator2, appium:udid=3691688b, appium:autoGrantPermissions=true, appium:unicodeKeyboard=true, appium:ignoreHiddenApiPolicyError=true, appium:suppressKillServer=true, appium:disableWindowAnimation=true, appium:appActivity=.splash.SplashActivityV6, platformName=ANDROID, appium:enableMultiWindows=true, appium:appPackage=pl.com.rossmann.centauros}], desiredCapabilities=Capabilities {appium:appActivity: .splash.SplashActivityV6, appium:appPackage: pl.com.rossmann.centauros, appium:appWaitActivity: pl.com.rossmann.centauros.d..., appium:appWaitDuration: 60000, appium:appWaitForLaunch: true, appium:autoGrantPermissions: true, appium:automationName: UIAutomator2, appium:disableWindowAnimation: true, appium:enableMultiWindows: true, appium:ignoreHiddenApiPolicyError: true, appium:newCommandTimeout: 60, appium:resetKeyboard: true, appium:suppressKillServer: true, appium:udid: 3691688b, appium:unicodeKeyboard: true, platformName: ANDROID}}]
Capabilities {}
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:126)
    at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:155)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:189)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:80)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
    at configuration.drivers.Drivers.initializeAndroidDriver(Drivers.java:43)
    at basetest.BaseTest.setUp(BaseTest.java:43)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
... Removed 25 stack frames

设置驱动程序配置的我的类:

public abstract class Drivers {

    protected AppiumDriver driver;
    protected AppiumDriverLocalService service;

    protected void initializeAndroidDriver(String udid, int appiumPort) {

        UiAutomator2Options options = new UiAutomator2Options();

        options.setAppWaitForLaunch(true);
        options.setNewCommandTimeout(Duration.ofSeconds(60));
        options.setAppWaitDuration(Duration.ofSeconds(60));
        options.setPlatformName("android");
        options.setUdid(udid);
        options.setAutoGrantPermissions(true);
        options.setAppPackage(ConfigProperties.getProperty("app.package"));
        options.setAppWaitActivity(ConfigProperties.getProperty("app.wait.activity"));
        options.setAppActivity(ConfigProperties.getProperty("app.activity"));
        options.setCapability("enableMultiWindows", true);
        options.setDisableWindowAnimation(true);
        options.setSuppressKillServer(true);
        options.setIgnoreHiddenApiPolicyError(true);

        options.setCapability("unicodeKeyboard", true);
        options.setCapability("resetKeyboard", true);

        try {
            driver = new AppiumDriver(new URL("http://127.0.0.1:" + appiumPort + "/wd/hub"), options);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

    }

    protected void runAppiumServer() {
        AppiumServiceBuilder builder = new AppiumServiceBuilder()
                .withArgument(() -> "--base-path", "/wd/hub")
                .withArgument(() -> "--log-level", "error:debug")
                .withIPAddress("127.0.0.1")
                .usingAnyFreePort();
        service = AppiumDriverLocalService.buildService(builder);
        service.start();
        Logger.info("Appium has been started successfully.");
    }
}

尝试了不同的IP地址与端口-总是类似的错误。我要求提示。
谢谢你,谢谢你

sshcrbum

sshcrbum1#

最后,我能够为一个设备做远程测试。在驱动程序代码中需要指明远程主机、端口和设备。

UiAutomator2Options options = new UiAutomator2Options();
 [...]
 options.setRemoteAdbHost("10.38.223.243");
 options.setAdbPort(5038);
 options.setUdid(udid);

这解决了问题中描述的问题。但是,这只在一部智能手机连接到远程服务器时才起作用。
当我在同一部电话上运行相同的测试,但有几部电话连接到远程服务器时,我遇到以下错误:
第一个
到目前为止我还不知道怎么解决这个问题。

相关问题