简体   繁体   English

为什么每次运行一组测试都需要重启Appium?

[英]Why do we need to restart Appium every time we run group of tests?

Why don't to set Appium running all the time?为什么不设置 Appium 一直运行? starting in the morning and stopping when day is complete, and running test scripts when we want.从早上开始,在一天结束时停止,并在需要时运行测试脚本。

Mac, Appium, Java. Mac、Appium、Java。

You could do that, just start it in the morning and stop it at night, but you could also do something better: Check to see in your test script if it is running, and if not, start it.您可以这样做,只需在早上启动它并在晚上停止它,但您也可以做一些更好的事情:检查您的测试脚本是否正在运行,如果没有,请启动它。 You could also then decide in your code whether or not to stop the service.然后,您还可以在代码中决定是否停止该服务。

Below is the class I wrote for my own use with the help of many others by researching the net and putting it all together:以下是我在许多其他人的帮助下通过研究网络并将它们放在一起而编写的供自己使用的类:

import java.io.IOException;
import java.net.ServerSocket;

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;

/**
 * This class handles Appium Server
 * 
 * @author Bill Hileman
 */
public class AppiumServer {

    private AppiumDriverLocalService service;
    private AppiumServiceBuilder builder;
    private DesiredCapabilities cap;

    private int port = 4723;

    public void startServer() {
        // Set Capabilities
        cap = new DesiredCapabilities();
        cap.setCapability("noReset", "false");

        // Build the Appium service
        builder = new AppiumServiceBuilder();
        builder.withIPAddress("127.0.0.1");
        builder.usingPort(port);
        builder.withCapabilities(cap);
        builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
        builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");

        // Start the server with the builder
        service = AppiumDriverLocalService.buildService(builder);
        service.start();
    }

    public void stopServer() {
        service.stop();
    }

    public boolean serverIsRunnning() {

        boolean isServerRunning = false;
        ServerSocket serverSocket;
        try {
            serverSocket = new ServerSocket(port);
            serverSocket.close();
        } catch (IOException e) {
            // If control comes here, then it means that the port is in use
            isServerRunning = true;
        } finally {
            serverSocket = null;
        }
        return isServerRunning;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM