zoukankan      html  css  js  c++  java
  • AppiumDriverLocalService 启动appium控制台不显示日志以及把日志保存到本地

    import java.io.File;
    import java.io.OutputStream;
    import java.lang.reflect.Field;
    import java.util.ArrayList;
    
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    
    import cn.lebo.appium.base.AndroidCapabilityType;
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.service.local.AppiumDriverLocalService;
    import io.appium.java_client.service.local.AppiumServiceBuilder;
    
    public class NewTest {
    
        AppiumDriverLocalService service = null;
        AndroidDriver<WebElement> driver = null;
    
        @SuppressWarnings("unchecked")
        @BeforeClass
        public void beforClass() {
            Field streamField = null;
            Field streamsField = null;
            
    
            service = AppiumDriverLocalService
                    .buildService(new AppiumServiceBuilder().usingPort(4723).withLogFile(new File("d:\44555554.txt")));
            try {
                streamField = AppiumDriverLocalService.class.getDeclaredField("stream");
                streamField.setAccessible(true);
                streamsField = Class.forName("io.appium.java_client.service.local.ListOutputStream")
                        .getDeclaredField("streams");
                streamsField.setAccessible(true);
            } catch (ClassNotFoundException | NoSuchFieldException e) {
                e.printStackTrace();
            }
            try {
                ((ArrayList<OutputStream>) streamsField.get(streamField.get(service))).clear(); // remove System.out logging
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            
            service.start();
    
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(AndroidCapabilityType.DEVICE_NAME, "android");
            capabilities.setCapability(AndroidCapabilityType.APP_PACKAGE, "com.hpplay.sdk.source.test");
            capabilities.setCapability(AndroidCapabilityType.APP_ACTIVITY, "com.hpplay.sdk.source.test.MainActivity");
            driver = new AndroidDriver<>(service, capabilities);
    
        }
    
        @Test
        public void demo1() {
            System.out.println("执行test");
            driver.openNotifications();
            System.out.println("执行" + driver.toString());
            // driver.manage().logs().get("logcat");
    
        }
    
        @AfterClass
        public void AfterClass() {
            service.stop();
            System.out.println("停止test");
        }
    
    }
  • 相关阅读:
    团队冲刺(九)
    TensorFlow利用Keras实现线性回归
    Spark Streaming 编程初级实践
    Spark SQL 编程初级实践
    解决Ubuntu输入正确密码后进不去桌面
    RDD 编程初级实践
    A master URL must be set in your configuration at org.apache.spark.SparkContext.<init>(SparkContext.
    TensorFlow加载mnist数据集并显示
    Spark读取文件统计行数
    【测试技能】服务端测试就是postman看接口和操作redis吗?
  • 原文地址:https://www.cnblogs.com/dengnapianhuahai/p/9029413.html
Copyright © 2011-2022 走看看