• 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");
        }
    
    }
  • 相关阅读:
    ASP.NET控件开发学习笔记第5回 HtmlTextWriter的相关枚举
    ASP.NET控件开发学习笔记第4回 为控件添加属性
    ASP.NET控件开发学习笔记第6回 ViewState
    构建可反转排序的泛型字典类(9完)完善
    ASP.NET控件开发学习笔记第一回 HelloWorld
    构建可反转排序的泛型字典类(7)实现IDictionary接口
    C#泛型专题系列文章目录导航
    构建可反转排序的泛型字典类(8)实现IDictionary接口
    ASP.NET控件开发学习笔记第二回 又见Hello World
    ASP.NET控件开发学习笔记第3回 自制导航控件
  • 原文地址:https://www.cnblogs.com/dengnapianhuahai/p/9029413.html
Copyright © 2020-2023  润新知